Raspberry Pi(树莓派)上从零开始构建Linux系统(简称PiLFS)(三)

九. 系统配置

  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. 管理网络设备

# 运行以下命令,创建网络设备 Udev 规则
bash /lib/udev/init-net-rules.sh

# 查看生成的规则
cat /etc/udev/rules.d/70-persistent-net.rules

  3. 配置系统主机名称

echo "lfs" > /etc/hostname

  4. 创建 /etc/hosts  文件

cat > /etc/hosts << "EOF"
# Begin /etc/hosts (network card version)

127.0.0.1 localhost

# End /etc/hosts (network card version)
EOF
View Code

  5. 配置 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 Code

  6. 安装 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

  7. Bash 启动文件

cat > /etc/profile << "EOF"
# Begin /etc/profile

export LANG=en_US.UTF-8

# End /etc/profile
EOF
View Code

  8. 创建 /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 Code

  9. 创建 /etc/shells 文件

    shells 文件是当前系统所有可用 shell  的列表文件

cat > /etc/shells << "EOF"
# Begin /etc/shells

/bin/sh
/bin/bash

# End /etc/shells
EOF
View Code

  10. LFS官方文档中还包含了其它可选配置,可按需添加

 

十. 让LFS系统可引导

  1. 创建 /etc/fstab 文件   

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 /            ext4     defaults,noatime    0     1
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
View Code

  2. 编译安装内核  

mkdir /mnt/boot
mount /dev/sda1 /mnt/boot

cd /sources
tar -zxf rpi-4.4.y.tar.gz
cd linux-rpi-4.4.y

make mrproper
sed -i 's/EXTRAVERSION =.*/EXTRAVERSION = +/' Makefile
make bcm2709_defconfig

make
make modules_install

cp -v arch/arm/boot/zImage /boot/kernel7.img
cp -v arch/arm/boot/dts/bcm2709-rpi-2-b.dtb /boot/
cp -v arch/arm/boot/dts/bcm2710-rpi-3-b.dtb /boot/
cp -v arch/arm/boot/dts/bcm2710-rpi-cm3.dtb /boot/

umount /mnt/boot
View Code


十一. 最后

  1. 创建 /etc/lfs-release 文件

cat > /etc/lsb-release << "EOF"
DISTRIB_ID="Pi Linux From Scratch"
DISTRIB_RELEASE="7.10"
DISTRIB_CODENAME="kevin"
DISTRIB_DESCRIPTION="Pi Linux From Scratch"
EOF
View Code

  2. 安装 OpenSSH

# openssh依赖于openssl库,先安装openssl 
cd /sources
tar -zxf openssl-1.0.2h.tar.gz
cd openssl-1.0.2h

./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.2h  &&
cp -vfr doc/*     /usr/share/doc/openssl-1.0.2h

cd /sources
rm -rf openssl-1.0.2h

 # 安装openssh
cd /sources
tar -zxf openssh-7.3p1.tar.gz
cd openssh-7.3p1

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.3p1     &&
install -v -m644    INSTALL LICENCE OVERVIEW README* \
                    /usr/share/doc/openssh-7.3p1

cd /sources 
rm -rf openssh-7.3p1

# 系统启动时开启ssh服务 
cd /sources 
tar -Jxf blfs-bootscripts-20160902.tar.xz 
cd blfs-bootscripts-20160902 
make install-sshd 
cd /sources 
rm -rf blfs-bootscripts-20160902
View Code

  3. 安装 dhcpcd

cd /sources
tar -Jxf dhcpcd-6.11.3.tar.xz
cd dhcpcd-6.11.3

./configure --libexecdir=/lib/dhcpcd \
            --dbdir=/var/lib/dhcpcd  &&
make

make install
cd /sources
rm -rf dhcpcd-6.11.3

#安装dhcpcd服务,网络断掉时执行hook脚本
cd /sources
tar -Jxf blfs-bootscripts-20160902.tar.xz
cd blfs-bootscripts-20160902
make install-service-dhcpcd
cd /sources
rm -rf blfs-bootscripts-20160902
View Code

  4. 安装 wpa_supplicant

# wpa_supplicant依赖于libnl-3库,先安装libnl-3
cd /sources
tar -zxf libnl-3.2.28.tar.gz
cd libnl-3.2.28

./configure --prefix=/usr     \
            --sysconfdir=/etc \
            --disable-static  &&
make

make install
cd /sources
rm -rf libnl-3.2.28


# 安装wpa_supplicant
cd /sources
tar -zxf wpa_supplicant-2.5.tar.gz
cd wpa_supplicant-2.5

cat > wpa_supplicant/.config << "EOF"
CONFIG_BACKEND=file
CONFIG_CTRL_IFACE=y
CONFIG_DEBUG_FILE=y
CONFIG_DEBUG_SYSLOG=y
CONFIG_DEBUG_SYSLOG_FACILITY=LOG_DAEMON
CONFIG_DRIVER_NL80211=y
CONFIG_DRIVER_WEXT=y
CONFIG_DRIVER_WIRED=y
CONFIG_EAP_GTC=y
CONFIG_EAP_LEAP=y
CONFIG_EAP_MD5=y
CONFIG_EAP_MSCHAPV2=y
CONFIG_EAP_OTP=y
CONFIG_EAP_PEAP=y
CONFIG_EAP_TLS=y
CONFIG_EAP_TTLS=y
CONFIG_IEEE8021X_EAPOL=y
CONFIG_IPV6=y
CONFIG_LIBNL32=y
CONFIG_PEERKEY=y
CONFIG_PKCS12=y
CONFIG_READLINE=y
CONFIG_SMARTCARD=y
CONFIG_WPS=y
CFLAGS += -I/usr/include/libnl3
EOF

cd wpa_supplicant &&
make BINDIR=/sbin LIBDIR=/lib

install -v -m755 wpa_{cli,passphrase,supplicant} /sbin/ &&
install -v -m644 doc/docbook/wpa_supplicant.conf.5 /usr/share/man/man5/ &&
install -v -m644 doc/docbook/wpa_{cli,passphrase,supplicant}.8 /usr/share/man/man8/

cd /sources
rm -rf wpa_supplicant-2.5


# 系统启动时自动加载wpa服务
cd /sources
tar -Jxf blfs-bootscripts-20160902.tar.xz
cd blfs-bootscripts-20160902
make install-service-wpa
cd /sources
rm -rf blfs-bootscripts-20160902
View Code

  5. 网络配置:复制到命令行执行前,记得把中文注释去掉,否则会出错

# 有线网络配置
cat > /etc/sysconfig/ifconfig.eth0 << "EOF"
ONBOOT="no"
IFACE="eth0"

# 静态IP
SERVICE="ipv4-static"
IP="192.168.1.2"
# 网关
GATEWAY="192.168.1.1"
# 子网掩码
PREFIX="24"
# 广播域
BROADCAST="192.168.1.255"


# 动态IP
#SERVICE="dhcpcd"
# -b background 后台运行
# -q quite 消息仍被记录,但是只有告警或错误的信息被打印
#DHCP_START="-b -q"
# -k release 退出前释放租期
#DHCP_STOP="-k"

EOF


# 无线网络配置
cat > /etc/sysconfig/ifconfig.wlan0 << "EOF"
ONBOOT="no" 
IFACE="wlan0" 
SERVICE="wpa"

# Additional arguments to wpa_supplicant 
WPA_ARGS=""

# 动态IP
WPA_SERVICE="dhcpcd"
DHCP_START="-b -q"
DHCP_STOP="-k"

# 静态IP
#WPA_SERVICE="ipv4-static"
#IP="192.168.1.2"
#GATEWAY="192.168.1.1"
#PREFIX="24"
#BROADCAST="192.168.1.255"

EOF


# WIFI配置
cat > /etc/sysconfig/wpa_supplicant-wlan0.conf << "EOF"
network={
ssid="WiFi-name1"
psk="WiFi-password1"
priority=5
}
EOF
View Code

  6. 安装WIFI固件

      RPi3 内置 WiFi 驱动 brcmfmac,需要二进制固件包 brcmfmac43430-sdio.bin

    和配置文件 brcmfmac43430-sdio.txt 才能正确地运行。点击此 找到并下载这两个文件,

    并放到 /lib/firmware/brcm/ 文件夹下,没有该文件夹则创建。

  7. 卸载文件系统

logout

umount -v $LFS/dev/pts
umount -v $LFS/dev
umount -v $LFS/run
umount -v $LFS/proc
umount -v $LFS/sys

rm -rf $LFS/sources
umount -v $LFS

 

十二. 如何将PiLFS做成TF卡镜像

  1. 需要一台装有Linux系统的PC机

  2. 利用 gparted 格式化并重新划分U盘:

    /dev/sda1       100M        FAT32        boot分区

    /dev/sda2       900M        EXT4          PiLFS分区

  3. 进入 /dev/mmcblk0p1 分区,将除 dtb 格式外的文件全部复制到 /dev/sda1 分区下

  4. 执行 sudo  fdisk -u -l /dev/sda 命令,查看硬件的分区情况,start和end中数字的单位是512字节

  5. 利用dd命令将U盘做成镜像:

      dd if=/dev/sda of=piLfs-7.10-linux-4.4.img bs=512 count=[fdisk命令中最大的end数+1]

posted on 2017-02-02 22:17  大饼酥  阅读(2094)  评论(0编辑  收藏  举报

导航