[转载]完全手工打造自定义的LINUX(三)

三:构建LFS系统 我们通过 chroot 命令进入一个临时的微型 Linux 系统,并作一些最后的预备,然后开始安装软件包。在这里软件包的安装顺序应当严格遵守,以确保没有一个程序会把 /tools 作为路径硬连接到代码中。同样不要并行编译包。并行编译可能会节省时间,但也可能造成程序包含 /tools 硬连接路径,以致在 /tools 目录被删除之后,程序无法运行。

1:改变所有者;挂载虚拟内核文件系统;进入 Chroot 环境以及创建/dev设备

chown -R root:root $LFS/tools
mkdir -pv $LFS/
mknod -m 600 $LFS/dev/console c 5 1
mknod -m 666 $LFS/dev/null c 1 3
mount -v --bind /dev $LFS/dev
mount -vt devpts devpts $LFS/dev/pts
mount -vt tmpfs shm $LFS/dev/shm
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mkdir $LFS/cdrom
mount /dev/cdrom $LFS/cdrom
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

2:创建目录树和必要的符号链接

mkdir -pv /
mkdir -pv /,sbin,srv,var}
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
mkdir -pv /usr/
mkdir -pv /usr/share/
mkdir -pv /usr/share/
mkdir -pv /usr/share/man/man
for dir in /usr /usr/local; do
ln -sv share/ $dir
done
mkdir -pv /var/
mkdir -pv /var/,local}
ln -sv /tools/bin/ /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
ln -sv bash /bin/sh
touch /etc/mtab

3:创建 passwd, group, log 文件

cat /etc/passwd "EOF"
root:x:0:0:root:/root:/bin/bash
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF
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
exec /tools/bin/bash --login +h
touch /var/run/utmp /var/log/
chgrp -v utmp /var/run/utmp /var/log/lastlog
chmod -v 664 /var/run/utmp /var/log/lastlog
cd /sources
export LFS=/cdrom/lfs-sources

4:Linux Header

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

5:Man-pages

tar xvf $LFS/man-pages-2.63.tar.bz2
cd man-pages-2.63
make install
cd ..
rm -rf man-pages-2.63

6:Glibc

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 ‘slibs -olibs -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 21 tee glibc-check-log
grep Error glibc-check-log
touch /etc/ld.so.conf
make install
make localedata/install-locales

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
cp -v --remove-destination /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cat /etc/ld.so.conf "EOF"
/usr/local/lib
/opt/lib
EOF
cd ..
rm -rf glibc-build
rm -rf glibc-2.5.1

7:再次调整工具链 现在,最终的 C 库已经安装好了,我们需要再次调整工具链,让随后编译的那些工具都连接到这个库上。基本上,就是把前面"调整工具链"那里做的调整给取消掉。前面的工具链 使用的库是从宿主系统的 /lib 转向新安装的 /tools/lib 目录。同样的,现在工具链使用的库将从临时的 /tools/lib 转向 LFS 系统最终的 /lib 目录。

mv -v /tools/bin/
mv -v /tools/$/bin/
mv -v /tools/bin/
ln -sv /tools/bin/ld /tools/$/bin/ld
gcc -dumpspecs sed -e
-e ‘/“startfile_prefix_spec:/‘ -e ‘/“cpp:/‘ dummy.c
cc dummy.c
readelf -l a.out grep ‘tools‘
[Requesting program interpreter: /tools/lib/ld-linux.so.2] #有这个提示才表示成功
rm -rf a.out dummy.c

8:Binutils

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 tooldir=/usr install
cp -v ../binutils-2.17/include/libiberty.h /usr/include
cd ..
rm -rf binutils-build
rm -rf binutils-2.17

9:GCC

tar xvf $LFS/gcc-4.1.2.tar.bz2
cd gcc-4.1.2
sed -i ‘s/install_to_$ //‘ libiberty/Makefile.in
sed -i ‘s/^XCFLAGS =$/ -fomit-frame-pointer/‘ gcc/Makefile.in
sed -i 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-3.4.3

这里也最好是测试一下GCC,其方法和前面的测试方法一致。  10:Berkeley DB

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

11:Sed

tar xvf $LFS/sed-4.1.5.tar.gz
cd sed-4.1.5
./configure --prefix=/usr --bindir=/bin --enable-html
make
make check
make install
cd ..
rm -rf sed-4.1.5

12:E2fsprogs

tar xvf $LFS/e2fsprogs-1.40.2.tar.gz
cd e2fsprogs-1.40.2
sed -i -e lib/blkid/test_probe.in
mkdir -v build
cd build
../configure --prefix=/usr --with-root-prefix="" --enable-elf-shlibs
make
make check
make install
make install-libs
cd ../..
rm -rf e2fsprogs-1.40.2

13:Coreutils

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
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"
sed -i ‘/dummy/d‘ /etc/group
make install
mv -v /usr/bin/ /bin
mv -v /usr/bin/ /bin
mv -v /usr/bin/ /bin
mv -v /usr/bin/chroot /usr/sbin
mv -v /usr/bin/ /bin
cd ..
rm -rf coreutils-6.9

14:Iana-etc

tar xvf $LFS/iana-etc-2.20.tar.bz2
cd iana-etc-2.20
make
make install
cd ..
rm -rf iana-etc-2.20

15:M4

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

16:Bison

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

17:Ncurses

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$.so ; “
echo "INPUT" /usr/lib/lib$.so ; ln -sfv lib$w.a /usr/lib/lib$.a ; done
ln -sfv libncurses++w.a /usr/lib/libncurses++.a
rm -vf /usr/lib/libcursesw.so
echo "INPUT" /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

18:Procps

tar xvf $LFS/procps-3.2.7.tar.gz
cd procps-3.2.7
make
make install
cd ..
rm -rf procps-3.2.7

19:Libtool

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

20:Perl

tar xvf $LFS/perl-5.8.8.tar.bz2
cd perl-5.8.8
echo "127.0.0.1 localhost $" /etc/hosts
./configure.gnu --prefix=/usr -Dman1dir=/usr/share/man/man1 “
-Dman3dir=/usr/share/man/man3 -Dpager="/usr/bin/less -isR"
make
make test
make install
cd ..
rm -rf perl-5.8.8

21:Readline

tar xvf $LFS/readline-5.2.tar.gz
cd readline-5.2
sed -i ‘/MV.old/d‘ Makefile.in
sed -i ‘//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.a /usr/lib
rm -v /lib/lib.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

22:Zlib

tar xvf $LFS/zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/usr --shared --libdir=/lib
make
make check
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
make install
chmod -v 644 /usr/lib/libz.a
cd ..
rm -rf zlib-1.2.3

23:Autoconf

tar xvf $LFS/autoconf-2.61.tar.bz2
cd autoconf-2.61
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf autoconf-2.61

24:Automake

tar xvf $LFS/automake-1.10.tar.bz2
cd automake-1.10
./configure --prefix=/usr
make
make check
make install
cd ..
rm -rf automake-1.10

25:Bash

tar xvf $LFS/bash-3.2.tar.gz
cd bash-3.2
tar -xvf $LFS/bash-doc-3.2.tar.gz
sed -i "shtmldir = @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@ 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

26:Bzip

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/
ln -sv bzip2 /bin/bunzip2
ln -sv bzip2 /bin/bzcat
cd ..
rm -rf bzip2-1.0.4

27:Diffutils

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

28:File

tar xvf $LFS/file-4.21.tar.gz
cd file-4.21
./configure --prefix=/usr
make
make install
cd ..
rm -rf file-4.21

29:Findutils

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:=$/find:=“/bin/‘ /usr/bin/updatedb
cd ..
rm -rf findutils-4.2.31

30:Flex

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
cat /usr/bin/lex "EOF"
#!/bin/sh
# Begin /usr/bin/lex
exec /usr/bin/flex -l "$@"
# End /usr/bin/lex
EOF
chmod -v 755 /usr/bin/lex
cd ..
rm -rf flex-2.5.33

31:Grub

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 /boot/grub
cd ..
rm -rf grub-0.97

32:Gawk

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

33:Gettext

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

34:Grep

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

35:Groff

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

36:Gzip

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/ /usr/bin
mv -v /bin/ /usr/bin
cd ..
rm -rf gzip-1.3.12

37:Inetutils

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

38:Iproute

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

39:Kbd

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/ /bin
cd ..
rm -rf kbd-1.12

40:Less

tar xvf $LFS/less-406.tar.gz
cd less-406
./configure --prefix=/usr --sysconfdir=/etc
make
make install
cd ..
rm -rf less-406

41:Make

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

42:Man-db

tar xvf $LFS/man-db-2.4.4.tar.gz
cd man-db-2.4.4
mv man/de
mv man/es
mv man/it
sed -i ‘s,“_“,,‘ man/Makefile.in
sed -i -e ‘“%/usr/man%d‘ -e ‘“%/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 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

43:Mktemp

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

44:Module-init-tools

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

45:Patch

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

46:Psmisc

tar xvf $LFS/psmisc-22.5.tar.gz
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

47:Shadow

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$ //‘ 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 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 pwconv
grpconv
useradd -D -b /home
sed -i ‘s/yes/no/‘ /etc/default/useradd
passwd root
cd ..
rm -rf shadow-4.0.18.1

48:Sysklogd

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

49:Sysvinit

tar xvf $LFS/sysvinit-2.86.tar.gz
cd sysvinit-2.86
sed -i ‘s@Sending processes@ configured via src/init.c
make -C src
make -C src install
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

50:Tar

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

51:Textinfo

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

52:Udev

tar xvf $LFS/udev-113.tar.bz2
cd udev-113
tar -xvf $LFS/udev-config-6.3.tar.bz2
install -dv /lib/}
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
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

53:Util-linux

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 $
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

54:Vim

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
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
cat /etc/vimrc "EOF"
" Begin /etc/vimrc
set nocompatible
set backspace=2
syntax on
if
set background=dark
endif
" End /etc/vimrc
EOF
cd ..
rm -rf vim71

55:再次清理系统

logout
chroot $LFS /tools/bin/env -i HOME=/root TERM=$TERM PS1=‘“u:“w“$ ‘ “
PATH=/bin:/usr/bin:/sbin:/usr/sbin /tools/bin/bash --login
/tools/bin/find / -type f -exec /tools/bin/strip --strip-debug ‘‘ ‘;‘
logout
chroot "$LFS" /usr/bin/env -i HOME=/root TERM="$TERM" PS1=‘“u:“w“$ ‘ “
PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/bash --login
cd /sources
export LFS=/cdrom/lfs-sources/

56:Lfs-bootscripts

tar xvf $LFS/lfs-bootscripts-6.3.tar.bz2
cd lfs-bootscripts-6.3
make install
cd ..
rm -rf lfs-bootscripts-6.3

57:创建相应的脚本和设备文件 其中的主机名称和网络相关的设置请根据实际的情况进行设置。不然,可能会导致网络服务使用不正常。

cat /etc/sysconfig/clock "EOF"
# Begin /etc/sysconfig/clock
UTC=1
# End /etc/sysconfig/clock
EOF cat /etc/inputrc "EOF"
set horizontal-scroll-mode Off
set meta-flag On
set input-meta On
set convert-meta Off
set output-meta On
set bell-style none
"“eOd": backward-word
"“eOc": forward-word
"“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
"“eOH": beginning-of-line
"“eOF": end-of-line
"“e[H": beginning-of-line
"“e[F": end-of-line
EOF cat /etc/profile "EOF"
# Begin /etc/profile
export LANG=zh_CN.UTF-8
export INPUTRC=/etc/inputrc
alias ls="ls --color"
export PS1=‘“u:“w“$ ‘
# End /etc/profile
EOF echo "HOSTNAME=mylinux" /etc/sysconfig/network
cat /etc/hosts "EOF"
# Begin /etc/hosts
127.0.0.1 mylinux localhost
# End /etc/hosts
EOF cd /etc/sysconfig/network-devices
mkdir -v ifconfig.eth0
cat ifconfig.eth0/ipv4 "EOF"
ONBOOT=yes
SERVICE=ipv4-static
IP=192.168.44.42
GATEWAY=192.168.44.2
PREFIX=24
BROADCAST=192.168.44.255
EOF cat /etc/resolv.conf "EOF"
# Begin /etc/resolv.conf
nameserver 192.168.42.21
nameserver 192.168.42.6
# End /etc/resolv.conf
EOF cat /etc/fstab "EOF"
# Begin /etc/fstab
# file system mount-point type options dump fsck
# order
/dev/hda2 / ext3 defaults 1 1
/dev/hda1 swap swap pri=1 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
devpts /dev/pts devpts gid=4,mode=620 0 0
shm /dev/shm tmpfs defaults 0 0
# End /etc/fstab
EOF

58:编译内核 假如在建立虚拟机的时候是选择的BusLogic的SCSI磁盘,那么应该在Device Drivers-SCSI device support-SCSI lowleveldrivers下加入BusLogic SCSI support的支持,可以采用编译到内核来避免未用initrd脚本来加载模块而导致启动失败;假如想支持网络则应该在Device Drivers-Networking support-Ethernet 加入AMD PCnet32 PCI support
的支持,可以采用编译到内核也可以编译成模块的方式。

cd /sources
tar xvf $LFS/linux-2.6.22.5.tar.bz2
cd linux-2.6.22.5
make mrproper
make menuconfig
make
make modules_install
cp -v arch/i386/boot/bzImage /boot/lfskernel-2.6.22.5
cp -v System.map /boot/System.map-2.6.22.5
cp -v .config /boot/config-2.6.22.5
install -d /usr/share/doc/linux-2.6.22.5
cp -r Documentation/ /usr/share/doc/linux-2.6.22.5

59:配置启动文件

grub
root
setup
quit cat /boot/grub/menu.lst "EOF"
# Begin /boot/grub/menu.lst
# By default boot the first menu entry.
default 0
# Allow 30 seconds before booting the default.
timeout 30
# Use prettier colors.
color green/black light-green/black
# The first entry is for LFS.
title Clean of Linux
root
kernel /boot/lfskernel-2.6.22.5 root=/dev/hda2
EOF mkdir -v /etc/grub
ln -sv /boot/grub/menu.lst /etc/grub
logout

 

四:测试 至此,自定义的Linux已可以启动使用了,假如你想加入其它的功能就自己定制使用吧,是不是觉得不是很难呢,当然,要完全的消化理解是要一定时间的,慢慢来吧,一切都会因努力而更加美好,不是吗?

 

 

 

完全手工打造自定义的LINUX(一)

完全手工打造自定义的LINUX(二)

 

» 本文链接地址:https://www.xidige.com/178

打开支付宝扫一扫,即可进行扫码打赏哦

扫码支持
扫码打赏,你说多少就多少

标签:

分享到:

扫一扫 在手机阅读、分享本文

上一篇: 下一篇:
评论区0人评论285人参与

电子邮件地址不会被公开。 必填项已用*标注

*

loading

赞助商广告