自动化构建LFS系统

来源: 作者:c-aries
  
春节在家制作多一次LFS,上次制作是一年前,也是寒假时分。
由于上手过,所以这次打算将“制作LFS系统的整个过程”写成bash脚本,以便以后快速构建系统。

LFS官网有个“自动化构建LFS系统”的项目,叫ALFS。其中官方推荐的ALFS程序有nALFS和jhalfs。
jhalfs的下载网址:
http://www.linuxfromscratch.org/alfs/downloads/jhalfs/stable/

暂时不用官网的jhalfs
Power By Myself
以后再研究jhalfs的代码也不迟,反正和GNU自由软件的缘分还长着呢,业余爱好 :)

自制的ALFS程序集(以下的README文件为使用说明):

自动化构建LFS系统


--------------------------------------------------------------------
[build-lfs目录结构]
--------------------------------------------------------------------
.
|-- README
|-- book-2010-02-24
|-- source
|   |-- get-source.sh
|   `-- url
`-- utils
    |-- build-lfs-pass-0-chroot.sh
    |-- build-lfs-pass-1.sh
    |-- build-lfs-pass-2-main.sh
    |-- build-lfs-pass-3-main.sh
    |-- build-lfs-pass-4-chroot.sh
    |-- build-lfs-pass-5.sh
    |-- build-lfs-pass-6-chroot.sh
    |-- build-lfs-pass-7.sh
    |-- build-lfs-pass-8-kernel.sh
    |-- build-lfs-pass-9.sh
    |-- build-temporary-system.sh
    |-- lfs.conf
    |-- lfs.lib
    |-- prepare-0.sh
    |-- prepare-1.sh
    `-- version-check.sh

2 directories, 20 files

--------------------------------------------------------------------
[./source/url]
--------------------------------------------------------------------
http://ftp.gnu.org/gnu/autoconf/autoconf-2.61.tar.bz2
http://ftp.gnu.org/gnu/automake/automake-1.10.tar.bz2
http://ftp.gnu.org/gnu/bash/bash-3.2.tar.gz
http://ftp.gnu.org/gnu/bash/bash-doc-3.2.tar.gz
http://download-east.oracle.com/berkeley-db/db-4.5.20.tar.gz
http://ftp.gnu.org/gnu/binutils/binutils-2.17.tar.bz2
http://ftp.gnu.org/gnu/bison/bison-2.3.tar.bz2
http://www.bzip.org/1.0.4/bzip2-1.0.4.tar.gz
http://ftp.gnu.org/gnu/coreutils/coreutils-6.9.tar.bz2
http://ftp.gnu.org/gnu/dejagnu/dejagnu-1.4.4.tar.gz
http://ftp.gnu.org/gnu/diffutils/diffutils-2.8.1.tar.gz
http://prdownloads.sourceforge.net/e2fsprogs/e2fsprogs-1.40.2.tar.gz
http://expect.nist.gov/src/expect-5.43.0.tar.gz
http://ftp.lfs-matrix.net/pub/lfs/conglomeration/file/file-4.21.tar.gz
http://ftp.gnu.org/gnu/findutils/findutils-4.2.31.tar.gz
http://prdownloads.sourceforge.net/flex/flex-2.5.33.tar.bz2
http://ftp.gnu.org/gnu/gawk/gawk-3.1.5.tar.bz2
http://ftp.gnu.org/gnu/gcc/gcc-4.1.2/gcc-4.1.2.tar.bz2
http://ftp.gnu.org/gnu/gettext/gettext-0.16.1.tar.gz
http://ftp.gnu.org/gnu/glibc/glibc-2.5.1.tar.bz2
http://ftp.gnu.org/gnu/glibc/glibc-libidn-2.5.1.tar.gz
http://ftp.gnu.org/gnu/grep/grep-2.5.1a.tar.bz2
http://ftp.gnu.org/gnu/groff/groff-1.18.1.4.tar.gz
ftp://alpha.gnu.org/gnu/grub/grub-0.97.tar.gz
http://ftp.gnu.org/gnu/gzip/gzip-1.3.12.tar.gz
http://www.sethwklein.net/projects/iana-etc/downloads/iana-etc-2.20.tar.bz2
http://ftp.gnu.org/gnu/inetutils/inetutils-1.5.tar.gz
http://developer.osdl.org/dev/iproute2/download/iproute2-2.6.20-070313.tar.gz
http://www.kernel.org/pub/linux/utils/kbd/kbd-1.12.tar.bz2
http://www.greenwoodsoftware.com/less/less-406.tar.gz
http://www.linuxfromscratch.org/lfs/downloads/6.3/lfs-bootscripts-6.3.tar.bz2
http://ftp.gnu.org/gnu/libtool/libtool-1.5.24.tar.gz
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.22.5.tar.bz2
http://ftp.gnu.org/gnu/m4/m4-1.4.10.tar.bz2
http://ftp.gnu.org/gnu/make/make-3.81.tar.bz2
http://savannah.nongnu.org/download/man-db/man-db-2.4.4.tar.gz
http://www.kernel.org/pub/linux/docs/manpages/Archive/man-pages-2.63.tar.bz2
http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/6.3/mktemp-1.5.tar.gz
http://www.kerneltools.org/pub/downloads/module-init-tools/module-init-tools-3.2.2.tar.bz2
http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/6.3/ncurses-5.6.tar.gz
http://ftp.gnu.org/gnu/patch/patch-2.5.4.tar.gz
http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/6.3/perl-5.8.8.tar.bz2
http://procps.sourceforge.net/procps-3.2.7.tar.gz
http://prdownloads.sourceforge.net/psmisc/psmisc-22.5.tar.gz
http://ftp.gnu.org/gnu/readline/readline-5.2.tar.gz
http://ftp.gnu.org/gnu/sed/sed-4.1.5.tar.gz
http://anduin.linuxfromscratch.org/sources/LFS/lfs-packages/6.3/shadow-4.0.18.1.tar.bz2
http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.4.1.tar.gz
ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/sysvinit-2.86.tar.gz
http://ftp.gnu.org/gnu/tar/tar-1.18.tar.bz2
http://prdownloads.sourceforge.net/tcl/tcl8.4.15-src.tar.gz
http://ftp.gnu.org/gnu/texinfo/texinfo-4.9.tar.bz2
http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-113.tar.bz2
http://www.linuxfromscratch.org/lfs/downloads/6.3/udev-config-6.3.tar.bz2
http://www.kernel.org/pub/linux/utils/util-linux/util-linux-2.12r.tar.bz2
ftp://ftp.vim.org/pub/vim/unix/vim-7.1.tar.bz2
ftp://ftp.vim.org/pub/vim/extra/vim-7.1-lang.tar.gz
http://www.zlib.net/zlib-1.2.3.tar.gz
http://www.linuxfromscratch.org/patches/lfs/6.3/bash-3.2-fixes-5.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/bzip2-1.0.4-install_docs-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/coreutils-6.9-i18n-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/coreutils-6.9-suppress_uptime_kill_su-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/coreutils-6.9-uname-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/db-4.5.20-fixes-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/diffutils-2.8.1-i18n-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/expect-5.43.0-spawn-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/gawk-3.1.5-segfault_fix-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/gcc-4.1.2-specs-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/grep-2.5.1a-redhat_fixes-2.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/groff-1.18.1.4-debian_fixes-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/grub-0.97-disk_geometry-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/inetutils-1.5-no_server_man_pages-2.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/kbd-1.12-backspace-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/kbd-1.12-gcc4_fixes-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/man-db-2.4.4-fixes-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/mktemp-1.5-add_tempfile-3.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/module-init-tools-3.2.2-modprobe-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/ncurses-5.6-coverity_fixes-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/perl-5.8.8-libc-2.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/readline-5.2-fixes-3.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/shadow-4.0.18.1-useradd_fix-2.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/sysklogd-1.4.1-8bit-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/sysklogd-1.4.1-fixes-2.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/texinfo-4.9-multibyte-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/texinfo-4.9-tempfile_fix-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/util-linux-2.12r-cramfs-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/util-linux-2.12r-lseek-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/vim-7.1-fixes-1.patch
http://www.linuxfromscratch.org/patches/lfs/6.3/vim-7.1-mandir-1.patch

--------------------------------------------------------------------
[./source/get-source.sh]
--------------------------------------------------------------------
#! /bin/sh

#change
URL=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/6.3/

wget -c ${URL}/MD5SUMS

echo "************"
echo "缺失的文件列表:"
for name in `cat url`
do
    file_name=`basename $name`
    if [ ! -e $file_name ] ; then
    echo $file_name
    wget -c $URL/$file_name
    fi
done
echo "************"

--------------------------------------------------------------------
[./README]
--------------------------------------------------------------------
--- utils文件夹

[1]. 测试宿主机的软件版本
version-check.sh

[2]. 制作LFS临时系统
prepare-0.sh
prepare-1.sh
build-temporary-system.sh

[3]. 制作目标LFS系统
build-lfs-pass-0-chroot.sh
build-lfs-pass-1.sh
build-lfs-pass-2-main.sh
build-lfs-pass-3-main.sh
build-lfs-pass-4-chroot.sh
build-lfs-pass-5.sh
build-lfs-pass-6-chroot.sh
build-lfs-pass-7.sh
build-lfs-pass-8-kernel.sh
build-lfs-pass-9.sh

[4]. 配置文件与函数库
lfs.conf
lfs.lib

LFS的制作过程为[2] -> [3],按以上列出的顺序运行脚本

--- source文件夹

[1]. 制作LFS所需要的所有源代码包
url
注: 使用方法"运行以下命令"
$ wget -c -i url

[2]. url有的文件无法下载时,运行以下脚本获得缺失文件
get-source.sh

--- 附加说明

本版本程序集,使用对象为LFS6.3
测试平台为Debian5.0.2
LFS6.3电子书下载网址:
http://www.linuxfromscratch.org/lfs/downloads/6.3/LFS-BOOK-6.3-HTML.tar.bz2

--------------------------------------------------------------------
[./utils/build-temporary-system.sh]
--------------------------------------------------------------------
#! /bin/sh

source lfs.conf
source lfs.lib

check_lfs

build_binutils()
{
    #检测
    cd $LFS/sources

    check_file binutils-2.17.tar.bz2
    check_dir binutils-2.17
    check_dir binutils-build

    #解压
    tar jxvf binutils-2.17.tar.bz2
    cd binutils-2.17

    before_date=`date -R`

    #编译
    mkdir -v ../binutils-build
    cd ../binutils-build
    CC="gcc -B/usr/bin/" ../binutils-2.17/configure \
    --prefix=/tools --disable-nls --disable-werror
    make || eval "echo \"error: make error in binutils\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    make -C ld clean
    make -C ld LIB_PATH=/tools/lib
    cp -v ld/ld-new /tools/bin

    #清理
    cd $LFS/sources/
    rm -f -R binutils-2.17
    rm -f -R binutils-build
}

build_gcc()
{
    #检测
    cd $LFS/sources

    check_file gcc-4.1.2.tar.bz2
    check_dir gcc-4.1.2
    check_dir gcc-build

    #解压
    tar jxvf gcc-4.1.2.tar.bz2
    cd gcc-4.1.2

    before_date=`date -R`

    #编译
    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 || eval "echo \"error: make error in gcc\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R gcc-4.1.2
    rm -f -R gcc-build

    #特殊
    ln -vs gcc /tools/bin/cc
}

build_linux_api_headers()
{
    #检测
    cd $LFS/sources

    check_file linux-2.6.22.5.tar.bz2
    check_dir linux-2.6.22.5

    #解压
    tar jxvf linux-2.6.22.5.tar.bz2
    cd linux-2.6.22.5

    before_date=`date -R`

    #编译
    make mrproper
    make headers_check
    make INSTALL_HDR_PATH=dest headers_install
    cp -rv dest/include/* /tools/include

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R linux-2.6.22.5
}

build_glibc()
{
    #检测
    cd $LFS/sources

    check_file glibc-2.5.1.tar.bz2
    check_dir glibc-2.5.1
    check_dir glibc-build

    #解压
    tar jxvf glibc-2.5.1.tar.bz2
    cd glibc-2.5.1

    before_date=`date -R`

    #编译
    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 || eval "echo \"error: make error in glibc\" && exit 1"
    mkdir -pv /tools/etc
    touch /tools/etc/ld.so.conf
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R glibc-2.5.1
    rm -f -R glibc-build
}

adjust_toolchain()
{
    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'
    #read input
    rm -v dummy.c a.out
}

build_tcl()
{
    #检测
    cd $LFS/sources

    check_file tcl8.4.15-src.tar.gz
    check_dir tcl8.4.15

    #解压
    tar zxvf tcl8.4.15-src.tar.gz
    cd tcl8.4.15

    before_date=`date -R`

    #编译
    cd unix
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in tcl\" && exit 1"
    make install && make install-private-headers

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    ln -sv tclsh8.4 /tools/bin/tclsh

    #清理
    cd $LFS/sources/
    rm -f -R tcl8.4.15
}

build_expect()
{
    #检测
    cd $LFS/sources

    check_file expect-5.43.0.tar.gz
    check_file expect-5.43.0-spawn-1.patch
    check_dir expect-5.43

    #解压
    tar zxvf expect-5.43.0.tar.gz
    cd expect-5.43

    #特殊
    patch -Np1 -i ../expect-5.43.0-spawn-1.patch
    cp configure{,.bak}
    sed 's:/usr/local/bin:/bin:' configure.bak > configure

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools --with-tcl=/tools/lib \
    --with-tclinclude=/tools/include --with-x=no
    make || eval "echo \"error: make error in expect\" && exit 1"
    make scriptS="" install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R expect-5.43
}

build_dejagnu()
{
    #检测
    cd $LFS/sources

    check_file dejagnu-1.4.4.tar.gz
    check_dir dejagnu-1.4.4

    #解压
    tar zxvf dejagnu-1.4.4.tar.gz
    cd dejagnu-1.4.4

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools && \
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R dejagnu-1.4.4
}

build_gcc_pass2()
{
    #测试
    expect -c "spawn ls"
    #read input

    #检测
    cd $LFS/sources

    check_file gcc-4.1.2.tar.bz2
    check_file gcc-4.1.2-specs-1.patch
    check_dir gcc-4.1.2
    check_dir gcc-build

    #解压
    tar jxvf 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 ../gcc-4.1.2-specs-1.patch

    before_date=`date -R`

    #编译
    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 || eval "echo \"error: make error in gcc pass2\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R gcc-4.1.2
    rm -f -R gcc-build

    #测试
    echo 'main(){}' > dummy.c
    cc dummy.c
    readelf -l a.out | grep ': /tools'
    #read input
    rm -v dummy.c a.out
}

build_binutils_pass2()
{
    #检测
    cd $LFS/sources

    check_file binutils-2.17.tar.bz2
    check_dir binutils-2.17
    check_dir binutils-build

    #解压
    tar jxvf binutils-2.17.tar.bz2
    cd binutils-2.17

    before_date=`date -R`

    #编译
    mkdir -v ../binutils-build
    cd ../binutils-build
    ../binutils-2.17/configure --prefix=/tools \
    --disable-nls --with-lib-path=/tools/lib
    make || eval "echo \"error: make error in binutils pass2\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    make -C ld clean
    make -C ld LIB_PATH=/usr/lib:/lib
    cp -v ld/ld-new /tools/bin

    #清理
    cd $LFS/sources/
    rm -f -R binutils-2.17
    rm -f -R binutils-build
}

build_ncurses()
{
    #检测
    cd $LFS/sources

    check_file ncurses-5.6.tar.gz
    check_dir ncurses-5.6

    #解压
    tar zxvf ncurses-5.6.tar.gz
    cd ncurses-5.6

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools --with-shared \
    --without-debug --without-ada --enable-overwrite
    make || eval "echo \"error: make error in ncurses\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R ncurses-5.6
}

build_bash()
{
    #检测
    cd $LFS/sources

    check_file bash-3.2.tar.gz
    check_file bash-3.2-fixes-5.patch
    check_dir bash-3.2

    #解压
    tar zxvf bash-3.2.tar.gz
    cd bash-3.2

    #打补丁
    patch -Np1 -i ../bash-3.2-fixes-5.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools --without-bash-malloc
    make || eval "echo \"error: make error in bash\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    ln -vs bash /tools/bin/sh

    #清理
    cd $LFS/sources/
    rm -f -R bash-3.2
}

build_bzip2()
{
    #检测
    cd $LFS/sources

    check_file bzip2-1.0.4.tar.gz
    check_dir bzip2-1.0.4

    #解压
    tar zxvf bzip2-1.0.4.tar.gz
    cd bzip2-1.0.4

    before_date=`date -R`

    #编译
    make || eval "echo \"error: make error in bzip2\" && exit 1"
    make PREFIX=/tools install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R bzip2-1.0.4
}

build_coreutils()
{
    #检测
    cd $LFS/sources

    check_file coreutils-6.9.tar.bz2
    check_dir coreutils-6.9

    #解压
    tar jxvf coreutils-6.9.tar.bz2
    cd coreutils-6.9

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in coreutils\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    cp -v src/su /tools/bin/su-tools

    #清理
    cd $LFS/sources/
    rm -f -R coreutils-6.9
}

build_diffutils()
{
    #检测
    cd $LFS/sources

    check_file diffutils-2.8.1.tar.gz
    check_dir diffutils-2.8.1

    #解压
    tar zxvf diffutils-2.8.1.tar.gz
    cd diffutils-2.8.1

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in diffutils\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R diffutils-2.8.1
}

build_findutils()
{
    #检测
    cd $LFS/sources

    check_file findutils-4.2.31.tar.gz
    check_dir findutils-4.2.31

    #解压
    tar zxvf findutils-4.2.31.tar.gz
    cd findutils-4.2.31

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in findutils\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R findutils-4.2.31
}

build_gawk()
{
    #检测
    cd $LFS/sources

    check_file gawk-3.1.5.tar.bz2
    check_dir gawk-3.1.5

    #解压
    tar jxvf gawk-3.1.5.tar.bz2
    cd gawk-3.1.5

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    cat >> config.h << "EOF"
#define HAVE_LANGINFO_CODESET 1
#define HAVE_LC_MESSAGES 1
EOF
    make || eval "echo \"error: make error in gawk\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R gawk-3.1.5
}

build_gettext()
{
    #检测
    cd $LFS/sources

    check_file gettext-0.16.1.tar.gz
    check_dir gettext-0.16.1

    #解压
    tar zxvf gettext-0.16.1.tar.gz
    cd gettext-0.16.1

    before_date=`date -R`

    #编译
    cd gettext-tools
    ./configure --prefix=/tools --disable-shared
    make -C gnulib-lib
    make -C src msgfmt
    cp -v src/msgfmt /tools/bin

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R gettext-0.16.1
}

build_grep()
{
    #检测
    cd $LFS/sources

    check_file grep-2.5.1a.tar.bz2
    check_dir grep-2.5.1a

    #解压
    tar jxvf grep-2.5.1a.tar.bz2
    cd grep-2.5.1a

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools \
    --disable-perl-regexp
    make || eval "echo \"error: make error in grep\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R grep-2.5.1a
}

build_gzip()
{
    #检测
    cd $LFS/sources

    check_file gzip-1.3.12.tar.gz
    check_dir gzip-1.3.12

    #解压
    tar zxvf gzip-1.3.12.tar.gz
    cd gzip-1.3.12

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in gzip\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R gzip-1.3.12
}

build_make()
{
    #检测
    cd $LFS/sources

    check_file make-3.81.tar.bz2
    check_dir make-3.81

    #解压
    tar jxvf make-3.81.tar.bz2
    cd make-3.81

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in make\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R make-3.81
}

build_patch()
{
    #检测
    cd $LFS/sources

    check_file patch-2.5.4.tar.gz
    check_dir patch-2.5.4

    #解压
    tar zxvf patch-2.5.4.tar.gz
    cd patch-2.5.4

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in patch\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R patch-2.5.4
}

build_perl()
{
    #检测
    cd $LFS/sources

    check_file perl-5.8.8.tar.bz2
    check_file perl-5.8.8-libc-2.patch
    check_dir perl-5.8.8

    #解压
    tar jxvf perl-5.8.8.tar.bz2
    cd perl-5.8.8

    #打补丁
    patch -Np1 -i ../perl-5.8.8-libc-2.patch

    before_date=`date -R`

    #编译
    ./configure.gnu --prefix=/tools -Dstatic_ext='Data/Dumper Fcntl IO POSIX'
    make perl utilities || eval "echo \"error: make error in perl\" && exit 1"
    cp -v perl pod/pod2man /tools/bin
    mkdir -pv /tools/lib/perl5/5.8.8
    cp -Rv lib/* /tools/lib/perl5/5.8.8

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R perl-5.8.8
}

build_sed()
{
    #检测
    cd $LFS/sources

    check_file sed-4.1.5.tar.gz
    check_dir sed-4.1.5

    #解压
    tar zxvf sed-4.1.5.tar.gz
    cd sed-4.1.5

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in sed\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R sed-4.1.5
}

build_tar()
{
    #检测
    cd $LFS/sources

    check_file tar-1.18.tar.bz2
    check_dir tar-1.18

    #解压
    tar jxvf tar-1.18.tar.bz2
    cd tar-1.18

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in tar\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R tar-1.18
}

build_texinfo()
{
    #检测
    cd $LFS/sources

    check_file texinfo-4.9.tar.bz2
    check_dir texinfo-4.9

    #解压
    tar jxvf texinfo-4.9.tar.bz2
    cd texinfo-4.9

    before_date=`date -R`

    #编译
    ./configure --prefix=/tools
    make || eval "echo \"error: make error in texinfo\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R texinfo-4.9
}

build_util_linux()
{
    #检测
    cd $LFS/sources

    check_file util-linux-2.12r.tar.bz2
    check_dir util-linux-2.12r

    #解压
    tar jxvf util-linux-2.12r.tar.bz2
    cd util-linux-2.12r

    #特殊
    sed -i 's@/usr/include@/tools/include@g' configure

    before_date=`date -R`

    #编译
    ./configure
    make -C lib
    make -C mount mount umount
    make -C text-utils more
    cp -v mount/{,u}mount text-utils/more /tools/bin

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd $LFS/sources/
    rm -f -R util-linux-2.12r
}

stripping()
{
    strip --strip-debug /tools/lib/*
    strip --strip-unneeded /tools/{,s}bin/*
    rm -rf /tools/{info,man}
}

logout_comment()
{
    echo "****************"
    echo "now exit from user lfs and type commonds below"
    echo
    echo "$ exit"
    echo
    echo "# export LFS=$LFS"
    echo "# chown -R root:root \$LFS/tools"
    echo
    echo "you can backup $LFS/tools for reuse"
    echo "****************"
}

if [ ! -e $LFS/sources ] ; then
    echo "error: $LFS/sources don't exist"
    exit 1
fi

before_date_sum=`date -R`

build_binutils
build_gcc
build_linux_api_headers
build_glibc
adjust_toolchain
build_tcl
build_expect
build_dejagnu
build_gcc_pass2
build_binutils_pass2
build_ncurses
build_bash
build_bzip2
build_coreutils
build_diffutils
build_findutils
build_gawk
build_gettext
build_grep
build_gzip
build_make
build_patch
build_perl
build_sed
build_tar
build_texinfo
build_util_linux
stripping

#计时
after_date_sum=`date -R`
echo "$before_date_sum"
echo "$after_date_sum"

logout_comment

--------------------------------------------------------------------
[./utils/build-lfs-pass-8-kernel.sh]
--------------------------------------------------------------------
#! /bin/sh

unset LFS
source lfs.lib

check_root

pass6_warning

configure_fstab()
{
    cat > /etc/fstab << "EOF"
# Begin /etc/fstab

# file system  mount-point  type   options         dump  fsck
#                                                        order

/dev/sda9     /            ext3  defaults        1     1
/dev/sda3     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
}

build_linux()
{
    #检测
    cd /sources
    check_file linux-2.6.22.5.tar.bz2
    check_dir linux-2.6.22.5

    #解压
    tar jxvf linux-2.6.22.5.tar.bz2
    cd linux-2.6.22.5

    before_date=`date -R`

    #编译
    make mrproper
    echo "wanna to run 'make menuconfig' ? (y/[n])"
    echo "if you press 'n', you should copy your own .config to `pwd`"
    read -s -n 1 -t 20 input
    if [ "$input" = "y" -o "$input" = "Y" ] ; then
    make menuconfig
    else
    if [ ! -e .config ] ; then
        echo "error: .config doesn't exist"
        exit 1
    fi
    fi
    make || eval "echo \"error: make error in linux\" && exit 1"
    make modules_install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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

    #清理
    cd /sources/
    rm -f -R linux-2.6.22.5
}

configure_grub()
{
    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 2

# Use prettier colors.
color green/black light-green/black

# The first entry is for LFS.
title LFS 6.3
root (hd0,8)
kernel /boot/lfskernel-2.6.22.5 root=/dev/sda9
EOF
    mkdir -pv /etc/grub
    ln -sv /boot/grub/menu.lst /etc/grub
}

configure_lfs()
{
    echo 6.3 > /etc/lfs-release
}

logout_comment()
{
    echo "******** warning ********"
    echo "please edit /etc/fstab by yourself"
    echo "please edit /boot/grub/menu.lst by yourself"
    echo "then login as root, run the following commands to setup grub"
    echo "这里的命令很危险!请修改grub> 下的命令参数"
    echo "hd0,8 指第1块磁盘,第9个分区"
    echo
    echo "示例:"
    echo "# grub"
    echo "grub> root (hd0,8)"
    echo "grub> setup (hd0)"
    echo "grub> quit"
    echo "# logout"
    echo
    echo "the logout from chroot enviroment"
    echo "******** warning ********"
}

configure_fstab
build_linux
configure_grub
configure_lfs

logout_comment

--------------------------------------------------------------------
[./utils/lfs.lib]
--------------------------------------------------------------------
check_root()
{
    myid=$(id -u)
    if [ $myid -ne 0 ] ; then
    echo "error: only root can run this program" >&2
    exit 1
    fi
}

check_lfs()
{
    myid=$(id -urn)
    if [ $myid != "lfs" ] ; then
    echo "error: only lfs can run this program" >&2
    exit 1
    fi
}

check_file()
{
    if [ ! -e $LFS/sources/$1 ] ; then
    echo "error: $LFS/sources/$1 doesn't exist"
    exit 1
    fi
}

check_dir()
{
    if [ -e $LFS/sources/$1 ] ; then
    rm -f -R $LFS/sources/$1
    echo "删除旧文件夹 $1"
    fi
}

pass0_warning()
{
    echo "******* warning *********"
    echo "这个脚本很危险!请先运行build-lfs-pass-0-chroot.sh"
    echo "在确保运行了chroot后再运行该脚本!"
    echo "******* warning *********"
    echo
    echo "如确认无误,要运行该脚本,请输入:"
    echo "GNU & LFS"
    read input
    if [ "$input" != "GNU & LFS" ] ; then
    echo "输入错误,程序中断运行!"
    exit 0
    fi
}

pass4_warning()
{
    echo "******* warning *********"
    echo "这个脚本很危险!请先运行build-lfs-pass-4-chroot.sh"
    echo "在确保运行了chroot后再运行该脚本!"
    echo "******* warning *********"
    echo
    echo "如确认无误,要运行该脚本,请输入:"
    echo "GNU & LFS"
    read input
    if [ "$input" != "GNU & LFS" ] ; then
    echo "输入错误,程序中断运行!"
    exit 0
    fi
}

pass6_warning()
{
    echo "******* warning *********"
    echo "这个脚本很危险!请先运行build-lfs-pass-6-chroot.sh"
    echo "在确保运行了chroot后再运行该脚本!"
    echo "******* warning *********"
    echo
    echo "如确认无误,要运行该脚本,请输入:"
    echo "GNU & LFS"
    read input
    if [ "$input" != "GNU & LFS" ] ; then
    echo "输入错误,程序中断运行!"
    exit 0
    fi
}

logout_from_chroot_warning()
{
    echo "******* warning *********"
    echo "如果现在是在chroot环境中"
    echo "请确保运行了logout后再运行该脚本!"
    echo "******* warning *********"
    echo
    echo "如确认无误,要运行该脚本,请输入:"
    echo "GNU & LFS"
    read input
    if [ "$input" != "GNU & LFS" ] ; then
    echo "输入错误,程序中断运行!"
    exit 0
    fi
}

--------------------------------------------------------------------
[./utils/prepare-1.sh]
--------------------------------------------------------------------
#! /bin/sh

source lfs.conf
source lfs.lib

check_lfs

cat > ~/.bash_profile <<EOF
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF

#change
cat > ~/.bashrc <<EOF
set +h
umask 022
LFS=/media/exp
LC_ALL=POSIX
PATH=/tools/bin:/bin:/usr/bin
export LFS LC_ALL PATH
EOF

source ~/.bash_profile

--------------------------------------------------------------------
[./utils/lfs.conf]
--------------------------------------------------------------------
#LFS为 LFS System 的根文件系统
export LFS=/media/exp

--------------------------------------------------------------------
[./utils/build-lfs-pass-6-chroot.sh]
--------------------------------------------------------------------
#! /bin/sh

source lfs.conf
source lfs.lib

check_root

logout_from_chroot_warning

virtual_file_system()
{
    mkdir -pv $LFS/{dev,proc,sys}

    if [ ! -e $LFS/dev/console ] ; then
    mknod -m 600 $LFS/dev/console c 5 1
    fi

    if [ ! -e $LFS/dev/null ] ; then
    mknod -m 666 $LFS/dev/null c 1 3
    fi

    mount | grep -q "/dev on $LFS/dev "
    if [ $? -ne 0 ] ; then
    mount -v --bind /dev $LFS/dev
    fi

    mount | grep -q "devpts on $LFS/dev/pts "
    if [ $? -ne 0 ] ; then
    mount -vt devpts devpts $LFS/dev/pts
    fi

    mount | grep -q "shm on $LFS/dev/shm "
    if [ $? -ne 0 ] ; then
    mount -vt tmpfs shm $LFS/dev/shm
    fi

    mount | grep -q "proc on $LFS/proc "
    if [ $? -ne 0 ] ; then
    mount -vt proc proc $LFS/proc
    fi

    mount | grep -q "sysfs on $LFS/sys "
    if [ $? -ne 0 ] ; then
    mount -vt sysfs sysfs $LFS/sys
    fi
}

chroot_comment()
{
    echo "****************"
    echo "now login as root, then run the fllowing commands"
    echo
    echo "# export LFS=$LFS"
    echo "# chroot \"\$LFS\" /usr/bin/env -i  \\
    HOME=/root TERM=\"\$TERM\" PS1='\\u:\\w\\$ ' \\
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \\
    /bin/bash --login"
    echo
    echo "you can delete $LFS/tools now"
    echo "****************"
}

if [ ! -e $LFS/sources ] ; then
    echo "error: $LFS/sources don't exist"
    exit 1
fi

virtual_file_system
chroot_comment

--------------------------------------------------------------------
[./utils/version-check.sh]
--------------------------------------------------------------------
#! /bin/sh

export LC_ALL=C

bash --version | head -n 1 | cut -d " " -f 2-4
echo "/bin/sh -> `readlink -f /bin/sh`"
echo -n "Binutils: "
ld --version | head -n 1 | cut -d " " -f 3-
bison --version | head -n 1
if [ -e /usr/bin/yacc ] ; then
    echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`"
else
    echo "yacc not found"
fi
bzip2 --version 2>&1 < /dev/null | head -n 1 | cut -d " " -f 1,6-
echo -n "Coreutils: "
chown --version | head -n 1 | cut -d ")" -f 2
diff --version | head -n 1
find --version | head -n 1
gawk --version | head -n 1
if [ -e /usr/bin/awk ] ; then
    echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`"
else
    echo "awk not found"
fi
gcc --version | head -n 1
/lib/libc.so.6 | head -n 1 | cut -d " " -f 1-7
grep --version | head -n 1
gzip --version | head -n 1
cat /proc/version
m4 --version | head -n 1
make --version | head -n 1
patch --version | head -n 1
echo Perl `perl -V:version`
sed --version | head -n 1
tar --version | head -n 1
makeinfo --version | head -n 1
echo "main(){}" > dummy.c && gcc -o dummy dummy.c
if [ -x dummy ] ; then
    echo "Compilation OK"
else
    echo "Compilation failed"
fi
rm -f dummy.c dummy

--------------------------------------------------------------------
[./utils/build-lfs-pass-0-chroot.sh]
--------------------------------------------------------------------
#! /bin/sh

source lfs.conf
source lfs.lib

check_root

virtual_file_system()
{
    mkdir -pv $LFS/{dev,proc,sys}

    if [ ! -e $LFS/dev/console ] ; then
    mknod -m 600 $LFS/dev/console c 5 1
    fi

    if [ ! -e $LFS/dev/null ] ; then
    mknod -m 666 $LFS/dev/null c 1 3
    fi

    mount | grep -q "/dev on $LFS/dev "
    if [ $? -ne 0 ] ; then
    mount -v --bind /dev $LFS/dev
    fi

    mount | grep -q "devpts on $LFS/dev/pts "
    if [ $? -ne 0 ] ; then
    mount -vt devpts devpts $LFS/dev/pts
    fi

    mount | grep -q "shm on $LFS/dev/shm "
    if [ $? -ne 0 ] ; then
    mount -vt tmpfs shm $LFS/dev/shm
    fi

    mount | grep -q "proc on $LFS/proc "
    if [ $? -ne 0 ] ; then
    mount -vt proc proc $LFS/proc
    fi

    mount | grep -q "sysfs on $LFS/sys "
    if [ $? -ne 0 ] ; then
    mount -vt sysfs sysfs $LFS/sys
    fi
}

chroot_comment()
{
    echo "****************"
    echo "now login as root, then run the fllowing commands"
    echo
    echo "# export LFS=$LFS"
    echo "# 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"
    echo
    echo "****************"
}

if [ ! -e $LFS/sources ] ; then
    echo "error: $LFS/sources don't exist"
    exit 1
fi

virtual_file_system
chroot_comment

--------------------------------------------------------------------
[./utils/build-lfs-pass-2-main.sh]
--------------------------------------------------------------------
#! /bin/sh

unset LFS
source lfs.lib

check_root

pass0_warning

essential_file()
{
    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
}

build_linux_api_headers()
{
    #检测
    cd /sources

    check_file linux-2.6.22.5.tar.bz2
    check_dir linux-2.6.22.5

    #解压
    tar jxvf linux-2.6.22.5.tar.bz2
    cd linux-2.6.22.5

    #特殊
    sed -i '/scsi/d' include/Kbuild

    before_date=`date -R`

    #编译
    make mrproper
    make headers_check
    make INSTALL_HDR_PATH=dest headers_install
    cp -rv dest/include/* /usr/include

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R linux-2.6.22.5
}

build_man_pages()
{
    #检测
    cd /sources

    check_file man-pages-2.63.tar.bz2
    check_dir man-pages-2.63

    #解压
    tar jxvf man-pages-2.63.tar.bz2
    cd man-pages-2.63

    before_date=`date -R`

    #编译
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R man-pages-2.63
}

build_glibc()
{
    #检测
    cd /sources

    check_file glibc-2.5.1.tar.bz2
    check_file glibc-libidn-2.5.1.tar.gz
    check_dir glibc-2.5.1
    check_dir glibc-build

    #解压
    tar jxvf glibc-2.5.1.tar.bz2
    cd glibc-2.5.1
    tar zxvf ../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

    before_date=`date -R`

    #编译
    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 || eval "echo \"error: make error in glibc\" && exit 1"
#    make -k check 2>&1 | tee glibc-check-log
#    grep Error glibc-check-log
#    echo "glibc check done, please press enter"
#    read input

    touch /etc/ld.so.conf
    make install

    #国际化,这里全部安装
    make localedata/install-locales

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #配置
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"
# Begin /etc/ld.so.conf

/usr/local/lib
/opt/lib

# End /etc/ld.so.conf
EOF

    #清理
    cd /sources/
    rm -f -R glibc-2.5.1
    rm -f -R glibc-build
}

adjust_toolchain()
{
    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 \
    -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'

    grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log
    grep -B1 '^ /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

#read input

    rm -v dummy.c a.out
}

build_binutils()
{
    #检测
    cd /sources

    check_file binutils-2.17.tar.bz2
    check_dir binutils-2.17
    check_dir binutils-build

    #测试
    expect -c "spawn ls"
#    read input

    #解压
    tar jxvf binutils-2.17.tar.bz2
    cd binutils-2.17

    before_date=`date -R`

    #编译
    mkdir -v ../binutils-build
    cd ../binutils-build
    ../binutils-2.17/configure --prefix=/usr \
    --enable-shared
    make tooldir=/usr || eval "echo \"error: make error in binutils\" && exit 1"
#    make check
    make tooldir=/usr install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    cp -v ../binutils-2.17/include/libiberty.h /usr/include

    #清理
    cd /sources/
    rm -f -R binutils-2.17
    rm -f -R binutils-build
}

build_gcc()
{
    #检测
    cd /sources

    check_file gcc-4.1.2.tar.bz2
    check_dir gcc-4.1.2
    check_dir gcc-build

    #解压
    tar jxvf 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

    before_date=`date -R`

    #编译
    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 || eval "echo \"error: make error in gcc\" && exit 1"
#    make -k check
#    ../gcc-4.1.2/contrib/test_summary
#    echo "check done, please press enter to continue"
#    read input
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    ln -sv ../usr/bin/cpp /lib
    ln -sv gcc /usr/bin/cc

    #测试
    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
#    echo "check log done, please press enter to continue"
#    read input
    rm -f -v dummy.c a.out dummy.log

    #清理
    cd /sources/
    rm -f -R gcc-4.1.2
    rm -f -R gcc-build
}

build_db()
{
    #检测
    cd /sources

    check_file db-4.5.20.tar.gz
    check_file db-4.5.20-fixes-1.patch
    check_dir db-4.5.20

    #解压
    tar zxvf db-4.5.20.tar.gz
    cd db-4.5.20

    #打补丁
    patch -Np1 -i ../db-4.5.20-fixes-1.patch

    before_date=`date -R`

    #编译
    cd build_unix
    ../dist/configure --prefix=/usr --enable-compat185 --enable-cxx
    make || eval "echo \"error: make error in db\" && exit 1"
    make docdir=/usr/share/doc/db-4.5.20 install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    chown -Rv root:root /usr/share/doc/db-4.5.20

    #清理
    cd /sources/
    rm -f -R db-4.5.20
}

build_sed()
{
    #检测
    cd /sources

    check_file sed-4.1.5.tar.gz
    check_dir sed-4.1.5

    #解压
    tar zxvf sed-4.1.5.tar.gz
    cd sed-4.1.5

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --bindir=/bin --enable-html
    make || eval "echo \"error: make error in sed\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R sed-4.1.5
}

build_e2fsprogs()
{
    #检测
    cd /sources

    check_file e2fsprogs-1.40.2.tar.gz
    check_dir e2fsprogs-1.40.2

    #解压
    tar zxvf e2fsprogs-1.40.2.tar.gz
    cd e2fsprogs-1.40.2

    #特殊
    sed -i -e 's@/bin/rm@/tools&@' lib/blkid/test_probe.in

    before_date=`date -R`

    #编译
    mkdir -v build
    cd build
    ../configure --prefix=/usr --with-root-prefix="" \
    --enable-elf-shlibs
    make || eval "echo \"error: make error in e2fsprogs\" && exit 1"
    make install
    make install-libs

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R e2fsprogs-1.40.2
}

build_coreutils()
{
    #检测
    cd /sources

    check_file coreutils-6.9.tar.bz2
    check_file coreutils-6.9-uname-1.patch
    check_file coreutils-6.9-suppress_uptime_kill_su-1.patch
    check_file coreutils-6.9-i18n-1.patch
    check_dir coreutils-6.9

    #解压
    tar jxvf coreutils-6.9.tar.bz2
    cd coreutils-6.9

    before_date=`date -R`

    #打补丁
    patch -Np1 -i ../coreutils-6.9-uname-1.patch
    patch -Np1 -i ../coreutils-6.9-suppress_uptime_kill_su-1.patch
    patch -Np1 -i ../coreutils-6.9-i18n-1.patch

    #特殊
    chmod +x tests/sort/sort-mb-tests

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in coreutils\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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 /sources/
    rm -f -R coreutils-6.9
}

build_iana_etc()
{
    #检测
    cd /sources

    check_file iana-etc-2.20.tar.bz2
    check_dir iana-etc-2.20

    #解压
    tar jxvf iana-etc-2.20.tar.bz2
    cd iana-etc-2.20

    before_date=`date -R`

    #编译
    make || eval "echo \"error: make error in iana-etc\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R iana-etc-2.20
}

build_m4()
{
    #检测
    cd /sources

    check_file m4-1.4.10.tar.bz2
    check_dir m4-1.4.10

    #解压   
    tar jxvf m4-1.4.10.tar.bz2
    cd m4-1.4.10

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in m4\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R m4-1.4.10
}

build_bison()
{
    #检测
    cd /sources

    check_file bison-2.3.tar.bz2
    check_dir bison-2.3

    #解压   
    tar jxvf bison-2.3.tar.bz2
    cd bison-2.3

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    echo '#define YYENABLE_NLS 1' >> config.h
    make || eval "echo \"error: make error in bison\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R bison-2.3
}

build_ncurses()
{
    #检测
    cd /sources

    check_file ncurses-5.6.tar.gz
    check_file ncurses-5.6-coverity_fixes-1.patch
    check_dir ncurses-5.6

    #打补丁
    patch -Np1 -i ../ncurses-5.6-coverity_fixes-1.patch

    #解压
    tar zxvf ncurses-5.6.tar.gz
    cd ncurses-5.6

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --with-shared --without-debug --enable-widec
    make || eval "echo \"error: make error in ncurses\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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 /sources/
    rm -f -R ncurses-5.6
}

build_procps()
{
    #检测
    cd /sources

    check_file procps-3.2.7.tar.gz
    check_dir procps-3.2.7

    #解压   
    tar zxvf procps-3.2.7.tar.gz
    cd procps-3.2.7

    before_date=`date -R`

    #编译
    make || eval "echo \"error: make error in procps\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R procps-3.2.7
}

build_libtool()
{
    #检测
    cd /sources

    check_file libtool-1.5.24.tar.gz
    check_dir libtool-1.5.24

    #解压   
    tar zxvf libtool-1.5.24.tar.gz
    cd libtool-1.5.24

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in libtool\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R libtool-1.5.24
}

build_perl()
{
    #检测
    cd /sources

    check_file perl-5.8.8.tar.bz2
    check_file perl-5.8.8-libc-2.patch
    check_dir perl-5.8.8

    #特殊
    echo "127.0.0.1 localhost $(hostname)" > /etc/hosts

    #解压
    tar jxvf perl-5.8.8.tar.bz2
    cd perl-5.8.8

    before_date=`date -R`

    #编译
    ./configure.gnu --prefix=/usr \
    -Dman1dir=/usr/share/man/man1 \
    -Dman3dir=/usr/share/man/man3 \
    -Dpager="/usr/bin/less -isR"
    make || eval "echo \"error: make error in perl\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R perl-5.8.8
}

build_readline()
{
    #检测
    cd /sources

    check_file readline-5.2.tar.gz
    check_file readline-5.2-fixes-3.patch
    check_dir readline-5.2

    #解压
    tar zxvf 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 ../readline-5.2-fixes-3.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --libdir=/lib
    make SHLIB_LIBS=-lncurses || eval "echo \"error: make error in readline\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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 /sources/
    rm -f -R readline-5.2
}

build_zlib()
{
    #检测
    cd /sources

    check_file zlib-1.2.3.tar.gz
    check_dir zlib-1.2.3

    #解压
    tar zxvf zlib-1.2.3.tar.gz
    cd zlib-1.2.3

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --shared --libdir=/lib
    make || eval "echo \"error: make error in zlib\" && exit 1"
    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 || eval "echo \"error: make error in zlib\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    chmod -v 644 /usr/lib/libz.a

    #清理
    cd /sources/
    rm -f -R zlib-1.2.3
}

build_autoconf()
{
    #检测
    cd /sources

    check_file autoconf-2.61.tar.bz2
    check_dir autoconf-2.61

    #解压
    tar jxvf autoconf-2.61.tar.bz2
    cd autoconf-2.61

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in autoconf\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R autoconf-2.61
}

build_automake()
{
    #检测
    cd /sources

    check_file automake-1.10.tar.bz2
    check_dir automake-1.10

    #解压
    tar jxvf automake-1.10.tar.bz2
    cd automake-1.10

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in automake\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R automake-1.10
}

bash_comment()
{
    echo "****************"
    echo "please run the following commands"
    echo
    echo "# exec /bin/bash --login +h"
    echo
    echo "****************"
}

build_bash()
{
    #检测
    cd /sources

    check_file bash-3.2.tar.gz
    check_file bash-doc-3.2.tar.gz
    check_file bash-3.2-fixes-5.patch
    check_dir bash-3.2

    #解压
    tar zxvf bash-3.2.tar.gz
    cd bash-3.2
    tar zxvf ../bash-doc-3.2.tar.gz

    #特殊
    sed -i "s|htmldir = @htmldir@|htmldir = /usr/share/doc/bash-3.2|" \
    Makefile.in

    #打补丁
    patch -Np1 -i ../bash-3.2-fixes-5.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --bindir=/bin \
    --without-bash-malloc --with-installed-readline
    make || eval "echo \"error: make error in bash\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    ln -vs bash /tools/bin/sh

    #清理
    cd /sources/
    rm -f -R bash-3.2

    #重新登录
    bash_comment
}

before_date_sum=`date -R`

essential_file
build_linux_api_headers
build_man_pages
build_glibc
adjust_toolchain
build_binutils
build_gcc
build_db
build_sed
build_e2fsprogs
build_coreutils
build_iana_etc
build_m4
build_bison
build_ncurses
build_procps
build_libtool
build_perl
build_readline
build_zlib
build_autoconf
build_automake
build_bash

#计时
after_date_sum=`date -R`
echo "$before_date_sum"
echo "$after_date_sum"

--------------------------------------------------------------------
[./utils/build-lfs-pass-5.sh]
--------------------------------------------------------------------
#! /bin/sh

source lfs.lib

check_root

pass4_warning

stripping()
{
    /tools/bin/find /{,usr/}{bin,lib,sbin} -type f \
    -exec /tools/bin/strip --strip-debug '{}' ';'
}

logout_comment()
{
    echo "****************"
    echo "run the fllowing command to logout"
    echo
    echo "# logout"
    echo
    echo "****************"
}

stripping
logout_comment

--------------------------------------------------------------------
[./utils/build-lfs-pass-1.sh]
--------------------------------------------------------------------
#! /tools/bin/sh

source lfs.lib

check_root

pass0_warning

create_directories()
{
    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}
}

essential_file()
{
    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

    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
}

prompt_comment()
{
    echo "****************"
    echo "now run this commonds to remove the \"I have no name!\""
    echo
    echo "# exec /tools/bin/bash --login +h"
    echo
    echo "****************"
}

create_directories
essential_file
prompt_comment

--------------------------------------------------------------------
[./utils/build-lfs-pass-7.sh]
--------------------------------------------------------------------
#! /bin/sh

unset LFS
source lfs.lib

check_root

pass6_warning

build_lfs_bootscripts()
{
    #检测
    cd /sources
    check_file lfs-bootscripts-6.3.tar.bz2
    check_dir lfs-bootscripts-6.3

    #解压
    tar jxvf lfs-bootscripts-6.3.tar.bz2
    cd lfs-bootscripts-6.3

    before_date=`date -R`

    #编译
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R lfs-bootscripts-6.3
}

configure_setclock()
{
    cat > /etc/sysconfig/clock << "EOF"
# Begin /etc/sysconfig/clock

UTC=1

# End /etc/sysconfig/clock
EOF
}

configure_inputrc()
{
    cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc
# Modified by Chris Lynn <roryo@roryo.dynup.net>

# Allow the command prompt to wrap to the next line
set horizontal-scroll-mode Off

# Enable 8bit input
set meta-flag On
set input-meta On

# Turns off 8th bit stripping
set convert-meta Off

# Keep the 8th bit for display
set output-meta On

# none, visible or audible
set bell-style none

# All of the following map the escape sequence of the value
# contained in the 1st argument to the readline specific functions
"\eOd": backward-word
"\eOc": forward-word

# for linux console
"\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

# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# for Konsole
"\e[H": beginning-of-line
"\e[F": end-of-line

# End /etc/inputrc
EOF
}

configure_bash()
{
    cat > /etc/profile << "EOF"
# Begin /etc/profile

export LANG=zh_CN.utf8

# End /etc/profile
EOF
}

configure_localnet()
{
    #enter you host name
    echo "HOSTNAME=babyaries" > /etc/sysconfig/network
}

configure_hosts()
{
    cat > /etc/hosts << "EOF"
# Begin /etc/hosts (network card version)

#127.0.0.1 localhost
#<192.168.1.1> <HOSTNAME.example.org> [alias1] [alias2 ...]
127.0.0.1 babyaries localhost

# End /etc/hosts (network card version)
EOF
}

configure_network()
{
    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
    cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf

#domain <Your Domain Name>
#nameserver <IP address of your primary nameserver>
#nameserver <IP address of your secondary nameserver>

nameserver 202.96.128.166
nameserver 202.96.134.133

# End /etc/resolv.conf
EOF
}

network_comment()
{
    echo "******** warning ********"
    echo "please edit /etc/resolv.conf by yourself"
    echo "******** warning ********"
}

build_lfs_bootscripts
configure_setclock
configure_inputrc
configure_bash
configure_localnet
configure_hosts
configure_network

network_comment

--------------------------------------------------------------------
[./utils/build-lfs-pass-9.sh]
--------------------------------------------------------------------
#! /bin/sh

source lfs.conf
source lfs.lib

check_root

logout_from_chroot_warning

virtual_file_system()
{
    mkdir -pv $LFS/{dev,proc,sys}

    if [ ! -e $LFS/dev/console ] ; then
    mknod -m 600 $LFS/dev/console c 5 1
    fi

    if [ ! -e $LFS/dev/null ] ; then
    mknod -m 666 $LFS/dev/null c 1 3
    fi

    mount | grep -q "/dev on $LFS/dev "
    if [ $? -ne 0 ] ; then
    mount -v --bind /dev $LFS/dev
    fi

    mount | grep -q "devpts on $LFS/dev/pts "
    if [ $? -ne 0 ] ; then
    mount -vt devpts devpts $LFS/dev/pts
    fi

    mount | grep -q "shm on $LFS/dev/shm "
    if [ $? -ne 0 ] ; then
    mount -vt tmpfs shm $LFS/dev/shm
    fi

    mount | grep -q "proc on $LFS/proc "
    if [ $? -ne 0 ] ; then
    mount -vt proc proc $LFS/proc
    fi

    mount | grep -q "sysfs on $LFS/sys "
    if [ $? -ne 0 ] ; then
    mount -vt sysfs sysfs $LFS/sys
    fi
}

umount_and_reboot()
{
    umount -v $LFS/dev/pts
    umount -v $LFS/dev/shm
    umount -v $LFS/dev
    umount -v $LFS/proc
    umount -v $LFS/sys
    umount -v $LFS
    echo "****************"
    echo "restart the system, good luck :)"
    echo
    echo "# init 6"
    echo
    echo "****************"
}

if [ ! -e $LFS/sources ] ; then
    echo "error: $LFS/sources don't exist"
    exit 1
fi

virtual_file_system
umount_and_reboot
--------------------------------------------------------------------
[./utils/prepare-0.sh]
--------------------------------------------------------------------
#! /bin/sh

source lfs.conf
source lfs.lib

check_root

mkdir -pv $LFS/sources
chmod -v a+wt $LFS/sources

mkdir -pv $LFS/tools
#重要,'/tools -> $LFS/tools',chroot时也会用到
ln -sv $LFS/tools /

groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
echo "enter user lfs' password"
passwd lfs
chown -v lfs $LFS/tools
chown -v lfs $LFS/sources

echo "****************"
echo "enter 'su - lfs' to run prepare-1.sh now"
echo "****************"

--------------------------------------------------------------------
[./utils/build-lfs-pass-4-chroot.sh]
--------------------------------------------------------------------
#! /bin/sh

source lfs.conf
source lfs.lib

check_root

logout_from_chroot_warning

virtual_file_system()
{
    mkdir -pv $LFS/{dev,proc,sys}

    if [ ! -e $LFS/dev/console ] ; then
    mknod -m 600 $LFS/dev/console c 5 1
    fi

    if [ ! -e $LFS/dev/null ] ; then
    mknod -m 666 $LFS/dev/null c 1 3
    fi

    mount | grep -q "/dev on $LFS/dev "
    if [ $? -ne 0 ] ; then
    mount -v --bind /dev $LFS/dev
    fi

    mount | grep -q "devpts on $LFS/dev/pts "
    if [ $? -ne 0 ] ; then
    mount -vt devpts devpts $LFS/dev/pts
    fi

    mount | grep -q "shm on $LFS/dev/shm "
    if [ $? -ne 0 ] ; then
    mount -vt tmpfs shm $LFS/dev/shm
    fi

    mount | grep -q "proc on $LFS/proc "
    if [ $? -ne 0 ] ; then
    mount -vt proc proc $LFS/proc
    fi

    mount | grep -q "sysfs on $LFS/sys "
    if [ $? -ne 0 ] ; then
    mount -vt sysfs sysfs $LFS/sys
    fi
}

chroot_comment()
{
    echo "****************"
    echo "now login as root, then run the fllowing commands"
    echo
    echo "# export LFS=$LFS"
    echo "# chroot \"\$LFS\" /tools/bin/env -i \\
    HOME=/root TERM=\"\$TERM\" PS1='\\u:\\w\\$ ' \\
    PATH=/bin:/usr/bin:/sbin:/usr/sbin \\
    /tools/bin/bash --login"
    echo
    echo "****************"
}

if [ ! -e $LFS/sources ] ; then
    echo "error: $LFS/sources don't exist"
    exit 1
fi

virtual_file_system
chroot_comment

--------------------------------------------------------------------
[./utils/build-lfs-pass-3-main.sh]
--------------------------------------------------------------------
#! /bin/sh

unset LFS
source lfs.lib

check_root

pass0_warning

build_bzip2()
{
    #检测
    cd /sources

    check_file bzip2-1.0.4.tar.gz
    check_file bzip2-1.0.4-install_docs-1.patch
    check_dir bzip2-1.0.4

    #解压
    tar zxvf bzip2-1.0.4.tar.gz
    cd bzip2-1.0.4

    #打补丁
    patch -Np1 -i ../bzip2-1.0.4-install_docs-1.patch

    before_date=`date -R`

    #编译
    make -f Makefile-libbz2_so
    make clean
    make || eval "echo \"error: make error in bzip2\" && exit 1"
    make PREFIX=/usr install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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 /sources/
    rm -f -R bzip2-1.0.4
}

build_diffutils()
{
    #检测
    cd /sources

    check_file diffutils-2.8.1.tar.gz
    check_file diffutils-2.8.1-i18n-1.patch
    check_dir diffutils-2.8.1

    #解压
    tar zxvf diffutils-2.8.1.tar.gz
    cd diffutils-2.8.1

    #打补丁
    patch -Np1 -i ../diffutils-2.8.1-i18n-1.patch

    #特殊
    touch man/diff.1

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in diffutils\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R diffutils-2.8.1
}

build_file()
{
    #检测
    cd /sources

    check_file file-4.21.tar.gz
    check_dir file-4.21

    #解压
    tar zxvf file-4.21.tar.gz
    cd file-4.21

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in file\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R file-4.21
}

build_findutils()
{
    #检测
    cd /sources

    check_file findutils-4.2.31.tar.gz
    check_dir findutils-4.2.31

    #解压
    tar zxvf findutils-4.2.31.tar.gz
    cd findutils-4.2.31

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --libexecdir=/usr/lib/findutils \
    --localstatedir=/var/lib/locate
    make || eval "echo \"error: make error in findutils\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    mv -v /usr/bin/find /bin
    sed -i -e 's/find:=${BINDIR}/find:=\/bin/' /usr/bin/updatedb

    #清理
    cd /sources/
    rm -f -R findutils-4.2.31
}

build_flex()
{
    #检测
    cd /sources

    check_file flex-2.5.33.tar.bz2
    check_dir flex-2.5.33

    #解压
    tar jxvf flex-2.5.33.tar.bz2
    cd flex-2.5.33

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in flex\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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 /sources/
    rm -f -R flex-2.5.33
}

build_grub()
{
    #检测
    cd /sources

    check_file grub-0.97.tar.gz
    check_file grub-0.97-disk_geometry-1.patch
    check_dir grub-0.97

    #解压
    tar zxvf grub-0.97.tar.gz
    cd grub-0.97

    #打补丁
    patch -Np1 -i ../grub-0.97-disk_geometry-1.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in grub\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊,/boot有可能是在另外一个挂载
    mkdir -v /boot/grub
    cp -v /usr/lib/grub/i386-pc/stage{1,2} /boot/grub
    cp -v /usr/lib/grub/i386-pc/e2fs_stage1_5 /boot/grub

    #清理
    cd /sources/
    rm -f -R grub-0.97
}

build_gawk()
{
    #检测
    cd /sources

    check_file gawk-3.1.5.tar.bz2
    check_file gawk-3.1.5-segfault_fix-1.patch
    check_dir gawk-3.1.5

    #解压
    tar jxvf gawk-3.1.5.tar.bz2
    cd gawk-3.1.5

    #打补丁
    patch -Np1 -i ../gawk-3.1.5-segfault_fix-1.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --libexecdir=/usr/lib
    cat >> config.h << "EOF"
#define HAVE_LANGINFO_CODESET 1
#define HAVE_LC_MESSAGES 1
EOF
    make || eval "echo \"error: make error in gawk\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R gawk-3.1.5
}

build_gettext()
{
    #检测
    cd /sources

    check_file gettext-0.16.1.tar.gz
    check_dir gettext-0.16.1

    #解压
    tar zxvf gettext-0.16.1.tar.gz
    cd gettext-0.16.1

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in gettext\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R gettext-0.16.1
}

build_grep()
{
    #检测
    cd /sources

    check_file grep-2.5.1a.tar.bz2
    check_file grep-2.5.1a-redhat_fixes-2.patch
    check_dir grep-2.5.1a

    #解压
    tar jxvf grep-2.5.1a.tar.bz2
    cd grep-2.5.1a

    #打补丁
    patch -Np1 -i ../grep-2.5.1a-redhat_fixes-2.patch

    #特殊
    chmod +x tests/fmbtest.sh

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --bindir=/bin
    make || eval "echo \"error: make error in grep\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R grep-2.5.1a
}

build_groff()
{
    #检测
    cd /sources

    check_file groff-1.18.1.4.tar.gz
    check_file groff-1.18.1.4-debian_fixes-1.patch
    check_dir groff-1.18.1.4

    #解压
    tar zxvf groff-1.18.1.4.tar.gz
    cd groff-1.18.1.4

    #打补丁
    patch -Np1 -i ../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

    before_date=`date -R`

    #编译
    PAGE=A4 ./configure --prefix=/usr --enable-multibyte
    make || eval "echo \"error: make error in groff\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    ln -sv eqn /usr/bin/geqn
    ln -sv tbl /usr/bin/gtbl

    #清理
    cd /sources/
    rm -f -R groff-1.18.1.4
}

build_gzip()
{
    #检测
    cd /sources

    check_file gzip-1.3.12.tar.gz
    check_dir gzip-1.3.12

    #解压
    tar zxvf gzip-1.3.12.tar.gz
    cd gzip-1.3.12

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --bindir=/bin
    make || eval "echo \"error: make error in gzip\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    mv -v /bin/{gzexe,uncompress,zcmp,zdiff,zegrep} /usr/bin
    mv -v /bin/{zfgrep,zforce,zgrep,zless,zmore,znew} /usr/bin

    #清理
    cd /sources/
    rm -f -R gzip-1.3.12
}

build_inetutils()
{
    #检测
    cd /sources

    check_file inetutils-1.5.tar.gz
    check_file inetutils-1.5-no_server_man_pages-2.patch
    check_dir inetutils-1.5

    #解压
    tar zxvf inetutils-1.5.tar.gz
    cd inetutils-1.5

    #打补丁
    patch -Np1 -i ../inetutils-1.5-no_server_man_pages-2.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --libexecdir=/usr/sbin \
    --sysconfdir=/etc --localstatedir=/var \
    --disable-ifconfig --disable-logger --disable-syslogd \
    --disable-whois --disable-servers
    make || eval "echo \"error: make error in inetutils\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    mv -v /usr/bin/ping /bin

    #清理
    cd /sources/
    rm -f -R inetutils-1.5
}

build_iproute()
{
    #检测
    cd /sources

    check_file iproute2-2.6.20-070313.tar.gz
    check_dir iproute-2.6.20-070313

    #解压
    tar zxvf 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

    before_date=`date -R`

    #编译
    make SBINDIR=/sbin || eval "echo \"error: make error in iproute\" && exit 1"
    make SBINDIR=/sbin install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    mv -v /sbin/arpd /usr/sbin

    #清理
    cd /sources/
    rm -f -R iproute-2.6.20-070313
}

build_kbd()
{
    #检测
    cd /sources

    check_file kbd-1.12.tar.bz2
    check_file kbd-1.12-backspace-1.patch
    check_file kbd-1.12-gcc4_fixes-1.patch
    check_dir kbd-1.12

    #解压
    tar jxvf kbd-1.12.tar.bz2
    cd kbd-1.12

    #打补丁
    patch -Np1 -i ../kbd-1.12-backspace-1.patch
    patch -Np1 -i ../kbd-1.12-gcc4_fixes-1.patch

    before_date=`date -R`

    #编译
    ./configure --datadir=/lib/kbd
    make || eval "echo \"error: make error in kbd\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    mv -v /usr/bin/{kbd_mode,openvt,setfont} /bin

    #清理
    cd /sources/
    rm -f -R kbd-1.12
}

build_less()
{
    #检测
    cd /sources

    check_file less-406.tar.gz
    check_dir less-406

    #解压
    tar zxvf less-406.tar.gz
    cd less-406

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --sysconfdir=/etc
    make || eval "echo \"error: make error in less\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R less-406
}

build_make()
{
    #检测
    cd /sources

    check_file make-3.81.tar.bz2
    check_dir make-3.81

    #解压
    tar jxvf make-3.81.tar.bz2
    cd make-3.81

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in make\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R make-3.81
}

build_man_db()
{
    #检测
    cd /sources

    check_file man-db-2.4.4.tar.gz
    check_file man-db-2.4.4-fixes-1.patch
    check_dir man-db-2.4.4

    #解压
    tar zxvf 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,}
    mv man/ja{_JP.eucJP,}
    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 ../man-db-2.4.4-fixes-1.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --enable-mb-groff --disable-setuid
    make || eval "echo \"error: make error in man_db\" && exit 1"
    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

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R man-db-2.4.4
}

build_mktemp()
{
    #检测
    cd /sources

    check_file mktemp-1.5.tar.gz
    check_file mktemp-1.5-add_tempfile-3.patch
    check_dir mktemp-1.5

    #解压
    tar zxvf mktemp-1.5.tar.gz
    cd mktemp-1.5

    #打补丁
    patch -Np1 -i ../mktemp-1.5-add_tempfile-3.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --with-libc
    make || eval "echo \"error: make error in mktemp\" && exit 1"
    make install
    make install-tempfile

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R mktemp-1.5
}

build_module_init_tools()
{
    #检测
    cd /sources

    check_file module-init-tools-3.2.2.tar.bz2
    check_file module-init-tools-3.2.2-modprobe-1.patch
    check_dir module-init-tools-3.2.2

    #解压
    tar jxvf module-init-tools-3.2.2.tar.bz2
    cd module-init-tools-3.2.2

    #打补丁
    patch -Np1 -i ../module-init-tools-3.2.2-modprobe-1.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/ --enable-zlib
    make || eval "echo \"error: make error in module_init_tools\" && exit 1"
    make INSTALL=install install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R module-init-tools-3.2.2
}

build_patch()
{
    #检测
    cd /sources

    check_file patch-2.5.4.tar.gz
    check_dir patch-2.5.4

    #解压
    tar zxvf patch-2.5.4.tar.gz
    cd patch-2.5.4

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in patch\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R patch-2.5.4
}

build_psmisc()
{
    #检测
    cd /sources

    check_file psmisc-22.5.tar.gz
    check_dir psmisc-22.5

    #解压
    tar zxvf psmisc-22.5.tar.gz
    cd psmisc-22.5

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --exec-prefix=""
    make || eval "echo \"error: make error in psmisc\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    mv -v /bin/pstree* /usr/bin
    ln -sv killall /bin/pidof

    #清理
    cd /sources/
    rm -f -R psmisc-22.5
}

build_shadow()
{
    #检测
    cd /sources

    check_file shadow-4.0.18.1.tar.bz2
    check_file shadow-4.0.18.1-useradd_fix-2.patch
    check_dir shadow-4.0.18.1

    #解压
    tar jxvf shadow-4.0.18.1.tar.bz2
    cd shadow-4.0.18.1

    #打补丁
    patch -Np1 -i ../shadow-4.0.18.1-useradd_fix-2.patch

    before_date=`date -R`

    #编译
    ./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/ ko//' -e 's/ zh_CN zh_TW//' man/Makefile
    for i in de es fi fr id it pt_BR; do
    convert-mans UTF-8 ISO-8859-1 man/${i}/*.?
    done
    for i in cs hu pl; do
    convert-mans UTF-8 ISO-8859-2 man/${i}/*.?
    done
    convert-mans UTF-8 EUC-JP man/ja/*.?
    convert-mans UTF-8 KOI8-R man/ru/*.?
    convert-mans UTF-8 ISO-8859-9 man/tr/*.?
    sed -i -e 's@#MD5_CRYPT_ENAB.no@MD5_CRYPT_ENAB yes@' \
    -e 's@/var/spool/mail@/var/mail@' etc/login.defs
    make || eval "echo \"error: make error in shadow\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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

#optional
#    echo "enter root's password"
#    passwd root

    #清理
    cd /sources/
    rm -f -R shadow-4.0.18.1
}

passwd_comment()
{
    echo "******** warning ********"
    echo "remeber to run the following command!"
    echo
    echo "# passwd root"
    echo
    echo "******** warning ********"
}

build_sysklogd()
{
    #检测
    cd /sources

    check_file sysklogd-1.4.1.tar.gz
    check_file sysklogd-1.4.1-fixes-2.patch
    check_file sysklogd-1.4.1-8bit-1.patch
    check_dir sysklogd-1.4.1

    #解压
    tar zxvf sysklogd-1.4.1.tar.gz
    cd sysklogd-1.4.1

    #打补丁
    patch -Np1 -i ../sysklogd-1.4.1-fixes-2.patch
    patch -Np1 -i ../sysklogd-1.4.1-8bit-1.patch

    before_date=`date -R`

    #编译
    make || eval "echo \"error: make error in sysklogd\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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 /sources/
    rm -f -R sysklogd-1.4.1
}

build_sysvinit()
{
    #检测
    cd /sources

    check_file sysvinit-2.86.tar.gz
    check_dir sysvinit-2.86

    #解压
    tar zxvf sysvinit-2.86.tar.gz
    cd sysvinit-2.86

    #特殊
    sed -i 's@Sending processes@& configured via /etc/inittab@g' \
    src/init.c

    before_date=`date -R`

    #编译
    make -C src || eval "echo \"error: make error in sysvinit\" && exit 1"
    make -C src install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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 /sources/
    rm -f -R sysvinit-2.86
}

build_tar()
{
    #检测
    cd /sources

    check_file tar-1.18.tar.bz2
    check_dir tar-1.18

    #解压
    tar jxvf tar-1.18.tar.bz2
    cd tar-1.18

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --bindir=/bin --libexecdir=/usr/sbin
    make || eval "echo \"error: make error in tar\" && exit 1"
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R tar-1.18
}

build_texinfo()
{
    #检测
    cd /sources

    check_file texinfo-4.9.tar.bz2
    check_file texinfo-4.9-multibyte-1.patch
    check_file texinfo-4.9-tempfile_fix-1.patch
    check_dir texinfo-4.9

    #解压
    tar jxvf texinfo-4.9.tar.bz2
    cd texinfo-4.9

    #打补丁
    patch -Np1 -i ../texinfo-4.9-multibyte-1.patch
    patch -Np1 -i ../texinfo-4.9-tempfile_fix-1.patch

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr
    make || eval "echo \"error: make error in texinfo\" && exit 1"
    make install
    make TEXMF=/usr/share/texmf install-tex

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    cd /usr/share/info
    rm dir
    for f in *
    do
    install-info $f dir 2>/dev/null
    done

    #清理
    cd /sources/
    rm -f -R texinfo-4.9
}

build_udev()
{
    #检测
    cd /sources

    check_file udev-113.tar.bz2
    check_file udev-config-6.3.tar.bz2
    check_dir texinfo-4.9

    #解压
    tar jxvf udev-113.tar.bz2
    cd udev-113

    #特殊
    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

    before_date=`date -R`

    #编译
    make EXTRAS="`echo extras/*/`" || eval "echo \"error: make error in udev\" && exit 1"
    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


    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R udev-113
}

build_util_linux()
{
    #检测
    cd /sources

    check_file util-linux-2.12r.tar.bz2
    check_file util-linux-2.12r-cramfs-1.patch
    check_file util-linux-2.12r-lseek-1.patch
    check_dir util-linux-2.12r

    #解压
    tar jxvf 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 ../util-linux-2.12r-cramfs-1.patch
    patch -Np1 -i ../util-linux-2.12r-lseek-1.patch

    before_date=`date -R`

    #编译
    ./configure
    make HAVE_KILL=yes HAVE_SLN=yes || eval "echo \"error: make error in util_linux\" && exit 1"
    make HAVE_KILL=yes HAVE_SLN=yes install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #清理
    cd /sources/
    rm -f -R util-linux-2.12r
}

build_vim()
{
    #检测
    cd /sources

    check_file vim-7.1.tar.bz2
    check_file vim-7.1-fixes-1.patch
    check_file vim-7.1-mandir-1.patch
    check_dir vim71

    #解压
    tar jxvf vim-7.1.tar.bz2
    cd vim71

    #打补丁
    patch -Np1 -i ../vim-7.1-fixes-1.patch
    patch -Np1 -i ../vim-7.1-mandir-1.patch

    #特殊
    echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h

    before_date=`date -R`

    #编译
    ./configure --prefix=/usr --enable-multibyte || eval "echo \"error: make error in vim\" && exit 1"
    make
    make install

    #计时
    after_date=`date -R`
    echo "$before_date"
    echo "$after_date"

    #特殊
    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 /sources/
    rm -f -R vim71
}

logout_comment()
{
    echo "****************"
    echo "run the fllowing command then logout"
    echo
    echo "# passwd root"
    echo "# logout"
    echo
    echo "****************"
}

before_date_sum=`date -R`

build_bzip2
build_diffutils
build_file
build_findutils
build_flex
build_grub
build_gawk
build_gettext
build_grep
build_groff
build_gzip
build_inetutils
build_iproute
build_kbd
build_less
build_make
build_man_db
build_mktemp
build_module_init_tools
build_patch
build_psmisc
build_shadow
build_sysklogd
build_sysvinit
build_tar
build_texinfo
build_udev
build_util_linux
build_vim

#计时
after_date_sum=`date -R`
echo "$before_date_sum"
echo "$after_date_sum"

logout_comment

build-lfs打包下载

网络资源

1. LFS官方网址
http://www.linuxfromscratch.org/

2. 手把手教你如何建立自己的Linux系统 第二版
http://www.[把这个方括号去掉,代替成“将linux_sir中_去掉”的单词,因为sir被和谐了]/bbs/thread322894.html

时间:2010-02-24 14:33 来源: 作者:c-aries 原文链接

好文,顶一下
(5)
83.3%
文章真差,踩一下
(1)
16.7%
------分隔线----------------------------


把开源带在你的身边-精美linux小纪念品
无觅相关文章插件,快速提升流量