开始前先参照前面的内网完成相关组件的编译安装 https://wiki.waringid.me/x/XwC1B
System V 是自 1983 年以来就在 Unix 和 Linux 等类 Unix 系统中被广泛应用的经典引导过程。它包含一个小程序 init,该程序设定 login (通过 getty) 等基本进程,并运行一个脚本。该脚本一般被命名为 rc,控制一组附加脚本的运行,这些附加脚本完成初始化系统需要的各项工作。
init 程序受到 /etc/inittab 文件的控制,被组织为用户可以选择的系统运行级别。在 LFS 中,运行级别定义为:
通常的默认运行级别是 3 或 5。
优点
缺点
tar xvf lfs-bootscripts-20240825.tar.xz cd lfs-bootscripts-20240825 make install |
创建自定义 Udev 规则
bash /usr/lib/udev/init-net-rules.sh cat /etc/udev/rules.d/70-persistent-net.rules sed -e '/^AlternativeNamesPolicy/s/=.*$/=/' \ /usr/lib/udev/network/99-default.link \ > /etc/udev/network/99-default.link udevadm test /sys/block/hdd sed -e 's/"write_cd_rules"/"write_cd_rules mode"/' \ -i /etc/udev/rules.d/83-cdrom-symlinks.rules |
cd /etc/sysconfig/ cat > ifconfig.eth0 << "EOF" ONBOOT=yes IFACE=eth0 SERVICE=DHCP EOF cat > /etc/resolv.conf << "EOF" # Begin /etc/resolv.conf domain lfs.local nameserver 119.29.29.29 nameserver 223.5.5.5 # End /etc/resolv.conf EOF echo "LFS" > /etc/hostname cat > /etc/hosts << "EOF" # Begin /etc/hosts 127.0.0.1 localhost.localdomain localhost 127.0.1.1 <FQDN> <HOSTNAME> <192.168.1.2> <FQDN> <HOSTNAME> [alias1] [alias2 ...] ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters # End /etc/hosts EOF |
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:S06:once:/sbin/sulogin s1:1:respawn:/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 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 cat > /etc/profile << "EOF" # Begin /etc/profile for i in $(locale); do unset ${i%=*} done if [[ "$TERM" = linux ]]; then export LANG=C.UTF-8 else export LANG=zh_CN.gb18030 fi # End /etc/profile EOF |
cat > /etc/inputrc << "EOF" # Begin /etc/inputrc # Modified by Chris Lynn <roryo@roryo.dynup.net> # Allow the command prompt to wrap to the next line set horizontal-scroll-mode Off # Enable 8-bit 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 |
cat > /etc/shells << "EOF" # Begin /etc/shells /bin/sh /bin/bash # End /etc/shells EOF |
创建 /etc/fstab 文件
cat > /etc/fstab << "EOF" # Begin /etc/fstab # 文件系统 挂载点 类型 选项 转储 检查 # 顺序 /dev/sdb1 /boot ext2 defaults 1 1 /dev/sdb3 / ext4 defaults 1 1 /dev/sdb2 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 tmpfs /dev/shm tmpfs nosuid,nodev 0 0 cgroup2 /sys/fs/cgroup cgroup2 nosuid,noexec,nodev 0 0 # End /etc/fstab EOF |
tar xvf linux-6.13.4.tar.xz cd linux-6.13.4 make mrproper make menuconfig make make modules_install mount -v -t ext2 /dev/sdb1 /boot cp -iv arch/x86/boot/bzImage /boot/vmlinuz-6.13.4-lfs-12.3 cp -iv System.map /boot/System.map-6.13.4 cp -iv .config /boot/config-6.13.4 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-install /dev/sdb 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,msdos1) set gfxpayload=1024x768x32 menuentry "GNU/Linux, Linux 6.13.4-lfs-12.3" { linux /vmlinuz-6.13.4-lfs-12.3 root=/dev/sda1 ro } EOF |
echo 12.3 > /etc/lfs-release cat > /etc/lsb-release << "EOF" DISTRIB_ID="Linux From Scratch" DISTRIB_RELEASE="12.3" DISTRIB_CODENAME="waringid" DISTRIB_DESCRIPTION="Linux From Scratch" EOF cat > /etc/os-release << "EOF" NAME="Linux From Scratch" VERSION="12.3" ID=lfs PRETTY_NAME="Linux From Scratch 12.3" VERSION_CODENAME="waringid" HOME_URL="https://www.linuxfromscratch.org/lfs/" RELEASE_TYPE="stable" EOF |
logout umount -v $LFS/dev/pts mountpoint -q $LFS/dev/shm && umount -v $LFS/dev/shm umount -v $LFS/dev umount -v $LFS/run umount -v $LFS/proc umount -v $LFS/sys umount -v $LFS/home umount -v $LFS/boot umount -v $LFS |