1. 系统配置
开始前先参照前面的内网完成相关组件的编译安装 https://wiki.waringid.me/x/XwC1B
1.1. System V
System V 是自 1983 年以来就在 Unix 和 Linux 等类 Unix 系统中被广泛应用的经典引导过程。它包含一个小程序 init,该程序设定 login (通过 getty) 等基本进程,并运行一个脚本。该脚本一般被命名为 rc,控制一组附加脚本的运行,这些附加脚本完成初始化系统需要的各项工作。
init 程序受到 /etc/inittab 文件的控制,被组织为用户可以选择的系统运行级别。在 LFS 中,运行级别定义为:
- 0 — 停止运行
- 1 — 单用户模式
- 2 — 用户自定义模式
- 3 — 完整的多用户模式
- 4 — 用户自定义模式
- 5 — 拥有显示管理器的完整多用户模式
- 6 — 重启系统
通常的默认运行级别是 3 或 5。
优点
- 完备的,已经被详细理解的系统。
- 容易定制。
缺点
- 引导速度较慢。一个中等速度的基本 LFS 系统从第一个内核消息开始,到出现登录提示符为止,需要 8-12 秒的引导时间,之后还需要约 2 秒启动网络连接。
- 串行执行引导任务。这与前一项缺点相关。引导过程中的延迟 (如文件系统检查) 会拖延整个引导过程。
- 不支持控制组 (cgroups) 和每用户公平共享调度等高级特性。
- 添加脚本时,需要手动决定它在引导过程中的次序。
1.2. LFS-Bootscripts-20240825
tar xvf lfs-bootscripts-20240825.tar.xz cd lfs-bootscripts-20240825 make install
1.3. 管理设备
创建自定义 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
1.4. 一般网络配置
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
1.5. System V 引导脚本使用与配置
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
1.6. 创建 /etc/inputrc 文件
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
1.7. 创建 /etc/shells 文件
cat > /etc/shells << "EOF" # Begin /etc/shells /bin/sh /bin/bash # End /etc/shells EOF
2. 使 LFS 系统可引导
创建 /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
2.1. Linux-6.13.4
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
2.2. 使用 GRUB 设定引导过程
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
3. 收尾工作
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
4. 重启系统
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
- 无标签
0 评论