备注:曾经看过<手把手教你如何建立自己的Linux系统>,但是制作后还是有些问题,一开始以为是自己打错了,后来发现其实是教程里漏掉一部分内容。所以自己又写了个详尽版本的,我已经成功进去了,所以这个版本没有问题。至于中途退出怎么重进的问题,我这里没有写,你可以在Vmware保存镜像,也可以用计算机休眠来保存状态,或者查看《手把手教你如何建立自己的Linux系统》
准备工作
Vmware 7.1
SecureCRT
# 为了保证成功率,这里使用了livecd
lfslivecd-x86-6.3-r2145.iso
Vmware 设置,除了内存你自己设置大点,大于256M最好,我设置的是640M,还有网络连接,你选择桥接,也就是bridge,也就是第一个。其他的均默认
启动VMware,进入系统后按回车
选择时区,上海
选择locale,chinese 简体 utf8
然后直接回车
看到 root[~]#: 后
#这里你有两个选择,手动输入和复制黏贴输入,如果手动输入,你不需要使用 SecureCRT,如果你是使用复制黏贴,那么就用。建议使用复制黏贴,因为手动输入很容易错误,如果你使用SecureCRT,建议首先输入:
#--------------------------------------------
# 修改管理员密码
#--------------------------------------------
passwd root
#--------------------------------------------
# 打开 sshd链接
#--------------------------------------------
/etc/rc.d/init.d/sshd start
#--------------------------------------------
# 查看 Ip 地址,从图中看到,我这里是 192.168.118.137,因为使用Vmware,每次都不同哦
#--------------------------------------------
ifconfig
#--------------------------------------------
# 然后是使用 SecureCRT登入
#--------------------------------------------
#密码就是上面设置的 root 密码
登入成功了。下面可以在SecureCRT进行操作,Vmware 缩小就可以,不要关闭哦。
#--------------------------------------------------------------------
# 用SecureCRT登入虚拟机,下面的操作开始可以在 SecureCRT 下面进行
# 在 SecureCRT 中可以使用复制黏贴,为了防止你打字出错,建议直接使用复制黏贴
#--------------------------------------------------------------------
# 因为 VMware 默认是 SCSI 所以我这里是 sda ,如果你设置的是 IDE,那么你就是hda
cfdisk /dev/sda
选择 New --> Primary 新建分区,sda1设置为你在VMware中设置的内存的大小作为 swarp区,而剩余的分为一个区
然后点 write ,输入 yes 保存后 Quit
#--------------------------------------------------------------------
# New --> Primary --> [大小为你设置的虚拟内存大小,我设置的是1024] ---> Beginning
# New --> Primary --> [剩余大小,我直接按回车,全部选择] ---> Beginning
# 选择 Write , 输入 yes
# 选择 Quite 完成分区,下面开始格式化[这里要注意,如果你一开始用虚拟器设置硬盘是SCSI的话,后面是 sda1 而不是 hda1]
#--------------------------------------------------------------------
# mke2fs -jv 设置的是 ext3 格式,至于为什么建立ext3,因为比较帅
mkswap /dev/sda1
mke2fs -jv /dev/sda2
#--------------------------------------------------------------------
# 下面开始准备工作,首先是预设一下 LFS 变量为 /mnt/ls 路径,这样做方面下面的重复操作
#--------------------------------------------------------------------
export LFS=/mnt/lfs
#--------------------------------------------------------------------
# 加载/dev/sda2 到 /mnt/lfs 下
#--------------------------------------------------------------------
mkdir -pv $LFS
mount -v -t ext3 /dev/sda2 $LFS
#--------------------------------------------------------------------
# 使用swap
#--------------------------------------------------------------------
/sbin/swapon -v /dev/sda1
#--------------------------------------------------------------------
# 创建 sources 作为存放源程序的文件夹,并且设置该文件夹可读写权限
# 相关知识点:
# chmod a+wt是将目录或文件的属性设置为1777,这样任何人都可以对其进行读写。
#--------------------------------------------------------------------
mkdir -v $LFS/sources
chmod -v a+wt $LFS/sources
#--------------------------------------------------------------------
# 创建工具链目录,用来存放编译好的编译新软件使用的工具
# ln 是将这个目录在 / [根目录]下创造一个链接,这样就能直接用 /tools 访问 /mnt/lfs/tools 了
#--------------------------------------------------------------------
mkdir -v $LFS/tools
ln -sv $LFS/tools /
#--------------------------------------------------------------------
# 创建 lfs 用户组和 lfs 账户
#--------------------------------------------------------------------
groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
#--------------------------------------------------------------------
# 设置 lfs 密码,为空就行
#--------------------------------------------------------------------
passwd lfs
#--------------------------------------------------------------------
# 将tools和sources目录的用户改为lfs,以便后面使用lfs来操作这两个目录
#--------------------------------------------------------------------
chown -v lfs $LFS/tools
chown -v lfs $LFS/sources
#--------------------------------------------------------------------
# 登入到 lfs 用户,这是一会发现原来 root[~]# 变成了 lfs[~]$
#--------------------------------------------------------------------
su - lfs
#--------------------------------------------------------------------
# 建立lfs用户的环境
# 创建 bash_profile 文件
#--------------------------------------------------------------------
cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF
#--------------------------------------------------------------------
# 创建 bashrc 文件
# 这里如果是在 SecureCRT 登入的话 TERM 是 vt100
#--------------------------------------------------------------------
cat > ~/.bashrc << "EOF"
set +h
umask 022
LFS=/mnt/lfs
LC_ALL=POSIX
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL PATH
EOF
#--------------------------------------------------------------------
# 用新配置登入 bash
#--------------------------------------------------------------------
source ~/.bash_profile
#--------------------------------------------------------------------
# 进入编译目录
#--------------------------------------------------------------------
cd $LFS/sources
# 每个程序安装完都要删除解压的目录,以防止后面出现问题
#--------------------------------------------------------------------
# Binutils-2.17 - Pass 1 安装
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# GCC-4.1.2 - Pass 1 安装
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Linux-2.6.22.5 API Headers 安装
#--------------------------------------------------------------------
tar xvf /lfs-sources/linux-2.6.22.5.tar.bz2
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
#--------------------------------------------------------------------
# Glibc-2.5.1 安装
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 调整一下工具链,就是用现在的工具链代替原来的那个
# 相关知识点:
# 工具链的调整方法有好几种,而且不同版本GCC的specs可能会有不同,但实际上都是把specs文件中的/lib/ld-linux.so.2替换成了/tools/lib/ld-linux.so.2,所以即使有些文章在调整工具链上的命令和LFS手册上的不一样也不用太奇怪,当然也可以直接用gcc -dumpspecs导出后手工直接编辑specs文件。
#--------------------------------------------------------------------
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
# *******************************************************************
# 测试工具链的调整
# 可做可不做
# *******************************************************************
#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 -v a.out dummy.c
#*******************************************************************
# 测试工具的安装
# 这部分将安装3个用于第六章各种源码包编译后的测试的工具,所以如果你不打算做make check之类的事情,那么这3个包可以不装。
# 我没有装,make check 好累
#*******************************************************************
# 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
#TZ=UTC make test
#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
#--------------------------------------------------------------------
# GCC-4.1.2 - Pass 2
#--------------------------------------------------------------------
tar xvf /lfs-sources/gcc-4.1.2.tar.bz2
cd gcc-4.1.2
expect -c "spawn ls"
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 -k check
make install
cd ..
rm -rf gcc-build
rm -rf gcc-4.1.2
#*******************************************************************
# 再次测试工具链的调整,以确保刚刚编译的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 -v a.out dummy.c
#--------------------------------------------------------------------
# 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
#--------------------------------------------------------------------
# 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
#--------------------------------------------------------------------
# Bash-3.2
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Bzip2-1.0.4
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Coreutils-6.9
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Diffutils-2.8.1
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Findutils-4.2.31
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Gawk-3.1.5
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Gettext-0.16.1
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Grep-2.5.1a
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Gzip-1.3.12
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Make-3.81
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Patch-2.5.4
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Perl-5.8.8
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Sed-4.1.5
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Tar-1.18
#--------------------------------------------------------------------
tar xvf /lfs-sources/tar-1.18.tar.bz2
cd tar-1.18
./configure --prefix=/tools
make
make install
cd ..
rm -rf tar-1.18
#--------------------------------------------------------------------
# Texinfo-4.9
#--------------------------------------------------------------------
tar xvf /lfs-sources/texinfo-4.9.tar.bz2
cd texinfo-4.9
./configure --prefix=/tools
make
make install
cd ..
rm -rf texinfo-4.9
#--------------------------------------------------------------------
# Util-linux-2.12r
#--------------------------------------------------------------------
tar xvf /lfs-sources/util-linux-2.12r.tar.bz2
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
#********************************************************************
# Stripping 可有可无
#********************************************************************
strip --strip-debug /tools/lib/*
strip --strip-unneeded /tools/{,s}bin/*
rm -rf /tools/{info,man}
#--------------------------------------------------------------------
# 退出lfs用户(这步不要少了)
#--------------------------------------------------------------------
exit
#--------------------------------------------------------------------
# 从现在开始不在需要lfs用户来制作系统了,因此我们改回来权限
#--------------------------------------------------------------------
chown -R root:root $LFS/tools
#--------------------------------------------------------------------
# 创建三个重要目录
#--------------------------------------------------------------------
mkdir -pv $LFS/{dev,proc,sys}
#--------------------------------------------------------------------
# 创建两个目标系统所必须的设备文件
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 将lfs-sources里面所有源码包复制到$LFS/sources目录中,这步对于后面在第六章使用源代码将非常方便
#--------------------------------------------------------------------
cp -a /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到目标系统的目录下,以便不受主系统的影响来制作目标系统
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 建立目标系统的目录结构
#--------------------------------------------------------------------
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
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{doc,info,locale,man}
mkdir -pv /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -pv /usr/{,local/}share/man/man{1..8}
for dir in /usr /usr/local; do
ln -sv share/{man,doc,info} $dir
done
mkdir -pv /var/{lock,log,mail,run,spool}
mkdir -pv /var/{opt,cache,lib/{misc,locate},local}
#--------------------------------------------------------------------
# 创建几个必要的链接,因为在目标系统的编译过程中,部分编译程序会用绝对路径来寻找命令或文件
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 创建root及nobody用户和必要的组
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 重新加载bash,以使root用户起效,这样前面的提示符就不会是“I have no name!”
#--------------------------------------------------------------------
exec /tools/bin/bash --login +h
#--------------------------------------------------------------------
# 创建和设置几个临时文件和日志文件。
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 开始目标系统软件安装。进入到源码目录下
#--------------------------------------------------------------------
cd /sources
#--------------------------------------------------------------------
# 设置 LFS
#--------------------------------------------------------------------
export LFS=/sources
#--------------------------------------------------------------------
# Linux-2.6.22.5
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Man-pages-2.63
#--------------------------------------------------------------------
tar xvf $LFS/man-pages-2.63.tar.bz2
cd man-pages-2.63
make install
cd ..
rm -rf man-pages-2.63
#--------------------------------------------------------------------
# Glibc-2.5.1,会出错,忽略
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 建立几个重要文件:
#--------------------------------------------------------------------
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
tzselect
cp -v --remove-destination /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cat > /etc/ld.so.conf << "EOF"
# Begin /etc/ld.so.conf
/usr/local/lib
/opt/lib
# End /etc/ld.so.conf
EOF
#--------------------------------------------------------------------
# 删除 Glibc 编译目录
#--------------------------------------------------------------------
cd ..
rm -rf glibc-build
rm -rf glibc-2.5.1
#--------------------------------------------------------------------
# 调整工具链
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 调整specs文件
#--------------------------------------------------------------------
gcc -dumpspecs | sed \
-e 's@/tools/lib/ld-linux.so.2@/lib/ld-linux.so.2@g' \
-e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \
-e '/\*cpp:/{n;s@$@ -isystem /usr/include@}' > \
`dirname $(gcc --print-libgcc-file-name)`/specs
#********************************************************************
# 测试工具链是否被调整成功,可以不进行
#********************************************************************
#echo 'main(){}' > dummy.c
#cc dummy.c -v -Wl,--verbose &> dummy.log
#readelf -l a.out | grep '/lib'
#如果显示[Requesting program interpreter: /lib/ld-linux.so.2]表示调整成功,动态库已经连接到了目标系统的/lib下。
#grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
#应该显示
# /usr/lib/crt1.o succeeded
# /usr/lib/crti.o succeeded
# /usr/lib/crtn.o succeeded
#grep -B1 '^ /usr/include' dummy.log
#应该显示
# #include <...> search starts here:
# /usr/include
#grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'
#应该显示
# SEARCH_DIR("/tools/i686-pc-linux-gnu/lib")
# SEARCH_DIR("/usr/lib")
# SEARCH_DIR("/lib");
#grep "/lib/libc.so.6 " dummy.log
#应该显示
# attempt to open /lib/libc.so.6 succeeded
#grep found dummy.log
#应该显示
# found ld-linux.so.2 at /lib/ld-linux.so.2
#如果上面均显示正常,那么表明工具链调整成功,可以删除测试文件了
#rm -v dummy.c a.out dummy.log
#--------------------------------------------------------------------
# Binutils-2.17
#--------------------------------------------------------------------
tar xvf $LFS/binutils-2.17.tar.bz2
expect -c "spawn ls"
mkdir binutils-build
cd binutils-build
../binutils-2.17/configure --prefix=/usr --enable-shared
make tooldir=/usr
# 由于前面没有装测试用的工具,所以我这里就不用测试了
#make check
make tooldir=/usr install
cp -v ../binutils-2.17/include/libiberty.h /usr/include
cd ..
rm -rf binutils-build
rm -rf binutils-2.17
#--------------------------------------------------------------------
# GCC-4.1.2
#--------------------------------------------------------------------
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
#********************************************************************
# 重新测试工具链是否正确,确定GCC是否安装正确,可做可不做
#********************************************************************
#echo 'main(){}' > dummy.c
#cc dummy.c -v -Wl,--verbose &> dummy.log
#readelf -l a.out | grep 'lib'
#如果显示[Requesting program interpreter: /lib/ld-linux.so.2]表示链接位置正确,动态库已经连接到了目标系统的/lib下。
#grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
#应该显示
# /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../crt1.o succeeded
# /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../crti.o succeeded
# /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/../../../crtn.o succeeded
#grep -B3 '^ /usr/include' dummy.log
#应该显示
# #include <...> search starts here:
# /usr/local/include
# /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include
# /usr/include
#grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'
#应该显示
# SEARCH_DIR("/usr/i686-pc-linux-gnu/lib")
# SEARCH_DIR("/usr/local/lib")
# SEARCH_DIR("/lib")
# SEARCH_DIR("/usr/lib");
#grep "/lib/libc.so.6 " dummy.log
#应该显示
# attempt to open /lib/libc.so.6 succeeded
#grep found dummy.log
#应该显示
# found ld-linux.so.2 at /lib/ld-linux.so.2
#如果上面均显示正常,那么表明工具链正常,可以删除测试文件了
#rm -v dummy.c a.out dummy.log
#--------------------------------------------------------------------
# Berkeley DB-4.5.20
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# E2fsprogs-1.40.2
#--------------------------------------------------------------------
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
make install
make install-libs
cd ../..
rm -rf e2fsprogs-1.40.2
#--------------------------------------------------------------------
# Coreutils-6.9
#--------------------------------------------------------------------
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/{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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Procps-3.2.7
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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 check
make install
cd ..
rm -rf perl-5.8.8
#--------------------------------------------------------------------
# Readline-5.2
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Autoconf-2.61
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Automake-1.10
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Bash-3.2
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 应用 bash
#--------------------------------------------------------------------
exec /bin/bash --login +h
#--------------------------------------------------------------------
# Bzip2-1.0.4
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# GRUB-0.97
#--------------------------------------------------------------------
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
# 这里要注意,如果你格式化时候是用的 xfs,那么就复制 xfs_stage1_5
cp -v /usr/lib/grub/i386-pc/e2fs_stage1_5 /boot/grub
cd ..
rm -rf grub-0.97
#--------------------------------------------------------------------
# Gawk-3.1.5
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Shadow-4.0.18.1
#--------------------------------------------------------------------
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
# 配置增加用户的默认设置
pwconv
grpconv
useradd -D -b /home
sed -i 's/yes/no/' /etc/default/useradd
# 修改root用户密码
passwd root
cd ..
rm -rf shadow-4.0.18.1
#--------------------------------------------------------------------
# Sysklogd-1.4.1
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# Sysvinit-2.86
#--------------------------------------------------------------------
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
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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
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
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
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 (&term == "iterm") || (&term == "putty")
set background=dark
endif
" End /etc/vimrc
EOF
cd ..
rm -rf vim71
# 退出choroot
logout
# 为Strip而进入chroot环境
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 /{,usr/}{bin,lib,sbin} -type f \
-exec /tools/bin/strip --strip-debug '{}' ';'
# 退出chroot环境
logout
# 为最后的设置进入chroot环境
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=/sources
#--------------------------------------------------------------------
# LFS-Bootscripts-6.3
#--------------------------------------------------------------------
tar xvf $LFS/lfs-bootscripts-6.3.tar.bz2
cd lfs-bootscripts-6.3
make install
cd ..
rm -rf lfs-bootscripts-6.3
#--------------------------------------------------------------------
# 时间设置(Configuring the setclock Script)
#--------------------------------------------------------------------
cat > /etc/sysconfig/clock << "EOF"
# Begin /etc/sysconfig/clock
UTC=1
# End /etc/sysconfig/clock
EOF
#--------------------------------------------------------------------
# 设置bash下的键盘功能键设置
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 设置Bash Shell启动文件(The Bash Shell Startup Files
#--------------------------------------------------------------------
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
#--------------------------------------------------------------------
# 设置本地网络名
#--------------------------------------------------------------------
# mylinux就是你设置的主机名,这个随便你喜欢
echo "HOSTNAME=mylinux" > /etc/sysconfig/network
#--------------------------------------------------------------------
# 设置hosts文件
#--------------------------------------------------------------------
# mylinux就是你设置的主机名
cat > /etc/hosts << "EOF"
# Begin /etc/hosts (no network card version)
127.0.0.1 mylinux localhost
# End /etc/hosts (no network card version)
EOF
#--------------------------------------------------------------------
# 设置网络的静态地址
#--------------------------------------------------------------------
cd /etc/sysconfig/network-devices
mkdir -v ifconfig.eth0
cat > ifconfig.eth0/ipv4 << "EOF"
ONBOOT=yes
SERVICE=ipv4-static
IP=192.168.1.1
GATEWAY=192.168.1.2
PREFIX=24
BROADCAST=192.168.1.255
EOF
#--------------------------------------------------------------------
# 设置DNS
#--------------------------------------------------------------------
cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf
nameserver 你的首个DNS的地址
nameserver 你的第二DNS的地址
# End /etc/resolv.conf
EOF
#--------------------------------------------------------------------
# 建立fstab文件 注意:这里的磁盘名以及文件系统名需要根据实际情况修改。
#--------------------------------------------------------------------
# 这里按你格式化时候的选择,如果是 IDE硬盘,那么前面是 /dev/hda…. 如果是scsi硬盘就和我一样是sda
# 还有type 我这里是ext3,你按你自己的东西设置
cat > /etc/fstab << "EOF"
# Begin /etc/fstab
# file system mount-point type options dump fsck
# order
/dev/sda2 / ext3 defaults 1 1
/dev/sda1 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
#--------------------------------------------------------------------
# 安装内核Linux-2.6.22.5
#--------------------------------------------------------------------
cd /sources
tar xvf $LFS/linux-2.6.22.5.tar.bz2
cd linux-2.6.22.5
#安装显示UTF-8编码文字的补丁
#如果之前下载了UTF-8编码文字显示补丁,那么这里可以将这两个补丁打入内核
patch -Np1 -i $LFS/utf8-kernel-2.6.22.5-core-1.patch
patch -Np1 -i $LFS/utf8-kernel-2.6.22.5-fonts-1.patch
# 安装
make mrproper
make menuconfig
#在构建LFS的host系统上,运行lspci命令,列出机器的硬件信息
#在硬件信息中,查找 IDE interface 或 SATA Controller 或 SAS Controller 等关键字,得到到硬盘控制器的型号
#根据你的机器实际情况配置内核选项,这里为了说明方便,以VMWare7.1为基础虚拟的硬件来配置内核
#如果在建立虚拟机的时候是选择的BusLogic的SCSI磁盘,那么应该在Device Drivers->SCSI device support->SCSI low-level drivers下加入BusLogic SCSI support的支持,可以采用编译到内核来避免未用initrd脚本来加载模块而导致启动失败
#这里要注意,如果如果你用的是SCSI硬盘,那么你要选择去掉General setup -->Create deprecated sysfs files 前面的星
#在内核配置中,把对应的驱动程序编译到内核(不能编译成模块)。对 IDE硬盘,驱动程序在Device Drivers-->ATA/ATAPI/MFM/RLL配置项下找;对于 SATA硬盘,驱动程序在Device Driver-->SCSI device support-->SCSI low-level drivers配置项下找。
#如果想支持网络则应该在Device Drivers->Networking support->Ethernet (10 or 100Mbit)加入AMD PCnet32 PCI support的支持,可以采用编译到内核也可以编译成模块的方式
#如果想支持声卡则应该在Device Drivers->Sound->Advanced Linux Sound Architecture->PCI devices加入(Creative) Ensoniq AudioPCI 1371/1373的支持,编译成模块即可
#文件系统的支持,需要根据之前将目标系统分区格式化的情况而定,使用了什么文件系统就需要加入该文件系统的支持,因之前采用的是Xfs文件系统,因此在File Systems->XFS support加入XFS的支持,可以采用编译到内核来避免未用initrd脚本来加载模块而导致启动失败
#如果之前给内核加入了显示UTF-8编码文字的补丁的话,那么这里需要加入framebuffer的支持才能使补丁生效,在Device Drivers->Graphics support中加入Support for frame buffer devices,并选择上VESA VGA graphics supports,这里将其编译到内核中
#同时还需要加入framebuffer字体支持,在Device Drivers->Graphics support->Console display driver support中加入Framebuffer Console support并选择上Select compiled-in fonts,选上VGA 8x16 font这一种字体就可以了,这里将这些选择都编译到内核中
#---------------------------------------------------------------------
# 保存并退出
#---------------------------------------------------------------------
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
#---------------------------------------------------------------------
# 安装Grub,使系统能启动,这里设置需要根据情况而修改,这里以之前介绍的分区设置为例:
#---------------------------------------------------------------------
grub
root (hd0,1)
setup (hd0)
quit
#--------------------------------------------------------------------------------------------------------------------
# 设置 grub 菜单,这里也要注意了,最后第二句 root=/dev/sda2 如果你是IDE那么就是hda
#--------------------------------------------------------------------------------------------------------------------
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 LFS 6.3
root (hd0,1)
kernel /boot/lfskernel-2.6.22.5 root=/dev/sda2 vga=788
EOF
#--------------------------------------------------------------------------------------------------------------------
# 将menu.lst链接到 /etc
#--------------------------------------------------------------------------------------------------------------------
mkdir -v /etc/grub
ln -sv /boot/grub/menu.lst /etc/grub
# 退出
logout
# 重启
reboot
#-------------------------------------------------------------------------------------------------------------------------------------------------
后记:花了一个星期,终于完成了LFS,虽然原本也看了教程,但是我发现如果完整的按照教程做还是会出错的,我经过了几次的修改才最终完成了这样一个系统,感到非常有成就感,期间想过放弃,但是朋友的鼓励最终让我坚持到了最后,我非常非常开心,看着自己的LFS,现在看起来虽然功能很简单,但是她是我亲自花了很多时间做的,我做了很多次,一次一次的,直到开始怀疑自己的智力水平,呵呵,不过最终还是坚持到了最后,下面是我的LFS的截图,希望给在我后面的朋友以鼓励。