参考:LFS7.10——准备Host系统

LFS7.10——构造临时Linux系统

本文正式开始构建LFS系统,后面所有命令的执行都是在root用户下完成的。

这时开始构建LFS前准备工作

更改$LFS/tools属主

chown -R root:root $LFS/tools

准备Virtual Kernel File Systems

mkdir -pv $LFS/{dev,proc,sys,run}

创建初始设备节点

mknod -m 600 $LFS/dev/console c 5 1
mknod -m 666 $LFS/dev/null c 1 3

挂载和激活 /dev

mount -v --bind /dev $LFS/dev

挂载Virtual Kernel File Systems

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 环境

chroot "$LFS" /tools/bin/env -i \
HOME=/root \
TERM="$TERM" \
PS1='\u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
/tools/bin/bash --login +h

准备LFS文件系统里面二点目录结构

mkdir -pv /{bin,boot,etc/{opt,sysconfig},home,lib/firmware,mnt,opt}
mkdir -pv /{media/{floppy,cdrom},sbin,srv,var}
install -dv -m /root
install -dv -m /tmp /var/tmp
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{color,dict,doc,info,locale,man}
mkdir -v /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -v /usr/libexec
mkdir -pv /usr/{,local/}share/man/man{..}
case $(uname -m) in
x86_64) ln -sv lib /lib64
ln -sv lib /usr/lib64
ln -sv lib /usr/local/lib64 ;;
esac
mkdir -v /var/{log,mail,spool}
ln -sv /run /var/run
ln -sv /run/lock /var/lock
mkdir -pv /var/{opt,cache,lib/{color,misc,locate},local}

创建必需的文件和符号链接

ln -sv /tools/bin/{bash,cat,echo,pwd,stty} /bin
ln -sv /tools/bin/perl /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.} /usr/lib
ln -sv /tools/lib/libstdc++.so{,.} /usr/lib
sed 's/tools/usr/' /tools/lib/libstdc++.la > /usr/lib/libstdc++.la
ln -sv bash /bin/sh

ln -sv /proc/self/mounts /etc/mtab

创建/etc/passwd 文件

cat > /etc/passwd << "EOF"
root:x:::root:/root:/bin/bash
bin:x:::bin:/dev/null:/bin/false
daemon:x:::Daemon User:/dev/null:/bin/false
messagebus:x:::D-Bus Message Daemon User:/var/run/dbus:/bin/false
nobody:x:::Unprivileged User:/dev/null:/bin/false
EOF

创建/etc/group 文件

cat > /etc/group << "EOF"
root:x::
bin:x::daemon
sys:x::
kmem:x::
tape:x::
tty:x::
daemon:x::
floppy:x::
disk:x::
lp:x::
dialout:x::
audio:x::
video:x::
utmp:x::
usb:x::
cdrom:x::
adm:x::
messagebus:x::
systemd-journal:x::
input:x::
mail:x::
nogroup:x::
users:x::
EOF

exec /tools/bin/bash --login +h

初始化一下日志文件并加上合适的权限

touch /var/log/{btmp,lastlog,faillog,wtmp}
chgrp -v utmp /var/log/lastlog
chmod -v /var/log/lastlog
chmod -v /var/log/btmp

安装Linux-4.7.2 API Headers

tar -xvf linux-4.7.2.tar.xz
cd linux-4.7.2
make mrproper
make INSTALL_HDR_PATH=dest headers_install
find dest/include \( -name .install -o -name ..install.cmd \) -delete
cp -rv dest/include/* /usr/include
cd ..
rm -rf linux-4.7.2

安装Man-pages

tar -xvf man-pages-4.07.tar.xz
cd man-pages-4.07
make install
cd ..
rm -rf man-pages-4.07

Glibc

安装

tar -xvf glibc-2.24.tar.xz
cd glibc-2.24
patch -Np1 -i ../glibc-2.24-fhs-1.patch
mkdir -v build
cd build

../configure --prefix=/usr \
--enable-kernel=2.6. \
--enable-obsolete-rpc

make -j8

make check

touch /etc/ld.so.conf
make install

cp -v ../nscd/nscd.conf /etc/nscd.conf
mkdir -pv /var/cache/nscd
mkdir -pv /usr/lib/locale
localedef -i cs_CZ -f UTF- cs_CZ.UTF-
localedef -i de_DE -f ISO-- de_DE
localedef -i de_DE@euro -f ISO-- de_DE@euro
localedef -i de_DE -f UTF- de_DE.UTF-
localedef -i en_GB -f UTF- en_GB.UTF-
localedef -i en_HK -f ISO-- en_HK
localedef -i en_PH -f ISO-- en_PH
localedef -i en_US -f ISO-- en_US
localedef -i en_US -f UTF- en_US.UTF-
localedef -i es_MX -f ISO-- es_MX
localedef -i fa_IR -f UTF- fa_IR
localedef -i fr_FR -f ISO-- fr_FR
localedef -i fr_FR@euro -f ISO-- fr_FR@euro
localedef -i fr_FR -f UTF- fr_FR.UTF-
localedef -i it_IT -f ISO-- it_IT
localedef -i it_IT -f UTF- it_IT.UTF-
localedef -i ja_JP -f EUC-JP ja_JP
localedef -i ru_RU -f KOI8-R ru_RU.KOI8-R
localedef -i ru_RU -f UTF- ru_RU.UTF-
localedef -i tr_TR -f UTF- tr_TR.UTF-
localedef -i zh_CN -f GB18030 zh_CN.GB18030

make localedata/install-locales

配置Glibc

创建一个新文件/etc/nsswitch.conf

cat > /etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf
passwd: files
group: files
shadow: files
hosts: files dns
networks: files
protocols: files
services: files
ethers: files
rpc: files
# End /etc/nsswitch.conf
EOF

安装时区数据:

tar -xf ../../tzdata2016f.tar.gz
ZONEINFO=/usr/share/zoneinfo
mkdir -pv $ZONEINFO/{posix,right}
for tz in etcetera southamerica northamerica europe africa antarctica \
asia australasia backward pacificnew systemv; do
zic -L /dev/null -d $ZONEINFO -y "sh yearistype.sh" ${tz}
zic -L /dev/null -d $ZONEINFO/posix -y "sh yearistype.sh" ${tz}
zic -L leapseconds -d $ZONEINFO/right -y "sh yearistype.sh" ${tz}
done
cp -v zone.tab zone1970.tab iso3166.tab $ZONEINFO
zic -d $ZONEINFO -p America/New_York
unset ZONEINFO

tzselect

cp -v /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime

配置Dynamic Loader

创建/etc/ld.so.conf

cat > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf
/usr/local/lib
/opt/lib
EOF
cat >> /etc/ld.so.conf << "EOF"
# Add an include directory
include /etc/ld.so.conf.d/*.conf
EOF
mkdir -pv /etc/ld.so.conf.d

调整工具链

与LFS7.10 Adjusting the Toolchain 预期结果不符,还在排查问题,未完待续。。。

05-22 19:14