1. 安装 LFS-Bootscripts-20150222
软件包包含一套在 LFS 系统启动和关闭时的启动和停止脚本。
cd /sources tar -jxf lfs-bootscripts-20150222.tar.bz2 cd lfs-bootscripts-20150222 make install cd /sources rm -rf lfs-bootscripts-20150222
2. 配置系统主机名称
echo "lfs" > /etc/hostname
3. 创建 /etc/hosts 文件
cat > /etc/hosts << "EOF" # Begin /etc/hosts (network card version) 127.0.0.1 localhost # End /etc/hosts (network card version) EOF
4. 配置 Sysvinit
内核初始化期间,第一个运行的程序默认是SysVinit,这个程序读取/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
View Code5. 安装 PiLFS-Bootscripts-20160219
软件包包含脚本的集合,以及针对树莓派硬件的一些修复
cd /sources tar -Jxf pilfs-bootscripts-20160219.tar.xz cd pilfs-bootscripts-20160219 make install-networkfix install-swapfix install-fake-hwclock install-switch-cpu-governor cd /sources rm -rf pilfs-bootscripts-20160219
6. 系统区域设置
cat > /etc/locale.conf << "EOF"
LANG=zh_CN.GB18030
EOF
7. 创建 /etc/inputrc 文件
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
View Code8. 创建 /etc/shells 文件
shells 文件是当前系统所有可用 shell 的列表文件
cat > /etc/shells << "EOF" # Begin /etc/shells /bin/sh /bin/bash # End /etc/shells EOF
9. LFS官方文档中还包含了其它可选配置,可按需添加
十. 让LFS系统可引导
1. 创建 /etc/fstab 文件
将宿主系统的分区放到 /home 目录下,第一次引导lfs系统后将不得不清除宿主系统
cat > /etc/fstab << "EOF" # Begin /etc/fstab
# file system mount-point type options dump fsck
# order
/dev/mmcblk0p1 /boot
vfat
defaults
0
0
/dev/mmcblk0p2 /home
ext4
defaults,noatime 0
1
/dev/mmcblk0p3 swap swap pri=1 0 0
/dev/mmcblk0p4 /
ext4
defaults,noatime 0
2
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
2. 内核和引导程序
当你可能可以编译你自己的Linux内核作为构建LFS的一部分时,强烈建议你确保系统首先正确的引导树莓派发行版的内核。
树莓派上没有GRUB,我们代替依赖树莓派发行版的 bootloader 去引导。
退出chroot,编辑 /boot/cmdline.txt ,将 root=/dev/mmcblk0p2 改为 root=/dev/mmcblk0p4
十. 最后
1. 创建 /etc/lfs-release 文件
cat > /etc/lsb-release << "EOF" DISTRIB_ID="Pi Linux From Scratch" DISTRIB_RELEASE="LFS-BOOK-SVN-20161221" DISTRIB_CODENAME="kevin" DISTRIB_DESCRIPTION="Pi Linux From Scratch" EOF
2. 安装配置 dhcpcd
cd /sources
tar -Jxf dhcpcd-6.11.5.tar.xz
cd dhcpcd-6.11.5
./configure --libexecdir=/lib/dhcpcd \
--dbdir=/var/lib/dhcpcd &&
make
make install
cd /sources
rm -rf dhcpcd-6.11.5
# 有线网络配置
cat > /etc/sysconfig/ifconfig.eth0 << "EOF"
ONBOOT="no"
IFACE="eth0"
SERVICE="dhcpcd"
DHCP_START="-b -q"
DHCP_STOP="-k"
EOF
# 无线网络配置
cat > /etc/sysconfig/ifconfig.wlan0 << "EOF"
ONBOOT="yes"
IFACE="wlan0"
SERVICE="wpa"
# Additional arguments to wpa_supplicant
WPA_ARGS=""
WPA_SERVICE="dhcpcd"
DHCP_START="-b -q"
DHCP_STOP="-k"
EOF
# wifi配置
cat > /etc/sysconfig/wpa_supplicant-wlan0.conf << "EOF"
network={
ssid="WiFi-name1"
psk="WiFi-password1"
priority=5
}
EOF
3. 安装 OpenSSH
# openssh依赖于openssl库,先安装openssl
cd /sources
tar -zxf openssl-1.0.2j.tar.gz
cd openssl-1.0.2j
./config --prefix=/usr
\
--openssldir=/etc/ssl \
--libdir=lib
\
shared
\
zlib-dynamic &&
make depend
&&
make
make MANDIR=/usr/share/man MANSUFFIX=ssl install &&
install -dv -m755 /usr/share/doc/openssl-1.0.2j &&
cp -vfr doc/*
/usr/share/doc/openssl-1.0.2j
cd /sources
rm -rf openssl-1.0.2j
# 安装openssh
cd /sources
tar -zxf openssh-7.4p1.tar.gz
cd openssh-7.4p1
install -v -m700 -d /var/lib/sshd &&
chown -v root:sys /var/lib/sshd &&
groupadd -g 50 sshd
&&
useradd -c 'sshd PrivSep' \
-d /var/lib/sshd \
-g sshd
\
-s /bin/false
\
-u 50 sshd
./configure --prefix=/usr
\
--sysconfdir=/etc/ssh
\
--with-md5-passwords
\
--with-privsep-path=/var/lib/sshd &&
make
make install &&
install -v -m755 contrib/ssh-copy-id /usr/bin
&&
install -v -m644 contrib/ssh-copy-id.1
/usr/share/man/man1
&&
install -v -m755 -d /usr/share/doc/openssh-7.4p1
&&
install -v -m644 INSTALL LICENCE OVERVIEW README*
/usr/share/doc/openssh-7.4p1
cd /sources
rm -rf openssh-7.4p1
# 系统启动时开启ssh服务
cd /sources
tar -Jxf blfs-bootscripts-20160902.tar.xz
cd blfs-bootscripts-20160902
make install-sshd
cd /sources
rm -rf blfs-bootscripts-20160902
4. 重启系统
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
十一. 如何将PiLFS做成TF卡镜像
1. 需要一台装有Linux系统的PC机
2. 将TF卡上的boot分区和PiLFS分区的内容分别复制到PC机上的bootfiles和lfsfiles文件夹下
3. 利用 gparted 格式化并重新划分TF卡:
/dev/sdb1 50M FAT32 boot分区
/dev/sdb2 2G EXT4 PiLFS分区
4. 使用 parted -l 命令查看并取得boot分区的开始位置(bootStart)和PiLFS分区的结束位置(lfsEnd)
5. 将bootfiles和lfsfiles文件夹下的内容分别复制到重新划分的boot分区和PiLFS分区
6. 利用dd命令将TF卡做成镜像:
dd if=/dev/sdb of=mylfs.img bs=1M count=2098
其中,bs为bootStart的值,count为lfsEnd的值