LFS ( Linux From Scratch http://www.linuxfromscratch.org )此篇博客是一個LFS的製做手冊, 內容涵蓋使用宿主系統或liveCD來製做LFS的詳細過程.從開始到結束手把手教你製做屬於你本身的linux系統.也能幫助你更清楚的知道linux系統是如何組成的, 這裏就簡單的說下LFS ,什麼linux開機流程,linux系統原理等等網上都有說明,這裏就不說了,至於linux系統的組成,將文檔從頭作到尾你就知道linux系統是怎麼組成的啦,嘿嘿!html
這是一個比較漫長的旅途,須要作的是細心,耐心,再細心, 這裏提醒下使用VMware虛擬機制做的朋友,快照纔是王道,在此旅途中肯定在此以前的操做是無誤並製做正確的, 能夠作下快照備份下當前虛擬機狀態,以避免後面不當心的操做而致使不可恢復性的錯誤,因此請務必階段性的作快照。固然若是使用物理機制做的朋友就是細心,當心啦........linux
製做的過程須要編譯大量的源碼,而編譯源代碼須要佔用大量的CPU時鐘週期,建議你們使用配置相對比較好的計算機,若是有PC Server的話建議在PC Server上面製做.個人環境是在一臺8核CPU,4G內存的PC Server上裝了一個虛擬機,(虛擬機分配的資源是8核CPU,2G內存),在這樣的配置下我編譯一個GCC跟glibc花了1個小時,因此建議你們有好的資源不要浪費啊.嘿嘿c++
好了,閒話很少說, Are you ready數據庫
若是使用liveCD做爲宿主系統的朋友須要去LFS官方下載liveCD鏡像包,裏面包含製做過程當中所需的軟件包,等,固然若是使用原有的操做系統來做爲宿主系統的朋友也須要去LFS官方下載liveCD鏡像,爲何呢?由於liveCD裏面包含有製做過程當中所須要的軟件包,這樣咱們就不用一個一個去互聯網上下載了,呵呵, bootstrap
這裏介紹下個人環境,在一臺8核CPU 4G內存的PCserver上裝了一個VMware虛擬機工具,而後在虛擬機上裝了個rhel5.4 32位系統(8核CPU/2G內存),我是經過現有的系統來製做的,那有些朋友說了,使用liveCD跟現有的宿主系統製做的步驟都是一眼的嗎? 沒錯,步驟是同樣的, 不管使用liveCD或者現有的宿主系統在製做過程上沒有什麼差異,bash
liveCD的下載地址 less
http://ftp.osuosl.org/pub/lfs-livecd/lfslivecd-x86_64-6.3-r2145.isoide
1,添加硬盤函數
關閉虛擬機添加一塊10G大小的IDE接口的虛擬硬盤,並將虛擬硬盤存爲一個文件,步驟見下圖.工具
建立一塊新硬盤
選擇虛擬硬盤的類型爲IDE
設置虛擬硬盤的大小並設置將虛擬硬盤存儲爲1個文件
選擇虛擬硬盤的存儲位置,根據本身須要定義
磁盤添加完成後啓動計算機待開機完成後安裝基本開發庫及GCC編譯器
#使用liveCD製做的不須要執行此藍色字體的命令
#yum –y groupinstall "Development Libraries" "Development Tools"
#yum –y install gcc*
#而後將下載好的liveCD的鏡像文件放入虛擬光驅中,並掛載使用
#mount /dev/cdrom /media
#cp –avf /media/lfs-sources /
2,分區並格式化
- fdisk /dev/hda
- n
- p
- 1
- +300
- n
- p
- 2
- +7G
- w
- mkfs.ext3 /dev/hda1 #/boot分區
- mkfs.ext3 /dev/hda2 #/分區
3,創建制做車間
- mkdir /mnt/lfs
- mount /dev/hda2 /mnt/lfs
- mkdir -pv /mnt/lfs/{sources,tools}
- chmod -v a+wt /mnt/lfs/sources
- ln -s /mnt/lfs/tools /
4,製做的用戶
- groupadd lfs
- useradd -s /bin/bash -g lfs -m -k /dev/null lfs
- passwd lfs
- chown lfs /mnt/lfs/*
- su - lfs
- cat > ~/.bash_profile <<EOF內容以下
- exec env -i HOME=${HOME} TERM=${TERM} PS1='\u:\w\$' /bin/bash
- EOF
- cat > ~/.bashrc <<EOF
- set +h
- umask 022
- LC_ALL=POSIX
- PATH=/tools/bin:/bin:/usr/bin
- export PATH LC_ALL
- EOF
- source ~/.bash_profile
5,安裝彙編鏈接器(binutils)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/binutils-2.17.tar.bz2
- mkdir /mnt/lfs/sources/binutils-build
- cd /mnt/lfs/sources/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 ld/ld-new /tools/bin/
- cd ..
- rm -rf /mnt/lfs/sources/binutils-build
- rm -rf /mnt/lfs/sources/binutils-2.17
6,安裝編譯器(GCC)
- cd /mnt/lfs/sources
- tar -xvf /lfs-sources/gcc-4.1.2.tar.bz2
- mkdir /mnt/lfs/sources/gcc-build
- cd /mnt/lfs/sources/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 /mnt/lfs/sources/gcc-build
- rm -rf /mnt/lfs/sources/gcc-4.1.2
7,安裝內核頭文件
- cd /mnt/lfs/sources
- 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
8,安裝基本C庫(glibc)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/glibc-2.5.1.tar.bz2
- mkdir /mnt/lfs/sources/glibc-build
- cd /mnt/lfs/sources/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 /tools/etc
- touch /tools/etc/ld.so.conf
- make install
- cd ..
- rm -rf /mnt/lfs/sources/glibc-2.5.1
- rm -rf /mnt/lfs/sources/glibc-build
9,調整工具鏈
- 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
10,測試工具鏈
- echo 'main() {}' > dummy.c
- cc dummy.c
- readelf -l a.out | grep 'tools'
- 若是有Requesting program interpreter: /tools/lib/ld-linux.so.2則說明成功
- rm -rf aa.out dummy.c
11,安裝測試工具(tcl expect dejagnu)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/tcl8.4.15-src.tar.gz
- cd tcl8.4.15/unix
- /configure --prefix=/tools
- make
- make install
- make install-private-headers
- ln -sv tclsh8.4 /tools/bin/tchsh
- cd /mnt/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 /mnt/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 /mnt/lfs/sources/tcl8.4.15
- rm -rf /mnt/lfs/sources/expect-5.43
- rm -rf /mnt/lfs/sources/dejagnu-1.4.4
12,安裝彙編工具(binutils)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/binutils-2.17.tar.bz2
- mkdir /mnt/lfs/sources/binutils-build
- cd /mnt/lfs/sources/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 ld/ld-new /tools/bin
- cd ..
- rm -rf /mnt/lfs/sources/binutils-build
- rm -rf /mnt/lfs/sources/binutils-2.17
13,安裝GCC
- cd /mnt/lfs/sources/
- tar xvf /lfs-sources/gcc-4.1.2.tar.bz2
- cd gcc-4.1.2
- cp 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 /mnt/lfs/sources/gcc-build
- cd /mnt/lfs/sources/gcc-build
- ./gcc-4.1.2/configure --prefix=/tools \
- --with-local-prefix=/tools \
- --enable-clocale=gnu --enable-shared \
- --enable-threads=posix --enable-__cxa_atexit \
- --enable-languages=c,c++ --disable-libstdcxx-pch
- make
- make install
- cd ..
- rm -rf /mnt/lfs/sources/gcc-build
- rm -rf /mnt/lfs/sources/gcc-4.1.2
14,測試工具鏈
- echo 'main() {}' > dummy.c
- cc dummy.c
- readelf -l a.out | grep 'tools'
- 若是有Requesting program interpreter: /tools/lib/ld-linux.so.2則說明成功
- rm -rf a.out dummy.c
15,安裝文本交互函數庫(ncurses)
- cd /mnt/lfs/sources
- 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 /mnt/lfs/sources/ncurses-5.6
16,安裝命令解釋器(bash)
- cd /mnt/lfs/sources
- 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 -sv bash /tools/bin/sh
- cd ..
- rm -rf bash-3.2
17,安裝壓縮工具(bzip2)
- cd /mnt/lfs/sources/
- 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
18,安裝經常使用命令集(Coreutils)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/coreutils-6.9.tar.bz2
- cd coreutils-6.9
- /configure --prefix=/tools
- make
- make install
- cp src/su /tools/bin/su-tools
- cd ..
- rm -rf coreutils-6.9
19,安裝文件比較工具(diffutils)
- cd /mnt/lfs/sources
- 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
- cd /mnt/lfs/sources
- 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
20,安裝查找工具(findutils)
- cd /mnt/lfs/sources
- 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
21,安裝文本處理工具(gawk)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/gawk-3.1.5.tar.bz2
- cd gawk-3.1.5
- /configure --prefix=/tools
- make
- make install
- cd ..
- rm -rf gawk-3.1.5
22,安裝國際語言支持工具(gettext)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/gettext-0.16.1.tar.gz
- cd gettext-0.16.1/gettext-tools
- /configure --prefix=/tools --disable-shared
- make -C gnulib-lib
- make -C src msgfmt
- cp src/msgfmt /tools/bin
- cd ../../
- rm -rf gettext-0.16.1
23,安裝文件過濾工具(grep)
- cd /mnt/lfs/sources
- 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
24,安裝壓縮工具(gzip)
- cd /mnt/lfs/sources
- 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
25,安裝宏處理工具(M4)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/m4-1.4.10.tar.bz2
- cd m4-1.4.10
- /configure --prefix=/tools
- make
- make install
- cd ..
- rm -rf m4-1.4.10
26,安裝語法分析工具(bison)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/bison-2.3.tar.bz2
- cd bison-2.3
- /configure --prefix=/tools
- make
- make install
- cd ..
- rm -rf bison-2.3
27,安裝編譯過程控制工具(make)
- cd /mnt/lfs/sources
- 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
28,安裝補丁工具(patch)
- cd /mnt/lfs/sources
- 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
29,安裝腳本語言(perl)
- cd /mnt/lfs/sources
- 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 -Destatic_ext='Data/Dumper Fcntl IO POSIX'
- make perl utilities
- cp 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
30,文件處理工具(sed)
- cd /mnt/lfs/sources
- 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
31,安裝打包工具(tar)
- cd /mnt/sources
- 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
32,安裝信息閱讀工具(Texinfo)
- cd /mnt/lfs/sources
- tar xvf /lfs-sources/texinfo-4.9.tar.bz2
- /configure --prefix=/tools
- make
- make install
- cd ..
- rm -rf texinfo-4.9
33,安裝工具集(util-linux)
- cd /mnt/lfs/sources
- 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 mount/{,u}mount text-utils/more /tools/bin
- cd ..
- rm -rf util-linux-2.12r
34,退出lfs用戶
- exit
目標系統
35,設置環境變量等
- chown -R root:root /mnt/lfs/tools
- mkdir -pv /mnt/lfs/{dev,proc,sys}
- mknod -m 600 /mnt/lfs/dev/console c 5 1
- mknod -m 666 /mnt/lfs/dev/null c 1 3
- mount --bind /dev /mnt/lfs/dev
- mount -t devpts devpts /mnt/lfs/dev/pts
- mount -t tmpfs shm /mnt/lfs/dev/shm
- mount -t proc proc /mnt/lfs/proc
- mount -t sysfs sysfs /mnt/lfs/sys
- cp -a /lfs-sources/* /mnt/lfs/sources/
- chroot "/mnt/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
36,創建目標系統的目錄結構
- 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
- mount /dev/hda1 /boot
37,建立目標系統的用戶及組
- 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
- exec /tools/bin/bash --login +h
38,創建臨時文件和日誌文件
- 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
目標系統工具鏈製做
39,安裝linux內核頭文件(linux-header)
- cd /sources
- tar xvf 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/* /usr/include
- cd ..
- rm -rf linux-2.6.22.5
40,安裝基本C庫(glibc)
- cd /sources
- tar xvf glibc-2.5.1.tar.bz2
- cd glibc-2.5.1
- tar xvf /sources/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 ../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
- passwd: files
- group: files
- shadow: files
- hosts: files dns
- networks: files
- protocols: files
- services: files
- ethers: files
- rpc: files
- EOF
- cp -v --remove-destination /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
- cat > /etc/ld.so.conf <<EOF
- /usr/local/lib
- /opt/lib
- EOF
- rm -rf /sources/glibc-build
- rm -rf /sources/glibc-2.5.1
41,調整工具鏈
- 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
42,正確性檢查
- 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
- 上面的信息均顯示正常,則OK!
- rm -v dummy.c a.out dummy.log
43,安裝彙編器(binutils)
- cd /sources
- tar xvf binutils-2.17.tar.bz2
- 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
44,安裝GCC
- cd /sources
- tar xvf 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
45,檢測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]
- 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
- 上面信息顯示正常則表示工具鏈ok
- rm -rf dummy.c a.out dummy.log
46,安裝高性能數據庫(berkeley DB)
- cd /sources
- tar xvf db-4.5.20.tar.gz
- cd db-4.5.20
- patch -Np1 -i /sources/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 -R root:root /usr/share/doc/db-4.5.20
- cd /sources
- rm -rf db-4.5.20
47,階段性檢查,
- type -p gcc cc g++ c++ ld ar ranlib 打印信息以下表示正常
- /usr/bin/gcc
- /usr/bin/cc
- /usr/bin/g++
- /usr/bin/c++
- /usr/bin/ld
- /usr/bin/ar
- /usr/bin/ranlib
- find /{,usr/}{bin,sbin,lib}/* -type f -exec ldd '{}' ';' 2>/dev/null | grep tools 沒有任何打印信息表示正常
48,安裝文本處理工具(sed)
- cd /sources
- tar xvf sed-4.1.5.tar.gz
- cd sed-4.1.5
- /configure --prefix=/usr --bindir=/bin
- make
- make install
- cd ..
- rm -rf sed-4.1.5
49,安裝ext文件系統管理工具(e2fsprogs)
- cd /sources
- tar xvf e2fsprogs-1.40.2.tar.gz
- cd e2fsprogs-1.40.2
- sed -i -e 's@/bin/rm@/tools&@' lib/blkid/test_probe.in
- mkdir build
- cd build
- ./configure --prefix=/usr --with-root-prefic="" \
- --enable-elf-shlibs --sysconfdir=/etc
- make
- make install
- make install-libs
- cd ../../
- rm -rf e2fsprogs-1.40.2
- # 49步在make的時候可能會出現找不到makeinfo命令,
- # 個人解決辦法是從宿主機上找到makeinfo命令而後cp到/mnt/lfs/tools/bin/目錄下而後再運行make
50,安裝經常使用命令集(coreutils)
- cd /sources
- tar xvf coreutils-6.9.tar.bz2
- cd coreutils-6.9
- /configure --prefix=/usr
- make
- 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
51,安裝端口及協議文件(nana-etc)
- cd /sources
- tar xvf iana-etc-2.20.tar.bz2
- cd iana-etc-2.20
- make
- make install
- cd ..
- rm -rf iana-etc-2.20
52,安裝宏處理工具(m4)
- cd /sources
- tar xvf m4-1.4.10.tar.bz2
- cd m4-1.4.10
- /configure --prefix=/usr
- make
- make install
- cd ..
- rm -rf m4-1.4.10
53,安裝語法分析工具(bison)
- cd /sources
- tar xvf bison-2.3.tar.bz2
- cd bison-2.3
- /configure --prefix=/usr
- echo '#define YYENABLE_NLS 1' >> config.h
- make
- make install
- cd ..
- rm -rf bison-2.3
54,安裝交互式函數庫(ncurses)
- cd /sources
- tar xvf ncurses-5.6.tar.gz
- cd ncurses-5.6
- patch -Np1 -i /sources/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
55,安裝進程管理工具(procps)
- cd /sources
- tar xvf procps-3.2.7.tar.gz
- cd procps-3.2.7
- make
- make install
- cd ..
- rm -rf procps-3.2.7
56,安裝通用支持庫工具(libtools)
- cd /sources
- tar xvf libtool-1.5.24.tar.gz
- cd libtool-1.5.24
- /configure --prefix=/usr
- make
- make install
- cd ..
- rm -rf libtool-1.5.24
57,安裝腳本語言(perl)
- cd /sources
- tar xvf 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 install
- cd ..
- rm -rf perl-5.8.8
58,安裝行編輯支持工具(readline)
- cd /sources
- tar xvf 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 /sources/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
59,安裝zip格式支持庫(zlib)
- cd /sources
- tar xvf zlib-1.2.3.tar.gz
- cd zlib-1.2.3
- /configure --prefix=/usr --shared --libdir=/lib
- make
- 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 install
- chmod 644 /usr/lib/libz.a
- cd ..
- rm -rf zlib-1.2.3
60,安裝自動化腳本生成工具(autoconf)
- cd /sources
- tar xvf autoconf-2.61.tar.bz2
- cd autoconf-2.61
- /configure --prefix=/usr
- make
- make install
- cd ..
- rm -rf autoconf-2.61
61,安裝自動編譯腳本生成工具(automake)
- cd /sources
- tar xvf automake-1.10.tar.bz2
- cd automake-1.10
- /configure --prefix=/usr
- make
- make install
- cd ..
- rm -rf automake-1.10
62,安裝命令解釋器(bash)
- cd /sources
- tar xvf bash-3.2.tar.gz
- cd bash-3.2
- sed -i "s|htmldir = @htmldir@|htmldir = /usr/share/doc/bash-3.2|" Makefile.in
- patch -Np1 -i /sources/bash-3.2-fixes-5.patch
- /configure --prefix=/usr --bindir=/bin --without-bash-malloc --with-installed-readline
- make
- make install
- cd ..
- rm -rf bash-3.2
63,使用剛剛編譯好的bash
- exec /bin/bash --login +h
64,安裝壓縮工具(bzip2)
- cd /sources
- tar xvf bzip2-1.0.4.tar.gz
- cd bzip2-1.0.4
- patch -Np1 -i /sources/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
65,安裝文件比較工具(diffutils)
- cd /sources
- tar xvf diffutils-2.8.1.tar.gz
- cd diffutils-2.8.1
- patch -Np1 -i /sources/diffutils-2.8.1-i18n-1.patch
- touch man/diff.1
- /configure --prefix=/usr
- make
- make install
- cd ..
- rm -rf diffutils-2.8.1
因爲博客限制一篇博客不能超過8W字符,餘下內容見下面的連接