前言
接【LFS-Linux From Scratch】LFS系统编译文。
这里开始真正的系统创建。
开始之前要重新chroot,具体的命令下:
mount -v --bind /dev $LFS/dev
mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run
chroot "$LFS" /usr/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/bash --login
注意跟之前chroot不同的是/usr/bin/env而不再是/tools/bin/env了。
当然除了chroot,mount硬盘之类的操作也还需要。
安装启动脚本
将lfs-bootscripts-20150222.tar.bz2解压到/etc目录下并进入解压后的目录。
运行如下的命令:
make install
结果如下:
root:/etc/lfs-bootscripts-20150222# make install
install -d -m 755 /etc/rc.d/rc0.d
install -d -m 755 /etc/rc.d/rc1.d
install -d -m 755 /etc/rc.d/rc2.d
install -d -m 755 /etc/rc.d/rc3.d
install -d -m 755 /etc/rc.d/rc4.d
install -d -m 755 /etc/rc.d/rc5.d
install -d -m 755 /etc/rc.d/rc6.d
install -d -m 755 /etc/rc.d/rcS.d
install -d -m 755 /etc/rc.d/init.d
install -d -m 755 /etc/sysconfig
install -d -m 755 /lib
install -d -m 755 /lib/services
install -d -m 755 /usr/share/man/man8
install -d -m 755 /sbin
ln -sfn services /lib/lsb
ln -sfn rc.d/init.d /etc/init.d
install -m 754 lfs/init.d/checkfs /etc/rc.d/init.d/
install -m 754 lfs/init.d/cleanfs /etc/rc.d/init.d/
install -m 754 lfs/init.d/halt /etc/rc.d/init.d/
install -m 754 lfs/init.d/console /etc/rc.d/init.d/
install -m 754 lfs/init.d/localnet /etc/rc.d/init.d/
install -m 754 lfs/init.d/modules /etc/rc.d/init.d/
install -m 754 lfs/init.d/mountfs /etc/rc.d/init.d/
install -m 754 lfs/init.d/mountvirtfs /etc/rc.d/init.d/
install -m 754 lfs/init.d/network /etc/rc.d/init.d/
install -m 754 lfs/init.d/rc /etc/rc.d/init.d/
install -m 754 lfs/init.d/reboot /etc/rc.d/init.d/
install -m 754 lfs/init.d/sendsignals /etc/rc.d/init.d/
install -m 754 lfs/init.d/setclock /etc/rc.d/init.d/
install -m 754 lfs/init.d/swap /etc/rc.d/init.d/
install -m 754 lfs/init.d/sysctl /etc/rc.d/init.d/
install -m 754 lfs/init.d/sysklogd /etc/rc.d/init.d/
install -m 754 lfs/init.d/template /etc/rc.d/init.d/
install -m 754 lfs/init.d/udev /etc/rc.d/init.d/
install -m 754 lfs/init.d/udev_retry /etc/rc.d/init.d/
install -m 754 lfs/sbin/ifup /sbin
install -m 754 lfs/sbin/ifdown /sbin
install -m 644 lfs/sbin/ifup.8 /usr/share/man/man8
ln -sf ifup.8 /usr/share/man/man8/ifdown.8
install -m 754 lfs/lib/services/ipv4-static-route /lib/services
install -m 754 lfs/lib/services/ipv4-static /lib/services
install -m 644 lfs/lib/services/init-functions /lib/services
if [ ! -f /etc/sysconfig/createfiles ]; then \
install -m 644 lfs/sysconfig/createfiles /etc/sysconfig/ ;\
fi
if [ ! -f /etc/sysconfig/modules ]; then \
install -m 644 lfs/sysconfig/modules /etc/sysconfig/ ;\
fi
if [ ! -f /etc/sysconfig/udev_retry ]; then \
install -m 644 lfs/sysconfig/udev_retry /etc/sysconfig/ ;\
fi
if [ ! -f /etc/sysconfig/rc.site ]; then \
install -m 644 lfs/sysconfig/rc.site /etc/sysconfig/ ;\
fi
ln -sf ../init.d/mountvirtfs /etc/rc.d/rcS.d/S00mountvirtfs
ln -sf ../init.d/modules /etc/rc.d/rcS.d/S05modules
ln -sf ../init.d/localnet /etc/rc.d/rcS.d/S08localnet
ln -sf ../init.d/udev /etc/rc.d/rcS.d/S10udev
ln -sf ../init.d/swap /etc/rc.d/rcS.d/S20swap
ln -sf ../init.d/checkfs /etc/rc.d/rcS.d/S30checkfs
ln -sf ../init.d/mountfs /etc/rc.d/rcS.d/S40mountfs
ln -sf ../init.d/cleanfs /etc/rc.d/rcS.d/S45cleanfs
ln -sf ../init.d/udev_retry /etc/rc.d/rcS.d/S50udev_retry
ln -sf ../init.d/console /etc/rc.d/rcS.d/S70console
ln -sf ../init.d/sysctl /etc/rc.d/rcS.d/S90sysctl
ln -sf ../init.d/network /etc/rc.d/rc0.d/K80network
ln -sf ../init.d/sysklogd /etc/rc.d/rc0.d/K90sysklogd
ln -sf ../init.d/sendsignals /etc/rc.d/rc0.d/S60sendsignals
ln -sf ../init.d/swap /etc/rc.d/rc0.d/S65swap
ln -sf ../init.d/mountfs /etc/rc.d/rc0.d/S70mountfs
ln -sf ../init.d/localnet /etc/rc.d/rc0.d/S90localnet
ln -sf ../init.d/halt /etc/rc.d/rc0.d/S99halt
ln -sf ../init.d/network /etc/rc.d/rc1.d/K80network
ln -sf ../init.d/sysklogd /etc/rc.d/rc1.d/K90sysklogd
ln -sf ../init.d/network /etc/rc.d/rc2.d/K80network
ln -sf ../init.d/sysklogd /etc/rc.d/rc2.d/K90sysklogd
ln -sf ../init.d/sysklogd /etc/rc.d/rc3.d/S10sysklogd
ln -sf ../init.d/network /etc/rc.d/rc3.d/S20network
ln -sf ../init.d/sysklogd /etc/rc.d/rc4.d/S10sysklogd
ln -sf ../init.d/network /etc/rc.d/rc4.d/S20network
ln -sf ../init.d/sysklogd /etc/rc.d/rc5.d/S10sysklogd
ln -sf ../init.d/network /etc/rc.d/rc5.d/S20network
ln -sf ../init.d/network /etc/rc.d/rc6.d/K80network
ln -sf ../init.d/sysklogd /etc/rc.d/rc6.d/K90sysklogd
ln -sf ../init.d/sendsignals /etc/rc.d/rc6.d/S60sendsignals
ln -sf ../init.d/swap /etc/rc.d/rc6.d/S65swap
ln -sf ../init.d/mountfs /etc/rc.d/rc6.d/S70mountfs
ln -sf ../init.d/localnet /etc/rc.d/rc6.d/S90localnet
ln -sf ../init.d/reboot /etc/rc.d/rc6.d/S99reboot
可以看到主要是安装了rc.d和sysconfig。
设备相关的操作
下面介绍设备相关的操作。
创建默认的udev规则
网络配置
cd /etc/sysconfig/
cat > ifconfig.eth0 << "EOF"
ONBOOT=yes
IFACE=eth0
SERVICE=ipv4-static
IP=192.168.1.2
GATEWAY=192.168.1.1
PREFIX=24
BROADCAST=192.168.1.255
EOF
cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf
domain <Your Domain Name>
nameserver 8.8.8.8
nameserver 8.8.4.4
# End /etc/resolv.conf
EOF
echo "lfs" > /etc/hostname
cat > /etc/hosts << "EOF"
# Begin /etc/hosts (no network card version)
127.0.0.1 localhost
127.0.1.1 lfs
# End /etc/hosts (no network card version)
EOF
这里的有些配置是参考手册的,有些是参考原本机器上的,现在还不确定是否有问题。
System V启动脚本配置
创建/etc/inittab文件:
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
创建/etc/sysconfig/clock文件:
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
创建/etc/sysconfig/console文件:
cat > /etc/sysconfig/console << "EOF"
# Begin /etc/sysconfig/console
KEYMAP="pl2"
FONT="lat2a-16 -m 8859-2"
# End /etc/sysconfig/console
EOF
通过/etc/sysconfig/rc.site可以修改启动的配置。
创建/etc/profile文件:
cat > /etc/profile << "EOF"
# Begin /etc/profile
export LANG=zh_CN.UTF-8
# End /etc/profile
EOF
这里的LANG是在编译服务器上通过echo $LANG获取到的。
创建/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 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
创建/etc/shalls文件:
cat > /etc/shells << "EOF"
# Begin /etc/shells
/bin/sh
/bin/bash
# End /etc/shells
EOF
让LFS系统可启动
创建/etc/fstab文件:
cat > /etc/fstab << "EOF"
# Begin /etc/fstab
# file system mount-point type options dump fsck
#
/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
这里的/dev/sdcx和ext4是根据实际情况确定的。
内核编译
1. 首先解压linux-4.9.9.tar.xz,并进入该目录;
2. 运行make mrproper;
3. 创建默认的config文件:make defconfig;
4. 执行make menuconfig进行一些配置;
5. make编译;
6. make modules_install;
7. 文件拷贝:
cp -v arch/x86/boot/bzImage /boot/vmlinuz-4.9.9-lfs-8.0
cp -v System.map /boot/System.map-4.9.9
cp -v .config /boot/config-4.9.9
install -d /usr/share/doc/linux-4.9.9
cp -r Documentation/* /usr/share/doc/linux-4.9.9
其他的一些配置:
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安装和配置:
grub-install /dev/sdc -d /usr/lib/grub/i386-pc/
cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5
insmod ext4
set root=(hd0,2)
menuentry "GNU/Linux, Linux 4.9.9-lfs-8.0" {
linux /boot/vmlinuz-4.9.9-lfs-8.0 root=/dev/sda2 ro
}
EOF
这里root= insmod之后的值可能需要根据实际情况更改的。
尾声
以上是LFS系统构建的所有内容。
之后是一些收尾的操作:
1. 设定版本:
echo 8.0 > /etc/lfs-release
cat > /etc/lsb-release << "EOF"
DISTRIB_ID="Linux From Scratch"
DISTRIB_RELEASE="8.0"
DISTRIB_CODENAME="<your name here>"
DISTRIB_DESCRIPTION="Linux From Scratch"
EOF
2. 退出系统:
logout
umount -v $LFS/dev/pts
umount -v $LFS/dev
umount -v $LFS/run
umount -v $LFS/proc
umount -v $LFS/sys
umount -v $LFS
shutdown -r now