制作工具链:
1.cd $LFS/sources 进入编译目录
2.安装binutils
tar xvf /lfs-sources/binutils-2.17.tar.bz2
cd binutils-2.17
mkdir -v ../binutils-build
cd ../binutils-build
CC="gcc -B/usr/bin/"
../binutils-2.17/configure --prefix=/tools --disable-nls --disable-werror
make
make install
make -C ld clean
make -C ld LIB_PATH=/tools/lib cp -v ld/ld-new /tools/bin
cd ..
rm -rf binutils-build
rm -rf binutils-2.17
3.安装gcc
tar xvf /lfs-sources/gcc-4.1.2.tar.bz2
mkdir -v gcc-build
cd gcc-build
CC="gcc -B/usr/bin/" ../gcc-4.1.2/configure --prefix=/tools /
--with-local-prefix=/tools --disable-nls /
--enable-shared --enable-languages=c
make bootstrap
make install
ln -vs gcc /tools/bin/cc
cd ..
rm -rf gcc-build
rm -rf gcc-4.1.2
4.安装内核头
tar xvf /lfs-sources/linux-2.6.22.5.tar.bz
cd linux-2.6.22.5
make mrproper
make headers_check
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include
cd ..
rm -rf linux-2.6.22.5
5.安装glibc
tar xvf /lfs-sources/glibc-2.5.1.tar.bz2
cd glibc-2.5.1
mkdir -v ../glibc-build
cd ../glibc-build
../glibc-2.5.1/configure --prefix=/tools /
--disable-profile --enable-add-ons /
--enable-kernel=2.6.0 --with-binutils=/tools/bin /
--without-gd --with-headers=/tools/include /
--without-selinux
make
mkdir -v /tools/etc
touch /tools/etc/ld.so.conf
make install
cd ..
rm -rf glibc-build
rm -rf glibc-2.5.1
6.调整工具链
mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld
gcc -dumpspecs | sed 's@^/lib/ld-linux.so.2@/tools&@g' > `dirname $(gcc -print-libgcc-file-name)`/specs
GCC_INCLUDEDIR=`dirname $(gcc -print-libgcc-file-name)`/include &&
find ${GCC_INCLUDEDIR}/* -maxdepth 0 -xtype d -exec rm -rvf '{}' /; &&
rm -vf `grep -l "DO NOT EDIT THIS FILE" ${GCC_INCLUDEDIR}/*` &&
unset GCC_INCLUDEDIR
7.
测试工具链的调整
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep 'tools'
如果输出大致如下
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
则表示调整成功,因为所有的库已经连接到了/tools/lib下。
rm -rf a.out dummy.c
8.测试工具的安装
说明:这部分将安装3个用于第六章各种源码包编译后的测试的工具,所以如果你不打算做make check之类的事情,那么这3个包可以不装。
Tcl-8.4.15 Expect-5.43.0 DejaGNU-1.4.4
tar xvf /lfs-sources/tcl8.4.15-src.tar.gz
cd tcl8.4.15/unix
./configure --prefix=/tools
make
make install
make install-private-headers
ln -sv tclsh8.4 /tools/bin/tclsh
cd $LFS/sources
tar xvf /lfs-sources/expect-5.43.0.tar.gz
cd expect-5.43
patch -Np1 -i /lfs-sources/expect-5.43.0-spawn-1.patch
cp configure{,.bak}
sed 's:/usr/local/bin:/bin:' configure.bak > configure
./configure --prefix=/tools --with-tcl=/tools/lib --with-tclinclude=/tools/include --with-x=no
make
make SCRIPTS="" install
cd $LFS/sources
tar xvf /lfs-sources/dejagnu-1.4.4.tar.gz
cd dejagnu-1.4.4
./configure --prefix=/tools
make install
cd ..
rm -rf tcl8.4.15
rm -rf expect-5.43
rm -rf dejagnu-1.4.4
9.第二遍安装gcc
tar xvf /lfs-sources/gcc-4.1.2.tar.bz2
cd gcc-4.1.2
cp -v gcc/Makefile.in{,.orig}
sed 's@/./fixinc/.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in
cp -v gcc/Makefile.in{,.tmp}
sed 's/^XCFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp /
> gcc/Makefile.in
patch -Np1 -i /lfs-sources/gcc-4.1.2-specs-1.patch
mkdir -v ../gcc-build
cd ../gcc-build
../gcc-4.1.2/configure --prefix=/tools /
--with-local-prefix=/tools /
--enable-clocale=gnu --enable-shared /
--enable-threads=posix --enable-__cxa_atexit /
--enable-languages=c,c++ --disable-libstdcxx-pch
make
make install
cd ..
rm -rf gcc-build
rm -rf gcc-4.1.2
10.再次测试工具链的调整,以确保刚刚编译的gcc正确工作
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep 'tools'
如果输出大致如下
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
则表示调整成功,因为所有的库已经连接到了/tools/lib下。
rm -rf a.out dummy.c
11.安装 Binutils-2.17 - Pass 2
tar xvf /lfs-sources/binutils-2.17.tar.bz2
mkdir -v binutils-build
cd binutils-build
../binutils-2.17/configure --prefix=/tools --disable-nls /
--with-lib-path=/tools/lib
make
make install
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin
cd ..
rm -rf binutils-build
rm -rf binutils-2.17
12.安装Ncurses-5.6
tar xvf /lfs-sources/ncurses-5.6.tar.gz
cd ncurses-5.6
./configure --prefix=/tools --with-shared --without-debug --without-ada --enable-overwrite
make
make install
cd ..
rm -rf ncurses-5.6
13.安装bash
tar xvf /lfs-sources/bash-3.2.tar.gz
cd bash-3.2
patch -Np1 -i /lfs-sources/bash-3.2-fixes-5.patch
./configure --prefix=/tools --without-bash-malloc
make
make install
ln -vs bash /tools/bin/sh
cd ..
rm -rf bash-3.2
14.安装bzip
tar xvf /lfs-sources/bzip2-1.0.4.tar.gz
cd bzip2-1.0.4
make
make PREFIX=/tools install
cd ..
rm -rf bzip2-1.0.4
15.安装coreutils
tar xvf /lfs-sources/coreutils-6.9.tar.bz2
cd coreutils-6.9
./configure --prefix=/tools
make
make install
cp -v src/su /tools/bin/su-tools
cd ..
rm -rf coreutils-6.9
16.安装diffutils
tar xvf /lfs-sources/diffutils-2.8.1.tar.gz
cd diffutils-2.8.1
./configure --prefix=/tools
make
make install
cd ..
rm -rf diffutils-2.8.1
17.安装findutils
tar xvf /lfs-sources/findutils-4.2.31.tar.gz
cd findutils-4.2.31
./configure --prefix=/tools
make
make install
cd ..
rm -rf findutils-4.2.31
18.安装gawk
tar xvf /lfs-sources/gawk-3.1.5.tar.bz2
cd gawk-3.1.5
./configure --prefix=/tools
cat >> config.h << "EOF"
#define HAVE_LANGINFO_CODESET 1
#define HAVE_LC_MESSAGES 1
EOF
make
make install
cd ..
rm -rf gawk-3.1.5
19.安装gettext
tar xvf /lfs-sources/gettext-0.16.1.tar.gz
cd gettext-0.16.1
cd gettext-tools
./configure --prefix=/tools --disable-shared
make -C gnulib-lib
make -C src msgfmt
cp -v src/msgfmt /tools/bin
cd $LFS/sources
rm -rf gettext-0.16.1
20.安装grep
tar xvf /lfs-sources/grep-2.5.1a.tar.bz2
cd grep-2.5.1a
./configure --prefix=/tools --disable-perl-regexp
make
make install
cd ..
rm -rf grep-2.5.1a
21.安装gzip
tar xvf /lfs-sources/gzip-1.3.12.tar.gz
cd gzip-1.3.12
./configure --prefix=/tools
make
make install
cd ..
rm -rf gzip-1.3.12
22安装make
tar xvf /lfs-sources/make-3.81.tar.bz2
cd make-3.81
./configure --prefix=/tools
make
make install
cd ..
rm -rf make-3.81
23.安装patch
tar xvf /lfs-sources/patch-2.5.4.tar.gz
cd patch-2.5.4
./configure --prefix=/tools
make
make install
cd ..
rm -rf patch-2.5.4
24.安装perl
tar xvf /lfs-sources/perl-5.8.8.tar.bz2
cd perl-5.8.8
patch -Np1 -i /lfs-sources/perl-5.8.8-libc-2.patch
./configure.gnu --prefix=/tools -Dstatic_ext='Data/Dumper Fcntl IO POSIX'
make perl utilities
cp -v perl pod/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.8.8
cp -Rv lib/* /tools/lib/perl5/5.8.8
cd ..
rm -rf perl-5.8.8
25.安装sed
tar xvf /lfs-sources/sed-4.1.5.tar.gz
cd sed-4.1.5
./configure --prefix=/tools
make
make install
cd ..
rm -rf sed-4.1.5
cd tar-1.18
./configure --prefix=/tools
make
make install
cd ..
rm -rf tar-1.18
cd texinfo-4.9
./configure --prefix=/tools
make
make install
cd ..
rm -rf texinfo-4.9
cd util-linux-2.12r
sed -i 's@/usr/include@/tools/include@g' configure
./configure
make -C lib
make -C mount mount umount
make -C text-utils more
cp -v mount/{,u}mount text-utils/more /tools/bin
cd ..
rm -rf util-linux-2.12r
strip --strip-unneeded /tools/{,s}bin/*
现在你应该是处于root用户状态的,看看你的命令行提示符是不是回到了#。
从现在开始不在需要lfs用户来制作系统了,因此我们用
创建三个重要目录
这个时候也许你想睡觉关机了,那么重新开机后回到工作状态的步骤是:
1.重新启动计算机,并从LiveCD启动
2.加载分区
export LFS=/mnt/lfs
mkdir -pv $LFS
mount /dev/hda2 $LFS
3.加载交换分区(如果不想用交换分区或者没有交换分区可跳过此步骤)
swapon /dev/hda1
相关知识点:
这时候已经制作好了工具链,因此可以不需要建立根目录下的tools链接了。
mount -vt tmpfs shm $LFS/dev/shm
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount命令加载的分区在重新启动后就失效了,所以在这其中重新启动则需要重新加载。
这里为了方便使用源码包,我将光盘加载到目标系统里
mkdir $LFS/cdrom
mount /dev/cdrom $LFS/cdrom
这个步骤不是必须的,如果你想使用,那么在重新启动后进入工作状态的步骤中在相应的位置上加入。
这里有一个更简单的办法,将lfs-sources里面所有源码包复制到$LFS/sources目录中,这步对于后面在第六章使用源代码将非常方便。
为了方便在制作完后的系统能够直接显示中文,这里可以从网络上下载本人写的一个显示UTF-8编码文字的内核补丁。
使用下面的命令来下载:
cd $LFS/sources/
wget http://zdbr.net.cn/download/utf8-kernel-2.6.22.5-core-1.patch.bz2
wget http://zdbr.net.cn/download/utf8-kernel-2.6.22.5-fonts-1.patch.bz2
解压缩这两个补丁
bunzip2 utf8-kernel-2.6.22.5-core-1.patch.bz2
bunzip2 utf8-kernel-2.6.22.5-fonts-1.patch.bz2
Chroot到目标系统的目录下,以便不受主系统的影响来制作目标系统
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin /
/tools/bin/bash --login +h
这个时候如果你关机或重新启动,那么重新开机后回到工作状态的步骤是:
1.重新启动计算机,并从LiveCD启动
2.加载分区
export LFS=/mnt/lfs
mkdir -pv $LFS
mount /dev/hda2 $LFS
3.加载交换分区(如果不想用交换分区或者没有交换分区可跳过此步骤)
swapon /dev/hda1
4.加载必要的文件系统
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
5.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