本文同步發(fā)布于
https://williamgong.github.io/2021/12/03/lfs%E6%90%AD%E5%BB%BA7/
現(xiàn)在進入最后一部分,內(nèi)核與 GRUB 的安裝。
構(gòu)建 Linux 內(nèi)核
先解壓:
tar -xvf linux-5.13.12.tar.xz
cd linux-5.13.12
清理源碼樹,雖然才解壓沒什么必要:
make mrproper
配置
此處使用:
make menuconfig
原來我一直想使用 arch 的配置然后
oldconfig,但試了很多次后機器啟動一直失敗。
配置選項說明參見金步國的博客:http://www.jinbuguo.com/kernel/longterm-linux-kernel-options.html
雖然是 4.4 的,但大部分選項都沒變,尤其是驅(qū)動相關(guān)。
盡量不要改默認的配置,驅(qū)動相關(guān)的另說。
下面是具體的配置選項:
General setup 下:
[*] Control Group support --->
# 手冊里沒有,但 systemd 建議打開
[*] Checkpoint/restore support
[*] Configure standard kernel features (expert users) --->
# 子選項需要關(guān)閉以下幾個:
[ ] Enable 16-bit UID system calls
[ ] sgetmask/ssetmask syscalls support
[ ] Sysfs syscall support
# 這個取決于主板有沒有蜂鳴器
[ ] Enable PC-Speaker support
Processor type and features 下:
# EFI 的支持選項:
[*] EFI runtime service support
[*] EFI stub support
[*] EFI mixed-mode support
# 虛擬機需要的選項
[*] Linux guest support --->
# 半虛擬化
[*] Enable paravirtualization code
# KVM
[*] KVM Guest support (including kvmclock)
Firmware Drivers 下
[*] Export DMI identification via sysfs to userspace
EFI (Extensible Firmware Interface) Support --->
< > EFI Variable Support via sysfs
[*] Export efi runtime maps to sysfs
Networking support 下:
Networking options --->
<*> The IPv6 protocol --->
[*] Enable the block layer 下:
Partition Types --->
[*] Advanced partition selection
[*] EFI GUID Partition support
Device Drivers 下:
Generic Driver Options --->
[ ] Support for uevent helper
[*] Maintain a devtmpfs filesystem to mount at /dev
Firmware loader --->
[ ] Enable the firmware sysfs fallback mechanism
Graphics support --->
Frame buffer Devices --->
--- Support for frame buffer devices
[*] EFI-based Framebuffer Support
Console display driver support --->
[*] Framebuffer Console support
File systems 下:
[*] Inotify support for userspace
Pseudo filesystems --->
[*] Tmpfs POSIX Access Control Lists
# 這里可以打成模塊也可以直接打進內(nèi)核
<M> EFI Variable filesystem
其他的都不用管。
由于 LFS 不使用 initramfs,所以盡量打包進內(nèi)核,尤其是文件系統(tǒng)相關(guān)的不要打成模塊。
安裝
配置完成,現(xiàn)在開始編譯:
make
安裝模塊:
make modules_install
復(fù)制內(nèi)核:
cp -iv arch/x86_64/boot/bzImage /boot/vmlinuz-5.13.12-lfs-11.0-systemd
此處的內(nèi)核文件名稱可以自行改變,但要以vmlinuz-開頭。
復(fù)制System.map:
cp -iv System.map /boot/System.map-5.13.12
手冊這里將配置.config保存到了/boot,但我是認為只要不刪除源碼,放源碼樹里就行了。
如果要復(fù)制配置的話,運行;
cp -iv .config /boot/config-5.13.12
安裝內(nèi)核文檔:
install -d /usr/share/doc/linux-5.13.12
cp -r Documentation/* /usr/share/doc/linux-5.13.12
因為不刪除源碼樹要留以后用,而且源碼樹里可能有不屬于root的文件,現(xiàn)在要切出目錄改變所有者:
chown -R 0:0 .
配置 Linux 內(nèi)核模塊加載順序
創(chuàng)建文件:
install -v -m755 -d /etc/modprobe.d
cat > /etc/modprobe.d/usb.conf << "EOF"
# Begin /etc/modprobe.d/usb.conf
install ohci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i ohci_hcd ; true
install uhci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i uhci_hcd ; true
# End /etc/modprobe.d/usb.conf
EOF
安裝 GRUB
掛載 EFI 變量文件系統(tǒng)
打開 UEFI 支持的 grub 需要文件系統(tǒng)efivars。
因為需要文件/sys/firmware/efi/efivars,而這個文件在非 UEFI 的機器上是不存在的,因此對于我來說需要將 LFS 硬盤遷移到目標機器掛載,現(xiàn)在就需要 live CD 了。
運行:
mountpoint /sys/firmware/efi/efivars || mount -v -t efivarfs efivarfs /sys/firmware/efi/efivars
然后安裝 grub:
grub-install --bootloader-id=LFS --recheck
手動寫入grub.cfg:
cat > /boot/grub/grub.cfg << EOF
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5
insmod part_gpt
insmod ext2
set root=(hd0,3)
if loadfont /boot/grub/fonts/unicode.pf2; then
set gfxmode=auto
insmod all_video
terminal_output gfxterm
fi
menuentry "GNU/Linux, Linux 5.13.12-lfs-11.0-systemd" {
linux /boot/vmlinuz-5.13.12-lfs-11.0-systemd root=/dev/sda3 ro
}
menuentry "Firmware Setup" {
fwsetup
}
EOF
收尾
現(xiàn)在手冊會創(chuàng)建一些描述文件,模板在這,不喜歡可以跳過:
echo 11.0-systemd > /etc/lfs-release
cat > /etc/lsb-release << "EOF"
DISTRIB_ID="Linux From Scratch"
DISTRIB_RELEASE="11.0-systemd"
DISTRIB_CODENAME="<your name here>"
DISTRIB_DESCRIPTION="Linux From Scratch"
EOF
cat > /etc/os-release << "EOF"
NAME="Linux From Scratch"
VERSION="11.0-systemd"
ID=lfs
PRETTY_NAME="Linux From Scratch 11.0-systemd"
VERSION_CODENAME="<your name here>"
EOF
現(xiàn)在是時候重啟了。
退出 chroot:
logout
解掛載:
umount -Rv $LFS
重啟
reboot
至此,LFS 安裝完成。