lfs-buildscripts/KernelBuild/02-linux-kernel.sh

96 lines
2.2 KiB
Bash
Raw Normal View History

2024-10-13 10:23:21 +08:00
#!/bin/bash
2024-10-13 22:02:09 +08:00
# if booted from flash drive and building for system install...
if [ ! -f /USBFlash ]; then
echo "Mounting existing /boot"
[ ! -d /boot ] && mkdir /boot
mount /boot
if [ $? -ne 0 ]; then
echo "failed to mount /boot"
exit 1
fi
fi
2024-10-13 10:23:21 +08:00
source versions.sh
GLSOURCES="/sources"
KVSTRING="${linux_lts_version}-lfs-12.2-systemd"
pushd ${GLSOURCES} > /dev/null 2>&1 || myfail "Failed to move to ${GLSOURCES}"
[ -d linux-${linux_lts_version} ] && rm -rf linux-${linux_lts_version}
tar -Jxf ${linux_lts_tarball}
cd linux-${linux_lts_version}
make mrproper
cp ../lts-kernel-config ./.config
make oldconfig
2024-10-13 13:01:39 +08:00
make
2024-10-13 10:23:21 +08:00
if [ $? -ne 0 ]; then
myfail "Failed building kernel"
fi
make modules_install
if [ $? -ne 0 ]; then
myfail "Failed building kernel modules"
fi
rm -f /lib/modules/${linux_lts_version}/build
rm -f /lib/modules/${linux_lts_version}/source
install -D -m644 .config /boot/config-${KVSTRING}
install -m644 System.map /boot/System.map-${KVSTRING}
install -m644 arch/x86_64/boot/bzImage /boot/vmlinuz-${KVSTRING}
2024-10-14 06:32:55 +08:00
[ ! -d /usr/share/doc/linux ] && mkdir -p /usr/share/doc/linux
2024-10-13 10:23:21 +08:00
cp -r Documentation /usr/share/doc/linux/linux-${linux_lts_version}
popd
# cleanup
pushd ${GLSOURCES}
rm -rf linux-${linux_lts_version}
# only write grub configuration for USBFlash
if [ ! -f /USBFlash ]; then
echo "Manually update the /boot/grub/grub.cfg file."
echo "In theory, you can shut down, remove the thumb drive, and boot!"
2024-10-13 22:02:09 +08:00
echo
echo "of course if it is a virgin /boot and this is first OS being installed"
echo "on it, you have to run grub-install /dev/whatever first."
2024-10-13 10:23:21 +08:00
exit 0
fi
[ ! -d /boot/grub ] && mkdir /boot/grub
cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5
insmod part_gpt
insmod ext2
2024-10-13 18:49:23 +08:00
search --set=root --fs-uuid add2119a-1a46-4c72-b212-863ee869ebd1
2024-10-13 10:23:21 +08:00
EOF
2024-10-13 18:49:23 +08:00
echo "#USB Flash Grub" >> /boot/grub/grub.cfg
2024-10-13 10:23:21 +08:00
echo "" >> /boot/grub/grub.cfg
2024-10-13 22:02:09 +08:00
echo "menuentry \"USB Flash GNU/Linux, Linux ${KVSTRING}\" {" \
2024-10-13 10:23:21 +08:00
>> /boot/grub/grub.cfg
2024-10-13 18:49:23 +08:00
echo " linux /boot/vmlinuz-${KVSTRING} root=PARTUUID=8d5d11ba-01 ro" \
2024-10-13 10:23:21 +08:00
>> /boot/grub/grub.cfg
echo "}" >> /boot/grub/grub.cfg
echo "Please verify /boot/grub/grub.cfg is correct."
2024-10-13 18:49:23 +08:00
echo "If so, run grub-install on USB Flash device inside the chroot."
2024-10-13 10:23:21 +08:00