第四章 配置系统让系统可以启动
1. LFS-boot script
cd /sources
tar xvf lfs-bootscripts-20200818.tar.xz
cd lfs-bootscripts-20200818
make install
cd ..
rm -rf lfs-bootscripts-20200818
2. Create custom udev rules:
bash /lib/udev/init-net-rules.sh
cat /etc/udev/rules.d/70-persistent-net.rules
3. Create a network configuration file:
cd /etc/sysconfig/
cat > ifconfig.enp0s3 << "EOF"
ONBOOT=yes
IFACE=enp0s3
SERVICE=ipv4-static
IP=192.168.3.27
GATEWAY=192.168.3.1
PREFIX=24
BROADCAST=192.168.3.255
EOF
Configure the network file according to your actual configuration here. It is the first chapter, tell me the name of the network card, IP address and so on.
4. Create the /etc/resolv.conf file:
cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf
domain mylfs10.0
nameserver 192.168.3.1
# End /etc/resolv.conf
EOF
5. Configure the system host name:
echo "lfs10.0" > /etc/hostname
6. Create the /etc/hosts file:
cat > /etc/hosts << "EOF"
# Begin /etc/hosts
127.0.0.1 localhost
192.168.3.20 lfs10.0
# End /etc/hosts
EOF
7. Create the /etc/inittab file:
cat > /etc/inittab << "EOF"
# Begin /etc/inittab
id:3:initdefault:
si::sysinit:/etc/rc.d/init.d/rc S
l0:0:wait:/etc/rc.d/init.d/rc 0
l1:S1:wait:/etc/rc.d/init.d/rc 1
l2:2:wait:/etc/rc.d/init.d/rc 2
l3:3:wait:/etc/rc.d/init.d/rc 3
l4:4:wait:/etc/rc.d/init.d/rc 4
l5:5:wait:/etc/rc.d/init.d/rc 5
l6:6:wait:/etc/rc.d/init.d/rc 6
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
su:S016:once:/sbin/sulogin
1:2345:respawn:/sbin/agetty --noclear tty1 9600
2:2345:respawn:/sbin/agetty tty2 9600
3:2345:respawn:/sbin/agetty tty3 9600
4:2345:respawn:/sbin/agetty tty4 9600
5:2345:respawn:/sbin/agetty tty5 9600
6:2345:respawn:/sbin/agetty tty6 9600
# End /etc/inittab
EOF
8. Create the /etc/sysconfig/clock file:
cat > /etc/sysconfig/clock << "EOF"
# Begin /etc/sysconfig/clock
UTC=1
# Set this to any options you might need to give to hwclock,
# such as machine hardware clock type for Alphas.
CLOCKPARAMS=
# End /etc/sysconfig/clock
EOF
9. Configure the console language environment and create the /etc/profile file:
cat > /etc/locale.conf << "EOF"
LANG=en_US.UTF-8
EOF
cat > /etc/profile << "EOF"
# Begin /etc/profile
export LANG=en_US.UTF-8
# End /etc/profile
EOF
10. Create /etc/inputrc file:
cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc
# Modified by Chris Lynn <[email protected]>
# Allow the command prompt to wrap to the next line
set horizontal-scroll-mode Off
# Enable 8bit input
set meta-flag On
set input-meta On
# Turns off 8th bit stripping
set convert-meta Off
# Keep the 8th bit for display
set output-meta On
# none, visible or audible
set bell-style none
# All of the following map the escape sequence of the value
# contained in the 1st argument to the readline specific functions
"\eOd": backward-word
"\eOc": forward-word
# for linux console
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert
# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line
# for Konsole
"\e[H": beginning-of-line
"\e[F": end-of-line
# End /etc/inputrc
EOF
11. Create /etc/shells file
cat > /etc/shells << "EOF"
# Begin /etc/shells
/bin/sh
/bin/bash
# End /etc/shells
EOF
12. Create the /etc/fstab file:
cat > /etc/fstab << "EOF"
# Begin /etc/fstab
# file system mount-point type options dump fsck
# order
/dev/sda2 / ext4 defaults 1 1
/dev/sda1 swap swap pri=1 0 0
proc /proc proc nosuid,noexec,nodev 0 0
sysfs /sys sysfs nosuid,noexec,nodev 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /run tmpfs defaults 0 0
devtmpfs /dev devtmpfs mode=0755,nosuid 0 0
# End /etc/fstab
EOF
Here you need to change <XXX> (system boot disk), <yyy> (system swap partition), and <fff> (boot disk partition format).
13. Configure, compile and install the linux5.8.3 kernel:
cd /sources
tar xvf linux-5.8.3.tar.xz
cd linux-5.8.3
make mrproper
make defconfig
make menuconfig
Make sure of the following options:
Device Drivers --->
Generic Driver Options --->
[ ] Support for uevent helper [CONFIG_UEVENT_HELPER]
[*] Maintain a devtmpfs filesystem to mount at /dev [CONFIG_DEVTMPFS]
Processor type and features --->
[*] EFI stub support [CONFIG_EFI_STUB]
General setup -->
[*] Control Group support [CONFIG_CGROUPS]
After configuration, save and exit.
Compile the kernel image and modules and install:
make
make modules_install
Move the kernel image to /boot (x86 architecture):
cp -iv arch/x86/boot/bzImage /boot/vmlinuz-5.8.3-lfs-10.0
The symbol file of the kernel:
cp -iv System.map /boot/System.map-5.8.3
Documentation for installing the Linux kernel:
install -d /usr/share/doc/linux-5.8.3
cp -r Documentation/* /usr/share/doc/linux-5.8.3
Create the /etc/modprobe.d/usb.conf file:
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
14. Set up the GRUB boot process.
Install the GRUB file to /boot/grub and set the boot sector:
grub-install /dev/sda
Create the /boot/grub/grub.cfg file:
cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5
insmod ext2
set root=(hd0,2)
menuentry "GNU/Linux, Linux 5.8.3-lfs-10.0" {
linux /boot/vmlinuz-5.8.3-lfs-10.0 root=/dev/sda2 ro
}
EOF
15. Create the /etc/lfs-release file:
echo 10.0 > /etc/lfs-release
16. Create the /etc/lsb-release file:
cat > /etc/lsb-release << "EOF"
DISTRIB_ID="Linux From Scratch"
DISTRIB_RELEASE="10.0"
DISTRIB_CODENAME="<your name here>"
DISTRIB_DESCRIPTION="Linux From Scratch"
EOF
17. Create the /etc/os-release file:
cat > /etc/os-release << "EOF"
NAME="Linux From Scratch"
VERSION="10.0"
ID=lfs
PRETTY_NAME="Linux From Scratch 10.0"
VERSION_CODENAME="<your name here>"
EOF
18. The last step is to restart the system and
exit the chroot environment:
logout
Unmount the virtual file system:
umount -v $LFS/dev/pts
umount -v $LFS/dev
umount -v $LFS/run
umount -v $LFS/proc
umount -v $LFS/sys
Unmount the primary partition:
umount -v $LFS
Reboot the system:
shutdown -r now
Next, Blfs struggles!
I hope everyone can criticize and correct the shortcomings!
Thank you for watching~! ~