LFS(三)

LFS(三)

0.前言

  LFS(二)中成功的解决了工具链的报错问题,也完成前期测试工具的编译安装和工具链调试,并且完成其他版本软件包的编译和安装以及创建系统配置文件的初步尝试,接下来将继续延续着昨天的创建系统配置文件进行开始,争取完成根据LFS手册,创建必要的系统配置文件,如/etc/fstab、/etc/passwd等;尝试配置相关内核,使用make menuconfig命令配置Linux内核,选择所需的功能和驱动。以及编译安装内核:编译并安装配置好的Linux内核。安装引导加载程序:安装GRUB等引导加载程序,并配置启动项

1.创建lfs系统目录结构

1
2
3
4
mkdir -pv /{bin,boot,etc/opt,home,lib,mnt,opt}
mkdir -pv /{media/{floppy,cdrom},sbin,srv,var}
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
1
2
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{doc,info,locale,man}
1
2
mkdir -pv /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -pv /usr/{,local/}share/man/man{1..8}
1
2
3
for dir in /usr /usr/local; do
ln -sv share/{man,doc,info} $dir
done
1
2
mkdir -pv /var/{lock,log,mail,run,spool}
mkdir -pv /var/{opt,cache,lib/{misc,locate},local}

  以上是创建目标系统的目录结构的相关代码,这里需要提及的是这一段中运用到了for循环的体系,遍历了usr和usr/local两个目录,一般来说,for循环遍历usr会遍历到usr/local下的文件,这里是因为需要在这两个目录下都创建软链接,所以是usr和usr/local两个目录

2.创建lfs系统必要链接

1
2
3
4
5
6
ln -sv /tools/bin/{bash,cat,echo,grep,pwd,stty} /bin
ln -sv /tools/bin/perl /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -sv /tools/lib/libstdc++.so{,.6} /usr/lib
ln -sv bash /bin/sh
touch /etc/mtab

  软链接的创建前面见识得比较多了,这里就不进行详细的阐述了,基本也是为了后面的使用方便,这里touch一个matab文件是为了用于记录已挂载的文件系统信息,在Linux系统中,/etc/mtab文件通常由mount命令自动生成,记录当前已挂载的文件系统信息,我们这里搭建lfs系统,自然是需要手建一个。

3.创建相关用户与用户组

1
2
3
4
cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF

  这两行命令描述了两个用户,root和nobody。每行由七个字段组成,分别是用户名、密码(通常为x,表示密码存储在/etc/shadow文件中)、用户ID、主组ID、注释、主目录和默认shell。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cat > /etc/group << "EOF"
root:x:0:
bin:x:1:
sys:x:2:
kmem:x:3:
tty:x:4:
tape:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
mail:x:34:
nogroup:x:99:
EOF

  这几段命令则是描述了系统中的各种组,每行由四个字段组成,分别是组名、密码(通常为x,表示密码存储在/etc/gshadow文件中)、组ID和组成员列表。执行完毕后需要重新加载bash

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

  这里修改成功后,就会以root用户进行,而不再是I have no name的用户了

4.创建并设置临时文件和日志

1
2
3
touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
chgrp -v utmp /var/run/utmp /var/log/lastlog
chmod -v 664 /var/run/utmp /var/log/lastlog

5.构建系统所需的基本库和工具

  首先进入源码目录

1
2
cd /sources
export LFS=/sources
  • Linux-2.6.22.5
1
2
3
4
5
6
7
8
9
tar xvf $LFS/linux-2.6.22.5.tar.bz2
cd linux-2.6.22.5
sed -i '/scsi/d' include/Kbuild
make mrproper
make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /usr/include
cd ..
rm -rf linux-2.6.22.5

  其对比与lfs用户中工具链的Linux-2.6.22.5 API Headers编译安装,不仅仅是复制头文件的目标路径不同,多多了一行sed -i ‘/scsi/d’ include/Kbuild命令,其作用是从include/Kbuild文件中删除包含”scsi”字符串的行。这是因为在构建LFS系统时,不需要SCSI支持,因此可以将相关代码从内核配置中删除以减少系统的大小和复杂性

  • Man-pages-2.63
1
2
3
4
5
tar xvf $LFS/man-pages-2.63.tar.bz2
cd man-pages-2.63
make install
cd ..
rm -rf man-pages-2.63

  在构建LFS系统时,root用户需要安装Man-pages-2.63软件包,而普通用户lfs不需要。这是因为Man-pages-2.63提供了Linux手册页的文档,这些文档对于系统管理员和开发人员来说非常有用。在构建LFS系统时,root用户需要访问这些手册页以了解如何使用和配置系统。而对于普通用户lfs来说,他们只需要了解如何构建LFS系统,因此不需要安装Man-pages-2.63软件包

  • Glibc-2.5.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
tar xvf $LFS/glibc-2.5.1.tar.bz2
cd glibc-2.5.1
tar -xvf $LFS/glibc-libidn-2.5.1.tar.gz
mv glibc-libidn-2.5.1 libidn
sed -i '/vi_VN.TCVN/d' localedata/SUPPORTED
sed -i 's|libs -o|libs -L/usr/lib -Wl,-dynamic-linker=/lib/ld-linux.so.2 -o|' scripts/test-installation.pl
sed -i 's|@BASH@|/bin/bash|' elf/ldd.bash.in
mkdir -v ../glibc-build
cd ../glibc-build
../glibc-2.5.1/configure --prefix=/usr \
--disable-profile --enable-add-ons \
--enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc
make
make -k check 2>&1 | tee glibc-check-log
grep Error glibc-check-log
touch /etc/ld.so.conf
make install
make localedata/install-locales

  这里的make -k check 2>&1 | tee glibc-check-log有些久,需要等待

6.root用户的相关软件包编译安装

  • Binutils-2.17
1
2
3
4
5
6
tar xvf $LFS/binutils-2.17.tar.bz2
mkdir binutils-build
cd binutils-build
../binutils-2.17/configure --prefix=/usr --enable-shared
make tooldir=/usr
make check
1
2
3
4
5
make tooldir=/usr install
cp -v ../binutils-2.17/include/libiberty.h /usr/include
cd ..
rm -rf binutils-build
rm -rf binutils-2.17

  这里对比与之前lfs的普通用户,多进行了make check的指令,这是因为。root用户需要执行make check来确保安装的Binutils-2.17工具链能够正常工作,并且没有任何问题。这是因为root用户拥有系统的最高权限,可以对系统进行更改,因此需要确保安装的工具链是可靠的。而普通用户则不需要执行make check,因为他们没有足够的权限来对系统进行更改,因此即使安装的工具链存在问题,也不会对系统造成影响。

  需要提及的是这里的测试统计可能会出现个别失败的情况,并不影响后面结果,可以忽略

  • GCC-4.1.2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
tar xvf $LFS/gcc-4.1.2.tar.bz2
cd gcc-4.1.2
sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
sed -i 's/^XCFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in
sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
sed -i 's/@have_mktemp_command@/yes/' gcc/gccbug.in
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.1.2/configure --prefix=/usr \
--libexecdir=/usr/lib --enable-shared \
--enable-threads=posix --enable-__cxa_atexit \
--enable-clocale=gnu --enable-languages=c,c++
make
make –k check
make install
ln -sv ../usr/bin/cpp /lib
ln -sv gcc /usr/bin/cc
cd ..
rm -rf gcc-build
rm -rf gcc-4.1.2

  首先这里的check时间确实是比较长的,其次对比前面的lfs普通用户的gcc编译安装 ,。root用户执行命令是在LFS系统中安装gcc-4.1.2,而lfs普通用户命令是在构建LFS系统所需的工具链中安装gcc-4.1.2。

  编译安装完gcc后需要再次测试是否正确

1
2
3
4
5
6
7
8
9
echo 'main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep 'lib'
grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
grep -B3 '^ /usr/include' dummy.log
grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'
grep "/lib/libc.so.6 " dummy.log
grep found dummy.log
rm -v dummy.c a.out dummy.log

  • Berkeley DB-4.5.20
1
2
3
4
5
6
7
8
9
10
tar xvf $LFS/db-4.5.20.tar.gz
cd db-4.5.20
patch -Np1 -i $LFS/db-4.5.20-fixes-1.patch
cd build_unix
../dist/configure --prefix=/usr --enable-compat185 --enable-cxx
make
make docdir=/usr/share/doc/db-4.5.20 install
chown -Rv root:root /usr/share/doc/db-4.5.20
cd /sources
rm -rf db-4.5.20
  • Sed-4.1.5
1
2
3
4
5
tar xvf $LFS/sed-4.1.5.tar.gz
cd sed-4.1.5
./configure --prefix=/usr --bindir=/bin --enable-html
make
make check
1
2
3
make install
cd ..
rm -rf sed-4.1.5
  • E2fsprogs-1.40.2
1
2
3
4
5
6
7
8
tar xvf $LFS/e2fsprogs-1.40.2.tar.gz
cd e2fsprogs-1.40.2
sed -i -e 's@/bin/rm@/tools&@' lib/blkid/test_probe.in
mkdir -v build
cd build
../configure --prefix=/usr --with-root-prefix="" --enable-elf-shlibs
make
make check

  这里check会有一个错误,没有影响,继续即可

1
2
3
4
make install
make install-libs
cd ../..
rm -rf e2fsprogs-1.40.2
  • Coreutils-6.9
1
2
3
4
5
6
7
8
tar xvf $LFS/coreutils-6.9.tar.bz2
cd coreutils-6.9
patch -Np1 -i $LFS/coreutils-6.9-uname-1.patch
patch -Np1 -i $LFS/coreutils-6.9-suppress_uptime_kill_su-1.patch
patch -Np1 -i $LFS/coreutils-6.9-i18n-1.patch
chmod +x tests/sort/sort-mb-tests
./configure --prefix=/usr
make
1
2
3
make NON_ROOT_USERNAME=nobody check-root
echo "dummy:x:1000:nobody" >> /etc/group
su-tools nobody -s /bin/bash -c "make RUN_EXPENSIVE_TESTS=yes check"

  删除测试用数据

1
2
3
4
5
6
7
8
9
10
sed -i '/dummy/d' /etc/group
1
make install
mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} /bin
mv -v /usr/bin/{false,hostname,ln,ls,mkdir,mknod,mv,pwd,readlink,rm} /bin
mv -v /usr/bin/{rmdir,stty,sync,true,uname} /bin
mv -v /usr/bin/chroot /usr/sbin
mv -v /usr/bin/{head,sleep,nice} /bin
cd ..
rm -rf coreutils-6.9
  • Iana-Etc-2.20
1
2
3
4
5
6
tar xvf $LFS/iana-etc-2.20.tar.bz2
cd iana-etc-2.20
make
make install
cd ..
rm -rf iana-etc-2.20
  • M4-1.4.10
1
2
3
4
5
6
7
8
tar xvf $LFS/m4-1.4.10.tar.bz2
cd m4-1.4.10
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf m4-1.4.10

  • Bison-2.3
1
2
3
4
5
6
7
8
9
tar xvf $LFS/bison-2.3.tar.bz2
cd bison-2.3
./configure --prefix=/usr
echo '#define YYENABLE_NLS 1' >> config.h
make
make check
make install
cd ..
rm -rf bison-2.3
  • Ncurses-5.6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
tar xvf $LFS/ncurses-5.6.tar.gz
cd ncurses-5.6
patch -Np1 -i $LFS/ncurses-5.6-coverity_fixes-1.patch
./configure --prefix=/usr --with-shared --without-debug --enable-widec
make
make install
chmod -v 644 /usr/lib/libncurses++w.a
mv -v /usr/lib/libncursesw.so.5* /lib
ln -sfv ../../lib/libncursesw.so.5 /usr/lib/libncursesw.so
for lib in curses ncurses form panel menu ; do \
rm -vf /usr/lib/lib${lib}.so ; \
echo "INPUT(-l${lib}w)" >/usr/lib/lib${lib}.so ; \
ln -sfv lib${lib}w.a /usr/lib/lib${lib}.a ; \
done
ln -sfv libncurses++w.a /usr/lib/libncurses++.a
rm -vf /usr/lib/libcursesw.so
echo "INPUT(-lncursesw)" >/usr/lib/libcursesw.so
ln -sfv libncurses.so /usr/lib/libcurses.so
ln -sfv libncursesw.a /usr/lib/libcursesw.a
ln -sfv libncurses.a /usr/lib/libcurses.a
cd ..
rm -rf ncurses-5.6

  这里在运行chmod -v 644 /usr/lib/libncurses++w.a,mv -v /usr/lib/libncursesw.so.5* /lib的时候有些奇怪,前面重新重复了三遍,第一遍报错没有libncurses++w.a,第二遍报错找不到  libncursesw.so.5*,第三遍才过,可是我并有输入错误内容,前面的内容也顺利跑通了,怎会如此

  • Procps-3.2.7
1
2
3
4
5
6
tar xvf $LFS/procps-3.2.7.tar.gz
cd procps-3.2.7
make
make install
cd ..
rm -rf procps-3.2.7
  • Libtool-1.5.24
1
2
3
4
5
6
7
8
tar xvf $LFS/libtool-1.5.24.tar.gz
cd libtool-1.5.24
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf libtool-1.5.24
  • Perl-5.8.8

  Perl在LFS构建过程中扮演着重要的角色,其用于构建和安装Prel的许多组成Linux操作系统的核心软件包,包括GNU编译器集合等,此外,在LFS构建的过程中,使用了许多脚本和工具都是由Perl编写

1
2
3
4
5
6
7
8
9
tar xvf $LFS/perl-5.8.8.tar.bz2
cd perl-5.8.8
echo "127.0.0.1 localhost $(hostname)" > /etc/hosts
./configure.gnu --prefix=/usr \
-Dman1dir=/usr/share/man/man1 \
-Dman3dir=/usr/share/man/man3 \
-Dpager="/usr/bin/less -isR"
make
make test

  这里在编译test的时候,等待了大量时间,主要是lib\benchmark这个部分停留了较久,尽管我使用了make –j4 test的指令,但是依旧是没有加快的迹象,其次是按照相关指南,这里test以后,应该是没有错误的,但我在运行的结果中,存在了两个不清晰的报错,目前暂未影响后续的代码执行

1
2
3
make install
cd ..
rm -rf perl-5.8.8
  • Readline-5.2

  Readline是一个开源软件库,它提供了命令行界面的编辑功能。它可以帮助用户在终端中输入和编辑命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
tar xvf $LFS/readline-5.2.tar.gz
cd readline-5.2
sed -i '/MV.*old/d' Makefile.in
sed -i '/{OLDSUFF}/c:' support/shlib-install
patch -Np1 -i $LFS/readline-5.2-fixes-3.patch
./configure --prefix=/usr --libdir=/lib
make SHLIB_XLDFLAGS=-lncurses
make install
mv -v /lib/lib{readline,history}.a /usr/lib
rm -v /lib/lib{readline,history}.so
ln -sfv ../../lib/libreadline.so.5 /usr/lib/libreadline.so
ln -sfv ../../lib/libhistory.so.5 /usr/lib/libhistory.so
cd ..
rm -rf readline-5.2
  • Zlib-1.2.3

  Zlib是一个开源的压缩库,它可以用于在许多不同的应用程序中进行数据压缩和解压缩

1
2
3
4
5
tar xvf $LFS/zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/usr --shared --libdir=/lib
make
make check
1
2
3
4
5
6
7
make install
rm -v /lib/libz.so
ln -sfv ../../lib/libz.so.1.2.3 /usr/lib/libz.so
make clean
./configure --prefix=/usr
make
make check
1
2
3
4
make install
chmod -v 644 /usr/lib/libz.a
cd ..
rm -rf zlib-1.2.3
  • Autoconf-2.61

  Automake是一个自动化工具,它可以帮助开发人员更轻松地管理和维护软件包的构建过程。它可以生成Makefile文件,这些文件描述了如何编译和安装软件包。Automake还提供了一些其他功能,例如自动检测源代码中的错误和依赖关系,并自动生成必要的文件

1
2
3
4
5
tar xvf $LFS/autoconf-2.61.tar.bz2
cd autoconf-2.61
./configure --prefix=/usr
make
make check

  这里check的测试时间比较长,但能顺利结束

1
2
3
make install
cd ..
rm -rf autoconf-2.61
  • Bash-3.2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
tar xvf $LFS/bash-3.2.tar.gz
cd bash-3.2
tar -xvf $LFS/bash-doc-3.2.tar.gz
sed -i "s|htmldir = @htmldir@|htmldir = /usr/share/doc/bash-3.2|" Makefile.in
patch -Np1 -i $LFS/bash-3.2-fixes-5.patch
./configure --prefix=/usr --bindir=/bin --without-bash-malloc --with-installed-readline
make
sed -i 's/LANG/LC_ALL/' tests/intl.tests
sed -i 's@tests@& </dev/tty@' tests/run-test
chown -Rv nobody ./
su-tools nobody -s /bin/bash -c "make tests"
make install
cd ..
rm -rf bash-3.2
exec /bin/bash --login +h

  这里需要注意的是在运行check时,会产生大量的警告,但是不会出现error的问题,所以不必担心

  • Bzip2-1.0.4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
tar xvf $LFS/bzip2-1.0.4.tar.gz
cd bzip2-1.0.4
patch -Np1 -i $LFS/bzip2-1.0.4-install_docs-1.patch
make -f Makefile-libbz2_so
make clean
make
make PREFIX=/usr install
cp -v bzip2-shared /bin/bzip2
cp -av libbz2.so* /lib
ln -sv ../../lib/libbz2.so.1.0 /usr/lib/libbz2.so
rm -v /usr/bin/{bunzip2,bzcat,bzip2}
ln -sv bzip2 /bin/bunzip2
ln -sv bzip2 /bin/bzcat
cd ..
rm -rf bzip2-1.0.4
  • Diffutils-2.8.1
1
2
3
4
5
6
7
8
9
tar xvf $LFS/diffutils-2.8.1.tar.gz
cd diffutils-2.8.1
patch -Np1 -i $LFS/diffutils-2.8.1-i18n-1.patch
touch man/diff.1
./configure --prefix=/usr
make
make install
cd ..
rm -rf diffutils-2.8.1
  • File-4.21
1
2
3
4
5
6
7
tar xvf $LFS/file-4.21.tar.gz
cd file-4.21
./configure --prefix=/usr
make
make install
cd ..
rm -rf file-4.21
  • Findutils-4.2.31
1
2
3
4
5
6
7
8
9
10
tar xvf $LFS/findutils-4.2.31.tar.gz
cd findutils-4.2.31
./configure --prefix=/usr --libexecdir=/usr/lib/findutils --localstatedir=/var/lib/locate
make
make check
make install
mv -v /usr/bin/find /bin
sed -i -e 's/find:=${BINDIR}/find:=\/bin/' /usr/bin/updatedb
cd ..
rm -rf findutils-4.2.31
  • Flex-2.5.33
1
2
3
4
5
6
7
tar xvf $LFS/flex-2.5.33.tar.bz2
cd flex-2.5.33
./configure --prefix=/usr
make
make check
make install
ln -sv libfl.a /usr/lib/libl.a

  接下来创建一个lex的命令

  • GRUB-0.97
1
2
3
4
5
6
7
8
9
10
11
tar xvf $LFS/grub-0.97.tar.gz
cd grub-0.97
patch -Np1 -i $LFS/grub-0.97-disk_geometry-1.patch
./configure --prefix=/usr
make
make check
make install
mkdir -v /boot/grub
cp -v /usr/lib/grub/i386-pc/stage{1,2} /boot/grub
cd ..
rm -rf grub-0.97
  • Gawk-3.1.5
1
2
3
4
5
6
7
8
9
10
11
12
13
tar xvf $LFS/gawk-3.1.5.tar.bz2
cd gawk-3.1.5
patch -Np1 -i $LFS/gawk-3.1.5-segfault_fix-1.patch
./configure --prefix=/usr --libexecdir=/usr/lib
cat >> config.h << "EOF"
#define HAVE_LANGINFO_CODESET 1
#define HAVE_LC_MESSAGES 1
EOF
make
make check
make install
cd ..
rm -rf gawk-3.1.5
  • Gettext-0.16.1
1
2
3
4
5
6
7
8
tar xvf $LFS/gettext-0.16.1.tar.gz
cd gettext-0.16.1
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf gettext-0.16.1
  • Grep-2.5.1a
1
2
3
4
5
6
7
8
9
10
tar xvf $LFS/grep-2.5.1a.tar.bz2
cd grep-2.5.1a
patch -Np1 -i $LFS/grep-2.5.1a-redhat_fixes-2.patch
chmod +x tests/fmbtest.sh
./configure --prefix=/usr --bindir=/bin
make
make check
make install
cd ..
rm -rf grep-2.5.1a
  • Groff-1.18.1.4
1
2
3
4
5
6
7
8
9
10
11
12
tar xvf $LFS/groff-1.18.1.4.tar.gz
cd groff-1.18.1.4
patch -Np1 -i $LFS/groff-1.18.1.4-debian_fixes-1.patch
sed -i -e 's/2010/002D/' -e 's/2212/002D/' \
-e 's/2018/0060/' -e 's/2019/0027/' font/devutf8/R.proto
PAGE=A4 ./configure --prefix=/usr --enable-multibyte
make
make install
ln -sv eqn /usr/bin/geqn
ln -sv tbl /usr/bin/gtbl
cd ..
rm -rf groff-1.18.1.4
  • Gzip-1.3.12
1
2
3
4
5
6
7
8
9
10
tar xvf $LFS/gzip-1.3.12.tar.gz
cd gzip-1.3.12
./configure --prefix=/usr --bindir=/bin
make
make check
make install
mv -v /bin/{gzexe,uncompress,zcmp,zdiff,zegrep} /usr/bin
mv -v /bin/{zfgrep,zforce,zgrep,zless,zmore,znew} /usr/bin
cd ..
rm -rf gzip-1.3.12
  • Inetutils-1.5
1
2
3
4
5
6
7
8
9
10
11
12
tar xvf $LFS/inetutils-1.5.tar.gz
cd inetutils-1.5
patch -Np1 -i $LFS/inetutils-1.5-no_server_man_pages-2.patch
./configure --prefix=/usr --libexecdir=/usr/sbin \
--sysconfdir=/etc --localstatedir=/var \
--disable-ifconfig --disable-logger --disable-syslogd \
--disable-whois --disable-servers
make
make install
mv -v /usr/bin/ping /bin
cd ..
rm -rf inetutils-1.5
  • IPRoute2-2.6.20-070313
1
2
3
4
5
6
7
8
tar xvf $LFS/iproute2-2.6.20-070313.tar.gz
cd iproute-2.6.20-070313
sed -i -e '/tc-bfifo.8/d' -e '/tc-pfifo.8/s/pbfifo/bfifo/' Makefile
make SBINDIR=/sbin
make SBINDIR=/sbin install
mv -v /sbin/arpd /usr/sbin
cd ..
rm -rf iproute-2.6.20-070313
  • Kbd-1.12
1
2
3
4
5
6
7
8
9
10
tar xvf $LFS/kbd-1.12.tar.bz2
cd kbd-1.12
patch -Np1 -i $LFS/kbd-1.12-backspace-1.patch
patch -Np1 -i $LFS/kbd-1.12-gcc4_fixes-1.patch
./configure --datadir=/lib/kbd
make
make install
mv -v /usr/bin/{kbd_mode,openvt,setfont} /bin
cd ..
rm -rf kbd-1.12
  • Less-406
1
2
3
4
5
6
7
tar xvf $LFS/less-406.tar.gz
cd less-406
./configure --prefix=/usr --sysconfdir=/etc
make
make install
cd ..
rm -rf less-406
  • Make-3.81
1
2
3
4
5
6
7
8
tar xvf $LFS/make-3.81.tar.bz2
cd make-3.81
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf make-3.81
  • Man-DB-2.4.4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
tar xvf $LFS/man-db-2.4.4.tar.gz
cd man-db-2.4.4
mv man/de{_DE.88591,}
mv man/es{_ES.88591,}
mv man/it{_IT.88591,}
sed -i 's,\*_\*,??,' man/Makefile.in
sed -i -e '\%\t/usr/man%d' -e '\%\t/usr/local/man%d' src/man_db.conf.in
cat >> include/manconfig.h.in << "EOF"
#define WEB_BROWSER "exec /usr/bin/lynx"
#define COL "/usr/bin/col"
#define VGRIND "/usr/bin/vgrind"
#define GRAP "/usr/bin/grap"
EOF
patch -Np1 -i $LFS/man-db-2.4.4-fixes-1.patch
./configure --prefix=/usr --enable-mb-groff --disable-setuid
make
make install

  接下来还需要创建一个用于转换man手册编码的脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat >> convert-mans << "EOF"
#!/bin/sh -e
FROM="$1"
TO="$2"
shift ; shift
while [ $# -gt 0 ]
do
FILE="$1"
shift
iconv -f "$FROM" -t "$TO" "$FILE" >.tmp.iconv
mv .tmp.iconv "$FILE"
done
EOF
install -m755 convert-mans /usr/bin
cd ..
rm -rf man-db-2.4.4
  • Mktemp-1.5
1
2
3
4
5
6
7
8
9
tar xvf $LFS/mktemp-1.5.tar.gz
cd mktemp-1.5
patch -Np1 -i $LFS/mktemp-1.5-add_tempfile-3.patch
./configure --prefix=/usr --with-libc
make
make install
make install-tempfile
cd ..
rm -rf mktemp-1.5
  • Module-Init-Tools-3.2.2
1
2
3
4
5
6
7
8
9
10
11
tar xvf $LFS/module-init-tools-3.2.2.tar.bz2
cd module-init-tools-3.2.2
patch -Np1 -i $LFS/module-init-tools-3.2.2-modprobe-1.patch
./configure
make check
make distclean
./configure --prefix=/ --enable-zlib
make
make INSTALL=install install
cd ..
rm -rf module-init-tools-3.2.2
  • Patch-2.5.4
1
2
3
4
5
6
7
tar xvf $LFS/patch-2.5.4.tar.gz
cd patch-2.5.4
./configure --prefix=/usr
make
make install
cd ..
rm -rf patch-2.5.4
  • Psmisc-22.5
1
2
3
4
5
6
7
8
cd psmisc-22.5
./configure --prefix=/usr --exec-prefix=""
make
make install
mv -v /bin/pstree* /usr/bin
ln -sv killall /bin/pidof
cd ..
rm -rf psmisc-22.5
  • Shadow-4.0.18.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
tar xvf $LFS/shadow-4.0.18.1.tar.bz2
cd shadow-4.0.18.1
patch -Np1 -i $LFS/shadow-4.0.18.1-useradd_fix-2.patch
./configure --libdir=/lib --sysconfdir=/etc --enable-shared --without-selinux
sed -i 's/groups$(EXEEXT) //' src/Makefile
find man -name Makefile -exec sed -i 's/groups\.1 / /' {} \;
sed -i -e 's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' \
-e 's@/var/spool/mail@/var/mail@' etc/login.defs
make
make install
mv -v /usr/bin/passwd /bin
mv -v /lib/libshadow.*a /usr/lib
rm -v /lib/libshadow.so
ln -sfv ../../lib/libshadow.so.0 /usr/lib/libshadow.so

  配置增加用户的默认设置

1
2
3
4
pwconv
grpconv
useradd -D -b /home
sed -i 's/yes/no/' /etc/default/useradd

  设置root用户密码,这里需要注意的是一定要设置root的密码,否则重启后是无法进行登录的

1
2
3
passwd root
cd ..
rm -rf shadow-4.0.18.1

  这里我将root密码设置为了4399

  • Sysklogd-1.4.1
1
2
3
4
5
6
tar xvf $LFS/sysklogd-1.4.1.tar.gz
cd sysklogd-1.4.1
patch -Np1 -i $LFS/sysklogd-1.4.1-fixes-2.patch
patch -Np1 -i $LFS/sysklogd-1.4.1-8bit-1.patch
make
make install

  接下来配置syslog的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
cat > /etc/syslog.conf << "EOF"
# Begin /etc/syslog.conf
auth,authpriv.* -/var/log/auth.log
*.*;auth,authpriv.none -/var/log/sys.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
*.emerg *
# End /etc/syslog.conf
EOF
cd ..
rm -rf sysklogd-1.4.1
  • Sysvinit-2.86
1
2
3
4
5
tar xvf $LFS/sysvinit-2.86.tar.gz
cd sysvinit-2.86
sed -i 's@Sending processes@& configured via /etc/inittab@g' src/init.c
make -C src
make -C src install

  设置启动配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
cat > /etc/inittab << "EOF"
# Begin /etc/inittab
id:3:initdefault:
si::sysinit:/etc/rc.d/init.d/rc sysinit
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 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
cd ..
rm -rf sysvinit-2.86
  • Tar-1.18
1
2
3
4
5
6
7
8
tar xvf $LFS/tar-1.18.tar.bz2
cd tar-1.18
./configure --prefix=/usr --bindir=/bin --libexecdir=/usr/sbin
make
make check
make install
cd ..
rm -rf tar-1.18
  • Texinfo-4.9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
tar xvf $LFS/texinfo-4.9.tar.bz2
cd texinfo-4.9
patch -Np1 -i $LFS/texinfo-4.9-multibyte-1.patch
patch -Np1 -i $LFS/texinfo-4.9-tempfile_fix-1.patch
./configure --prefix=/usr
make
make check
make install
make TEXMF=/usr/share/texmf install-tex
cd /usr/share/info
rm dir
for f in *
do install-info $f dir 2>/dev/null
done
cd /sources
rm -rf texinfo-4.9
  • Udev-113
1
2
3
4
5
6
7
8
9
10
11
12
tar xvf $LFS/udev-113.tar.bz2
cd udev-113
tar -xvf $LFS/udev-config-6.3.tar.bz2
install -dv /lib/{firmware,udev/devices/{pts,shm}}
mknod -m0666 /lib/udev/devices/null c 1 3
ln -sv /proc/self/fd /lib/udev/devices/fd
ln -sv /proc/self/fd/0 /lib/udev/devices/stdin
ln -sv /proc/self/fd/1 /lib/udev/devices/stdout
ln -sv /proc/self/fd/2 /lib/udev/devices/stderr
ln -sv /proc/kcore /lib/udev/devices/core
make EXTRAS="`echo extras/*/`"
make test

  这里进行test后发现有错误,可以不必理会,继续进行下一步

1
2
3
4
5
6
7
8
9
10
11
make DESTDIR=/ EXTRAS="`echo extras/*/`" install
cp -v etc/udev/rules.d/[0-9]* /etc/udev/rules.d/
cd udev-config-6.3
make install
make install-doc
make install-extra-doc
cd ..
install -m644 -v docs/writing_udev_rules/index.html \
/usr/share/doc/udev-113/index.html
cd ..
rm -rf udev-113
  • Util-linux-2.12r
1
2
3
4
5
6
7
8
9
10
11
12
tar xvf $LFS/util-linux-2.12r.tar.bz2
cd util-linux-2.12r
sed -e 's@etc/adjtime@var/lib/hwclock/adjtime@g' \
-i $(grep -rl '/etc/adjtime' .)
mkdir -pv /var/lib/hwclock
patch -Np1 -i $LFS/util-linux-2.12r-cramfs-1.patch
patch -Np1 -i $LFS/util-linux-2.12r-lseek-1.patch
./configure
make HAVE_KILL=yes HAVE_SLN=yes
make HAVE_KILL=yes HAVE_SLN=yes install
cd ..
rm -rf util-linux-2.12r
  • Vim-7.1
1
2
3
4
5
6
7
8
9
tar xvf $LFS/vim-7.1.tar.bz2
tar xvf $LFS/vim-7.1-lang.tar.gz
cd vim71
patch -Np1 -i $LFS/vim-7.1-fixes-1.patch
patch -Np1 -i $LFS/vim-7.1-mandir-1.patch
echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h
./configure --prefix=/usr --enable-multibyte
make
make test
1
2
3
4
5
6
make install
ln -sv vim /usr/bin/vi
for L in "" fr it pl ru; do
ln -sv vim.1 /usr/share/man/$L/man1/vi.1
done
ln -sv ../vim/vim71/doc /usr/share/doc/vim-7.1

  接下来建立并配置vim的默认配置文件

1
2
3
4
5
6
7
8
9
10
11
12
cat > /etc/vimrc << "EOF"
" Begin /etc/vimrc
set nocompatible
set backspace=2
syntax on
if (&term == "iterm") || (&term == "putty")
set background=dark
endif
" End /etc/vimrc
EOF
cd ..
rm -rf vim71

LFS(三)
https://one-null-pointer.github.io/2023/06/13/Linux运维——LFS3/
Author
liaoyue
Posted on
June 13, 2023
传送口