目的:深刻了解以Linux內核爲基礎的系統是如何組成,運行,以構建一個最基礎的,純淨的系統。css
LFS構建步驟
宿主機準備
- linux操做系統安裝
- 使用獨立硬盤,建立分區
- 配置用戶和組
- 下載全部須要的軟件包源代碼
準備開發環境
構建一個基本開發環境
構造完整的目標系統
配置系統啓動腳本
啓動系統html
1、宿主系統準備
1.1.安裝所須要依賴包node
[root@node ~]# yum install -y bash binutils bison bzip2 coreutils diffutils findutils gawk gcc glibc grep gzip kernel m4 make patch perl sed tar texinfo xz gcc-c++ flex
檢查python
cat > version-check.sh << "EOF" #!/bin/bash # Simple script to list version numbers of critical development tools export LC_ALL=C bash --version | head -n1 | cut -d" " -f2-4 MYSH=$(readlink -f /bin/sh) echo "/bin/sh -> $MYSH" echo $MYSH | grep -q bash || echo "ERROR: /bin/sh does not point to bash" unset MYSH echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3- bison --version | head -n1 if [ -h /usr/bin/yacc ]; then echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`"; elif [ -x /usr/bin/yacc ]; then echo yacc is `/usr/bin/yacc --version | head -n1` else echo "yacc not found" fi bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6- echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2 diff --version | head -n1 find --version | head -n1 gawk --version | head -n1 if [ -h /usr/bin/awk ]; then echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`"; elif [ -x /usr/bin/awk ]; then echo awk is `/usr/bin/awk --version | head -n1` else echo "awk not found" fi gcc --version | head -n1 g++ --version | head -n1 ldd --version | head -n1 | cut -d" " -f2- # glibc version grep --version | head -n1 gzip --version | head -n1 cat /proc/version m4 --version | head -n1 make --version | head -n1 patch --version | head -n1 echo Perl `perl -V:version` sed --version | head -n1 tar --version | head -n1 makeinfo --version | head -n1 xz --version | head -n1 echo 'int main(){}' > dummy.c && g++ -o dummy dummy.c if [ -x dummy ] then echo "g++ compilation OK"; else echo "g++ compilation failed"; fi rm -f dummy.c dummy EOF [root@node ~]# bash version-check.sh bash, version 4.2.46(2)-release /bin/sh -> /usr/bin/bash Binutils: version 2.27-34.base.el7 bison (GNU Bison) 3.0.4 yacc not found ##使用bison來替代 ,語法分析器 [root@node ~]# ln -sv /usr/bin/bison /usr/bin/yacc ‘/usr/bin/yacc’ -> ‘/usr/bin/bison’ Also check for some library consistency: cat > library-check.sh << "EOF" #!/bin/bash for lib in lib{gmp,mpfr,mpc}.la; do echo $lib: $(if find /usr/lib* -name $lib| grep -q $lib;then :;else echo not;fi) found done unset lib EOF [root@node ~]# bash library-check.sh libgmp.la: not found libmpfr.la: not found libmpc.la: not found
1.2.術語說明
- 宿主系統 host system(用於製做系統的系統)
- 目標系統 target system(最終制做出來的系統)
- 臨時系統 temporary system(在製做系統過程當中,須要一個小型過渡的系統,這個系統在幫助完成目標系統製做後就不使用)
- 編譯工具 compiler(gcc等)
- 工具鏈 tools chain(開發中有不少依賴,爲了避免重複開發,能夠作成公共的來調用 )
- 原工具鏈: 宿主系統的工具鏈
- 預工具鏈:用於生成臨時工具鏈的工具鏈
- 臨時工具鏈:用於生成臨時系統的工具鏈
- 目標工具鏈:用於生成目標系統的工具鏈
- 輔助工具 associated tools(除編譯外,相似make這種輔助的)
- 運行環境 running environment(運行系統上可有多個環境,這些環境有各自root目錄和環境的設置)
頭文件:C開發,在編譯時以.h結尾,存放函數,接口的描述,結構體信息
純淨度:當前系統與依賴於其餘系統的相關性linux
1.3.源代碼編譯過程:源代碼編譯成可執行文件流程c++
描述:三個階段
- 配置configure
生成配置文件,文件名一般是makefile
- 編譯make
最複雜階段,根據配置生成的makefile,執行一系列動做,如建立一些必要的文件,調用工具鏈環境中的命令來編譯源代碼和連接目標文件,
最終生成所須要的可執行文件,函數庫和各類輔助文件程序員
- 安裝make install
copy到相應的目錄中正則表達式
1.4.工具鏈(vim例子)
描述:linux下二進制文件都採用共享庫的運行方式,能夠減小程序文件的代碼量,使用應用程序佔用的空間更小,
運行過程當中要訪問共享庫,必須存在系統中,並且要在搜索路徑中能夠找到,若是共享庫丟失或者應用程
序找不到就會報錯
vim:
vim的所編譯過程: 依賴於各類庫,要編譯vim,vim依賴於ncurses,ncurses依賴於glibc,這種依賴關係就是工具鏈,由編譯器,彙編器,和相應的庫函數組成的,在linux上常使用的是gcc,bintuils,和glibc組合的工具鏈,工具鏈的原則是從某一個工具鏈編譯出來的二進制文件或者庫函數文件,必須連接到該工具的函數庫,不管是靜態仍是動態,從圖上能夠看出ncurses和vim都是連接在glibc上,也就是工具鏈的函數庫部分就是glibc,glibc是"自給自足的"的,不依賴於函數庫就能夠完成編譯的連接,最終要製做的系統包含完整的工具鏈,由於但願目標系統是一個純淨的系統,能夠獨立運行,不依賴於外部,因此其中的工具鏈到最終是要依賴於工具鏈內部的glibc,能夠經過工具鏈的兩種依賴方式,能夠很方便從源生最原始的工具鏈到製做出來的工個鏈算法
- gcc、binutiils運行時依賴於glibc
- 外部依賴:依賴於工具鏈以外的glibc
- 內部依賴:依賴於工具鏈中的glibc
圖中的軟件包存在依賴關係,有依賴必須先安裝,要編譯vim要先編譯ncurses,要編譯ncurses,要先安裝glibc,決定了要按次順來操做,通常生成共享庫或程序文件時,連接器來連接所依賴的函數庫,因次在編譯某個軟件包前,編譯它所依賴的軟件不只是要安裝頭文件,仍是由於在用到它所提供的函數庫,不然就沒法完成編譯連接的過程.
linux內核部分:雖然運行任何程序都要使用到內核,可是在製做目標系統的過程當中,目標系統的內核並不須要先編譯和安裝,由於使用Linux內核並不像使用glibc須要使用動態連接庫來調用,內核的調用是經過glibc的各類函數庫,或其餘函數庫經過系統調用來進行的,因此並不須要一開始編譯安裝內核,只須要內核所須要的頭文件就能夠.shell
[root@node ~]# ldd /usr/bin/vim linux-vdso.so.1 => (0x00007ffd621f3000) libm.so.6 => /lib64/libm.so.6 (0x00007fd292cf8000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fd292ad0000) libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007fd2928a6000) libacl.so.1 => /lib64/libacl.so.1 (0x00007fd29269d000) libgpm.so.2 => /lib64/libgpm.so.2 (0x00007fd292495000) libdl.so.2 => /lib64/libdl.so.2 (0x00007fd292291000) libperl.so => /usr/lib64/perl5/CORE/libperl.so (0x00007fd291f03000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd291ce6000) libc.so.6 => /lib64/libc.so.6 (0x00007fd291919000) /lib64/ld-linux-x86-64.so.2 (0x00007fd293000000) libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fd2916b8000) libattr.so.1 => /lib64/libattr.so.1 (0x00007fd2914b2000) libncurses.so.5 => /lib64/libncurses.so.5 (0x00007fd29128b000) libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fd291072000) libnsl.so.1 => /lib64/libnsl.so.1 (0x00007fd290e57000) libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fd290c20000) libutil.so.1 => /lib64/libutil.so.1 (0x00007fd290a1d000) libfreebl3.so => /lib64/libfreebl3.so (0x00007fd290819000)
1.5.工具鏈製做關係
描述:工具鏈是由編譯器,彙編器,函數庫等組成的,工具鏈有兩種依賴方式,圖中從原工具鏈A等經過工具鏈B生成目標系統的工具鏈C,C與A沒有關係,因此是純淨的,可是仍是須要臨時工具鏈B的幫助
工具鏈分步實現過程
- 最開始原系統只有一個工具鏈A
- 使用工具鏈A生成gcc_B和binutils_B,因爲工具鏈之間的依賴關係,gcc_B和binutils_B都連接到glibA上,這時還不構成完整的工具鏈,由於要依賴於工具鏈A的glibA,不是純淨的工具鏈依賴於外部
- 編譯成一個新的程序A,依賴於gcc_B和binutils_B,glib_A
- 編譯出一個新的glib_B
- 把gcc_B和binutils_B的連接對象調整爲glib_B,這時能夠造成完整的工具鏈B
- 工具鏈B能夠編譯成一個新的應用程序B,它依賴於glibc_B,這種屬於外部依賴
- 使用現有的臨時工具鏈,編譯出gcc_C和binutils_C,造成工具鏈C,它使用工具鏈B的glibc_B做爲函數庫,造成與原始不要緊純淨的目標系統的工具鏈C
summary: 整個過程的關鍵點是編譯工具能夠修改指定的函數庫,也就是能夠修改依賴方式,經過設置內部和外部依賴的相互轉換,工具鏈B從內部依賴變成外部依賴,這個過程稱爲調整工具鏈,以最終實現純淨的一個工具鏈C
1.6.製做步驟概述
描述:三個階段按順序依次執行,每一個階段都爲下個階段作準備,並且三個階段都是相互交叉,上一個階段爲下一階段作準備
- 預工具鏈階段
- 臨時系統階段
- 目標系統階段
過程:
- 宿主系統:要求並不高,與目標系統架構兼容,不兼容使用交叉編譯製做,宿主系統包含工具鏈和輔助命令,在製做過程當中稱爲源工具鏈
- 建立預工具鏈,爲了創建臨時工具鏈,預工具鏈是由源工具鏈生成,建立初是內部依賴方式的工具鏈,用它編譯出來的工具鏈須要連接到
宿主系統的glibc上,
- 生成臨時工具鏈,爲了完成臨時系統,它須要脫離宿主系統的運行環境,臨時工具鏈自己也是臨時系統的重要組成部分,預工具鏈負責生成臨時系統的glibc,當glibc完成後,能預工具鏈的依賴關係進行調整,把預工具鏈變成外部依賴的工具鏈,調整完成後就生成臨時編譯工具,臨時編譯工具依賴於臨時系統的glibc,臨時編譯工具與glibc組成臨時工具鏈,這樣預工具鏈的使命就完成了,由臨時工具鏈替代預工具鏈進行臨時系統的製做,這個臨時工具鏈是內部依賴,它不依賴於宿系統的函數庫
- 編譯一個軟件系統編譯工具,一般還須要其餘程序參與,只是靠臨時工具鏈是沒法完成對目標系統的製做的,因此須要一個相對完整的環境,因此是一個臨時系統,臨時系統的完成須要宿主系統的輔助命令參與,臨時工具鏈將不依賴於宿主系統的輔助命令來編譯軟件,這樣就能夠爲臨時系統脫離宿主系統做好準備,臨時工具鏈將繼續完成臨時系統的製做,製做臨時系統的目的就是爲製做目標系統提供一個不依賴於宿主系統的環境,臨時工具鏈生成臨時系統,能夠保證各類工具軟件所依賴的函數庫是臨時系統自身的函數庫,而不是宿主系統的函數庫,在完成臨時系統的製做後,就可讓臨時系統脫離原有的系統,用臨時系統製做,就是爲了讓目標系統成爲獨立可擴展的系統,因此必須爲目標系統生成一個目標工具鏈
- 用臨時系統生成目標系統的glibc,而後調整臨時工具鏈,使用其編譯出來的程序文件和庫文件連接到目標系統的glibc上,及從內部依賴變成外部系統的方式,在編譯目標系統上的gcc,binutils,完成了目標工具鏈的創建,臨時工具鏈完成它的使命,可是臨時工具鏈中的輔助命令還要繼續使用,直到目標工具鏈中有相應輔助,造成一個完整的目標工具鏈環境
- 爲了讓目標系統能自足進行更新擴展,目標系統也須要有最基本的編譯環境,雖然已經生成目標工具鏈,可是輔助命令仍是使用臨時系統的,這時須要編譯出來一些輔助命令,安裝到目標系統中,從而造成目標工具鏈環境
- 在具體操做過程當中,能夠按照生成臨時系統的內容編譯各類輔助命令,也能夠根據須要安裝更多的輔助命令,或者是其餘的程序,在目標工具鏈環境生成以後,就像生成一個車間,能夠把目標環境系統進行進一步的完善,還要運行啓動系統須要grub之類
1.7.磁盤分區準備
- 40GB: 8g是swap, 32g其餘使用ext4 [root@node ~]# fdisk /dev/sdb Device Boot Start End Blocks Id System /dev/sdb1 2048 16779263 8388608 83 Linux /dev/sdb2 16779264 83886079 33553408 83 Linux [root@node ~]# mkswap /dev/sdb1 [root@node ~]# mkfs.ext4 /dev/sdb2 設置環境變量掛載 [root@node ~]# export LFS=/mnt/lfs [root@node ~]# mkdir -pv $LFS [root@node ~]# mount | grep $LFS /dev/sdb2 on /mnt/lfs type ext4 (rw,relatime,seclabel,data=ordered) [root@node ~]# source .bash_profile [root@node ~]# tail -1 .bash_profile export LFS=/mnt/lfs 或: [root@node ~]# tail -1 /etc/fstab /dev/sdb2 /mnt/lfs ext4 defaults 0 0 [root@node ~]# mount -a
2、軟件包及補丁
下載地址:http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/
[root@node ~]# mkdir -v $LFS/downloads 進行md5校驗: http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/MD5SUMS [root@node downloads]# md5sum lfs-packages-8.0.tar 2d1672ebe969628fc53d483a898fb500 lfs-packages-8.0.tar [root@node downloads]# tar xf lfs-packages-8.0.tar [root@node downloads]# mv 8.0/* . 建立源碼目錄: [root@node ~]# mkdir $LFS/sources [root@node ~]# chmod a+wt $LFS/sources
3、目錄和專用用戶準備
3.1.目錄結構準備
- /mnt/lfs目錄做爲"創做基地"
- $LFS/tools是"臨時系統"
[root@node ~]# mkdir $LFS/tools - 在宿主系統中建立符號連接/tools的,將其指向$LFS/tools,目的是宿主系統運行環境和目標系統運行環境均可以使用/tools,指向臨時目錄使用的命令 [root@node ~]# ln -sv $LFS/tools / ‘/tools’ -> ‘/mnt/lfs/tools’
3.2.添加LFS用戶
[root@node ~]# groupadd lfs [root@node ~]# useradd -s /bin/bash -g lfs -m -k /dev/null lfs #-k指定一個空設備,是防止從/etc/skel中複製模板,不使用發行版的模板,徹底自定義 [root@node ~]# echo lfs | passwd --stdin lfs [root@node ~]# chown lfs $LFS/tools [root@node ~]# chown lfs $LFS/sources [root@node ~]# ls -l $LFS total 28 drwxr-xr-x. 3 root root 4096 Jan 6 17:00 downloads drwx------. 2 root root 16384 Jan 6 15:57 lost+found drwxrwxrwt. 2 lfs root 4096 Jan 6 16:32 sources drwxr-xr-x. 2 lfs root 4096 Jan 6 17:07 tools
3.3.建立簡單的環境變量
[root@node ~]# su - lfs cat > ~/.bash_profile << "EOF" exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash EOF cat > ~/.bashrc << "EOF" set +h #關閉bash的hash功能,隨後有些工具要立刻生效,若是更新緩存須要時間 umask 022 LFS=/mnt/lfs LC_ALL=POSIX LFS_TGT=$(uname -m)-lfs-linux-gnu #編譯的架構要一致,若是不同要調 PATH=/tools/bin:/bin:/usr/bin #搜索路徑,並且hash,可讓它立刻生效 export LFS LC_ALL LFS_TGT PATH EOF 檢查: [root@node ~]# su - lfs Last login: Sun Jan 6 17:17:29 CST 2019 on pts/0 lfs:~$ export declare -x HOME="/home/lfs" declare -x LC_ALL="POSIX" declare -x LFS="/mnt/lfs" declare -x LFS_TGT="x86_64-lfs-linux-gnu" declare -x OLDPWD declare -x PATH="/tools/bin:/bin:/usr/bin" declare -x PS1="\\u:\\w\\\$ " declare -x PWD="/home/lfs" declare -x SHLVL="1" declare -x TERM="xterm"
3.4.軟件包的編譯時間
- SBU是標準編譯單位,使用binutils做爲一個值,其餘與它來做比較
- 經過time來肯定
3.5.測試
描:include一個標準的io輸入,在函數主體打印一個hello world,返回0,沒有語法錯誤是正常
cat > test.c << "EOF" #include <stdio.h> main() { printf("hello World\n"); return 0; } EOF lfs:~$ gcc test.c lfs:~$ ls a.out test.c lfs:~$ ./a.out hello World
4、構建臨時系統
描述:要製做臨時工具鏈,要先生成一個預工具鏈,LFS文檔中並不沒有說起,是爲了更好理解
- 利用宿主系統安裝的組件生成預工具鏈,再使用預工具鏈生成臨時工具鏈,再根據臨時工具鏈生成輔助命令,造成臨時系統
- 預工具鏈主要有兩個工具:彙編連接器bintuils和gcc
- 構建臨時系統
- 構建與宿主系統無關的臨時工具鏈,包括庫,編譯器,彙編器等
- 使用臨時工具鏈生成輔助命令
- 最終要實現臨時系統是要安裝在lfs目錄下tools目錄,與宿主系統目錄分開,與目標系統目錄也分開
4.1.編譯的次序
- 預工具鏈
Bintuils-2.27 gcc和glibc的configure命令都會須要一些彙編器和連接器的檢查測試,因此首先要編譯安裝bintuils [root@node ~]# type ld GUN連接器,把目標文件連接到可執行程序 ld is /usr/bin/ld [root@node ~]# whatis ld ld (1) - The GNU linker [root@node ~]# whereis ld ld: /usr/bin/ld /usr/bin/ld.bfd /usr/bin/ld.gold /usr/share/man/man1/ld.1.gz [root@node ~]# ld --verbose | grep SEARCH 連接器重要配置是庫文件從那裏搜索,如下是宿主系統中默認的 SEARCH_DIR("=/usr/x86_64-redhat-linux/lib64"); SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib64"); SEARCH_DIR("=/usr/x86_64-redhat-linux/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); 當使用gcc編譯程序時,若是使用gcc參數--verbose,它調用連接器時也會傳參數,能夠把ld裏連接那些文件都顯示出來 [root@node tmp]# gcc test.c -Wl,--verbose 2>&1 |grep succ 把預處理,編譯,彙編的過程都顯示,還包括gcc的include搜索次序 attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crt1.o succeeded attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64/crti.o succeeded attempt to open /usr/lib/gcc/x86_64-redhat-linux/4.8.5/crtbegin.o succeeded attempt to open /tmp/ccG2XNzN.o succeeded GCC-6.3.0 Linux-4.9.9 API Headers 把頭文件copy到tools目錄下,可使用是glibc與內核進行個性化交互
- 臨時工具鏈
Glibc-2.25 考慮編譯器和頭文件的來源 Libstdc++-6.3.0 標準c++庫 Binutils-2.27 第二次,要經過一個開關項指定ld的搜索路徑--with-lib-path=/tools/lib,使用得臨時工具鏈的生成與宿主系統做一個隔離 GCC-6.3.0 第二次gcc,也要調整,要直接修改gcc的源代碼文件,告訴gcc之後使用的動態連接器要使用本身的,不修改會嵌入宿主系統的/lib通常動態庫,形成可能不純淨
- 輔助命令
4.2.GUN screen命令
編譯流程:編譯時間過長
- 進入到LFS的源文件目錄,即用sources目錄
- 以lfs用戶身份,解壓要編譯的軟件包
- 進入到解壓後建立目錄中
- 根據指南說明編譯、檢查、安裝軟件包
- 回退到源文件目錄
- 除非特別說明,刪除解壓出來的目錄和全部編譯過程當中生成的目錄
GUN screen使用的場景
- 須要長時間鏈接
- 防止意外網絡中斷
功能:
- 會話恢復:只要screen進程沒有被終止,在其內部運行的會話就能夠恢復,登陸主機screen -r恢復,若是暫時性離開,可使用分離命令detach保證其中的程序正常的運行,把session進行掛起,切換到後臺,在screen中每一個會話都是獨立運行的,每一個會話各自編號本身的輸入輸出緩存,
- 多窗口
- 會話共享:有些人可能會使用QQ提供遠程協助的技術支持,screen也可讓一個或多個用戶從不一樣終端屢次登陸到一個會話中,而且共享會話中全部特性,看到是相同徹底同樣的輸出,提供窗口訪問控制權的限制,對窗口進行密碼保護
[root@node ~]# yum install screen -y screen [-AmRvx -ls -wipe][-d <做業名稱>][-h <行數>][-r <做業名稱>][-s ][-S <做業名稱>] 參數說明 -A 將全部的視窗都調整爲目前終端機的大小。 -d <做業名稱> 將指定的screen做業離線。 -h <行數> 指定視窗的緩衝區行數。 -m 即便目前已在做業中的screen做業,仍強制創建新的screen做業。 -r <做業名稱> 恢復離線的screen做業。 -R 先試圖恢復離線的做業。若找不到離線的做業,即創建新的screen做業。 -s 指定創建新視窗時,所要執行的shell。 -S <做業名稱> 指定screen做業的名稱。 -v 顯示版本信息。 -x 恢復以前離線的screen做業。 -ls或--list 顯示目前全部的screen做業。 -wipe 檢查目前全部的screen做業,並刪除已經沒法使用的screen做業。 經常使用參數: 列出當前全部的session,當着有當前活動有人使用,另外一個是已經分離 screen ls 新建一個叫reid的session screen -S reid 回到reid這個session screen -r reid 遠程detach某個session screen -d reid 結束當前session 並回到reid這個session screen -d -r reid 在每一個screen session 下,全部命令都以 ctrl+a(C-a) 開始。 注:技巧,是按完ctrl+a後鬆開,再按如shift ?,要鬆開ctril+a再按其餘鍵 C-a ? -> 顯示全部鍵綁定信息 C-a c -> 建立一個新的運行shell的窗口並切換到該窗口 C-a n -> Next,切換到下一個 window C-a p -> Previous,切換到前一個 window C-a 0..9 -> 切換到第 0..9 個 window Ctrl+a [Space] -> 由視窗0循序切換到視窗9 C-a C-a -> 在兩個最近使用的 window 間切換 C-a x -> 鎖住當前的 window,需用用戶密碼解鎖 **C-a d -> detach,暫時離開當前session,將目前的 screen session (可能含有多個 windows) 丟到後臺執行,並會回到還沒進 screen 時的狀態,此時在 screen session 裏,每一個 window 內運行的 process (不管是前臺/後臺)都在繼續執行,即便 logout 也不影響。 C-a z -> 把當前session放到後臺執行,用 shell 的 fg 命令則可回去。 C-a w -> 顯示全部窗口列表 C-a t -> Time,顯示當前時間,和系統的 load C-a k -> kill window,強行關閉當前的 window C-a [ -> 進入 copy mode,在 copy mode 下能夠回滾、搜索、複製就像用使用 vi 同樣 C-b Backward,PageUp C-f Forward,PageDown H(大寫) High,將光標移至左上角 L Low,將光標移至左下角 0 移到行首 $ 行末 w forward one word,以字爲單位往前移 b backward one word,以字爲單位日後移 Space 第一次按爲標記區起點,第二次按爲終點 Esc 結束 copy mode C-a ] -> Paste,把剛剛在 copy mode 選定的內容貼上 操做: [root@node ~]# screen -S backup 退出ctrl+a 再按d [detached from 12849.backup] 暫時離開,到後臺執行 [root@node ~]# screen -ls There is a screen on: 12849.backup (Detached) job的名稱 1 Socket in /var/run/screen/S-root. [root@node ~]# screen -r backup 恢復 [root@node ~]# screen -S vim-opt vim tom.txt [detached from 12866.vim-opt] [root@node ~]# screen -ls There are screens on: 12866.vim-opt (Detached) 12849.backup (Detached) 2 Sockets in /var/run/screen/S-root. 使用id恢復: [root@node ~]# screen -r 12866 看多個ctrl+a 再按w ctrl+a 再按c,建立一個新的screen 清除dead會話 screen -wipe 關閉或殺死窗口 ctrl+a K screen高級應用 - 會話共享 screen -x [root@node ~]# screen -S kk [root@node ~]# screen -x kk 進入到同一個會話 - 會話鎖定與解鎖 ctrl+a s ctrl+a q 屏幕不輸出,可是仍是會被接收,想不給其餘人看見時先按ctrl+a s - 發送命令到screen screen -S reid -X screen ping ip - 屏幕分割 ctrl+a S ctrl+a | - 複製、粘貼模式 ctrl+a <Esc> 或copy:ctrl+a [ paste: ctrl+a ]
4.3.Binutils的第一遍
[root@node ~]# screen [root@node ~]# su - lfs Last login: Sun Jan 6 17:22:48 CST 2019 on pts/0 lfs:~$ cd $LFS/sources lfs:/mnt/lfs/sources$ tar xf $LFS/downloads/binutils-2.27.tar.bz2 lfs:/mnt/lfs/sources$ cd binutils-2.27/ #包括連接器,彙編器,和其餘處理工具,之因此第一個處理binutils是由於他們的gcc,glibc的configure階段會對連接器等作檢查 lfs:/mnt/lfs/sources/binutils-2.27$ mkdir build lfs:/mnt/lfs/sources/binutils-2.27$ cd build lfs:/mnt/lfs/sources/binutils-2.27/build$ #通常linux源代碼都須要配置值,過程能夠檢查環境的狀態,與及配值自身的選項,還能夠經過參數設置出來的軟件是啓用或禁用 lfs:/mnt/lfs/sources/binutils-2.27/build$ time ../configure --prefix=/tools \ --with-sysroot=$LFS \ --with-lib-path=/tools/lib \ --target=$LFS_TGT \ --disable-nls \ --disable-werror 解釋: -prefix=/tools 軟件包安裝目錄,同時也爲其餘目錄設置一個基礎的目錄,至關於windows安裝時的一個自定義目錄 --with-sysroot=$LFS 交叉編譯用於告訴編譯系統在那查找所須要的文件, --with-lib-path=/tools/lib 編譯好後連接器一些庫的路徑存放的位置 --disable-nls 國際語言支持,根據不一樣的語言環境變量來顯示語言環境的技術,因爲是作一個預工具鏈的binutils,不須要長期使用, 因此在編譯時,能夠禁用這個功能,從而加快編譯的速度 --disable-werror 禁止宿主機上的一些警告事件,以防編譯的終止 configure命令:主要是檢查平臺安裝的一些特性,檢測到是cc,仍是gcc,configure是一個shell腳本,make是用來編譯的,configure檢查 後,最終會生成一個makefile,make就經過這個makefile來讀取指令,make install是用來進行安裝,也是經過makefile來 讀取指令,安裝到相應的位置上, 時間: real 0m13.983s -- user 0m6.628s sys 0m7.193s lfs:/mnt/lfs/sources/binutils-2.27/build$ time make real 10m20.188s user 7m10.288s sys 3m19.655s - 若是在x86_64上編譯,須要建立一個符號文件來確保工具鏈的完整性 lfs:/mnt/lfs/sources/binutils-2.27/build$ ls /tools/ -l total 0 lfs:/mnt/lfs/sources/binutils-2.27/build$ case $(uname -m) in x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;; esac mkdir: created directory '/tools/lib' '/tools/lib64' -> 'lib' 注:若是是x86_64實際會建一個lib文件夾,再作一個軟件鏈接 lfs:/mnt/lfs/sources/binutils-2.27/build$ ls /tools/ -l total 4 drwxr-xr-x. 2 lfs lfs 4096 Jan 6 20:15 lib lrwxrwxrwx. 1 lfs lfs 3 Jan 6 20:15 lib64 -> lib 安裝軟件包:install至關於個copy的過程 lfs:/mnt/lfs/sources/binutils-2.27/build$ time make install real 0m13.277s user 0m5.955s sys 0m7.826s lfs:/mnt/lfs/sources/binutils-2.27/build$ ls /tools/ -l total 16 drwxr-xr-x. 2 lfs lfs 4096 Jan 6 20:16 bin drwxr-xr-x. 2 lfs lfs 4096 Jan 6 20:15 lib lrwxrwxrwx. 1 lfs lfs 3 Jan 6 20:15 lib64 -> lib drwxr-xr-x. 4 lfs lfs 4096 Jan 6 20:16 share drwxr-xr-x. 4 lfs lfs 4096 Jan 6 20:16 x86_64-lfs-linux-gnu 刪除編譯目錄和源代碼目錄:爲了不一些沒必要要的問題 lfs:/mnt/lfs/sources/binutils-2.27/build$ cd $LFS/sources lfs:/mnt/lfs/sources$ rm -rf binutils-2.27/
4.4.gcc第一遍
- 本身先作一個gcc lfs:/mnt/lfs/sources$ tar xf ../downloads/gcc-6.3.0.tar.bz2 注:增長一些軟件包,都與數據運算有關,gpm是任何精度的算法庫,mpfr是一個高精度浮點算法庫 lfs:/mnt/lfs/sources$ cd gcc-6.3.0/ lfs:/mnt/lfs/sources/gcc-6.3.0$ tar xf $LFS/downloads/mpfr-3.1.5.tar.xz lfs:/mnt/lfs/sources/gcc-6.3.0$ mv mpfr-3.1.5 mpfr lfs:/mnt/lfs/sources/gcc-6.3.0$ tar xf $LFS/downloads/gmp-6.1.2.tar.xz lfs:/mnt/lfs/sources/gcc-6.3.0$ mv gmp-6.1.2 gmp lfs:/mnt/lfs/sources/gcc-6.3.0$ tar xf $LFS/downloads/mpc-1.0.3.tar.gz lfs:/mnt/lfs/sources/gcc-6.3.0$ mv mpc-1.0.3 mpc - 修改gcc默認動態連接庫,把/lib或/lib64修改到/tools下 lfs:/mnt/lfs/sources/gcc-6.3.0$ 注:在gcc原文件目錄下,找到這幾個文件linux,i386/linux{,64}}.h,對它們作備份,再作一個替換,把目錄加個tools for file in gcc/config/{linux,i386/linux{,64}}.h do cp -uv $file{,.orig} sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \ -e 's@/usr@/tools@g' $file.orig > $file echo ' #undef STANDARD_STARTFILE_PREFIX_1 #undef STANDARD_STARTFILE_PREFIX_2 #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/" #define STANDARD_STARTFILE_PREFIX_2 ""' >> $file touch $file.orig done - 對平臺作調整 lfs:/mnt/lfs/sources/gcc-6.3.0$ case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' \ -i.orig gcc/config/i386/t-linux64 ;; esac - 建立新的目錄 lfs:/mnt/lfs/sources/gcc-6.3.0$ mkdir build lfs:/mnt/lfs/sources/gcc-6.3.0$ cd build/ - configure 建議:參數 ../configure \ --target=$LFS_TGT \ --prefix=/tools \ --with-glibc-version=2.11 \ --with-sysroot=$LFS \ --with-newlib \ --without-headers \ --with-local-prefix=/tools \ --with-native-system-header-dir=/tools/include \ --disable-nls \ --disable-shared \ --disable-multilib \ --disable-decimal-float \ --disable-threads \ --disable-libatomic \ --disable-libgomp \ --disable-libmpx \ --disable-libquadmath \ --disable-libssp \ --disable-libvtv \ --disable-libstdcxx \ --enable-languages=c,c++ - make lfs:/mnt/lfs/sources/gcc-6.3.0/build$ time make real 45m18.791s user 36m47.849s sys 8m33.278s - 安裝 lfs:/mnt/lfs/sources/gcc-6.3.0/build$ make install - 刪除相應的包 lfs:/mnt/lfs/sources/gcc-6.3.0/build$ cd $LFS/sources lfs:/mnt/lfs/sources$ rm -rf gcc-6.3.0 注:到此預工具鏈完成
4.5.Linux-4.9.9 API 頭文件
搭述:編譯glibc時,須要使用內核,要安裝相關內核頭文件,這部分文件是存放在內核源代碼中的,因此在內核源代碼中提取各類頭文件,經過這部分頭文件可讓編譯器瞭解如何讓內核提供的各類各樣的功能,經過接口的調用須要運行的程序,
lfs:~$ cd $LFS/sources lfs:/mnt/lfs/sources$ tar xf ../downloads/linux-4.9.9.tar.xz lfs:/mnt/lfs/sources$ cd linux-4.9.9/ lfs:/mnt/lfs/sources/linux-4.9.9$ make mrproper #清除多餘的源代碼,主要獲得一個乾淨的內核,內核源代碼中可能保住編譯殘留的信息,這些信息會對後面產生沒必要要的內容, #因此在安裝頭部前進行一些清理的工做,清理除了mrproper,還有make clean,clean是清除當前目錄下編譯生產的文件,可是它 #會保持一些配置文件,mrproper會刪除全部的文件,包括編譯,配置,備份等文件,因此進行一次乾淨內核編譯以前都會用到它 lfs:/mnt/lfs/sources/linux-4.9.9$ time make INSTALL_HDR_PATH=dest headers_install #提取可用的內核頭文件,INSTALL_HDR_PATH=dest這是頭部安裝的文件,其實是有一個反作用, #安裝過程當中不加INSTALL_HDR_PATH=dest到目錄中,會把安裝目錄目標文件夾都給刪除後,再安裝頭部文件, #若是目標文件夾是空的,能夠,有東西就可能比較大些,默認安裝路徑是/usr/include,如今要安裝/tools/include, #因此通dest這個變量來指定 real 0m28.704s user 0m12.109s sys 0m18.641s lfs:/mnt/lfs/sources/linux-4.9.9$ ls dest/include/ asm asm-generic drm linux misc mtd rdma scsi sound uapi video xen lfs:/mnt/lfs/sources/linux-4.9.9$ cp -rv dest/include/* /tools/include #純手工的安裝 - 刪除無用的文件 lfs:/mnt/lfs/sources$ rm -rf linux-4.9.9
4.6.Glibc-2.25
描述:glibc的安裝,又叫GNU的基本C庫,它是linux內核的核心組件,它保證了應用程序和內核之間的調用,經過它對內核的包裝,能夠實現應用程序源代碼級別的可移植性,glibc能夠認爲內核和應用程序之間的橋樑,經過它所實現的函數能夠將Unix的程序在不修改或者在極小修改的狀況下,能夠遷移到linux上,須要所的就是從新編譯這個程序。
lfs:/mnt/lfs/sources$ tar xf ../downloads/glibc-2.25.tar.xz lfs:/mnt/lfs/sources/glibc-2.25$ mkdir build lfs:/mnt/lfs/sources/glibc-2.25$ cd build/ lfs:/mnt/lfs/sources/glibc-2.25/build$ ../configure \ --prefix=/tools \ --host=$LFS_TGT \ --build=$(../scripts/config.guess) \ --enable-kernel=2.6.32 \ --with-headers=/tools/include \ libc_cv_forced_unwind=yes \ libc_cv_c_cleanup=yes real 0m5.999s user 0m1.292s sys 0m1.907s lfs:/mnt/lfs/sources/glibc-2.25/build$ time make real 11m34.307s user 8m38.528s sys 2m57.258s lfs:/mnt/lfs/sources/glibc-2.25/build$ time make install real 1m45.307s user 1m18.925s sys 0m26.433s lfs:/mnt/lfs/sources/glibc-2.25/build$ /tools/lib/libc.so.6 GNU C Library (GNU libc) stable release version 2.25, by Roland McGrath et al. #2.25是編譯安裝glibc的target的版本號 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled by GNU CC version 6.3.0. #由這個版本編譯出2.25,這是預工具鏈的gcc Available extensions: crypt add-on version 2.1 by Michael Glad and others GNU Libidn by Simon Josefsson Native POSIX Threads Library by Ulrich Drepper et al BIND-8.2.3-T5B libc ABIs: UNIQUE IFUNC For bug reporting instructions, please see: <http://www.gnu.org/software/libc/bugs.html>. lfs:/mnt/lfs/sources/glibc-2.25/build$ rpm -qa|grep gcc libgcc-4.8.5-36.el7.x86_64 gcc-c++-4.8.5-36.el7.x86_64 gcc-4.8.5-36.el7.x86_64 宿主系統的gcc lfs:/mnt/lfs/sources/glibc-2.25/build$ echo $PATH /tools/bin:/bin:/usr/bin #lfs用戶的PATH中,把/tools/bin做爲搜索路徑的第一位,也就是這個裏面的gcc是如今所編譯的glibc2.25的編譯器 - 檢查(glibc特別重要) #作一個空的c文件 lfs:/mnt/lfs/sources/glibc-2.25/build$ echo 'int main(){}' > dummy.c #經過cc來作編譯 lfs:/mnt/lfs/sources/glibc-2.25/build$ $LFS_TGT-gcc dummy.c #根據編譯的結果,讀a.out裏面的信息,再使用grep作一個過濾 lfs:/mnt/lfs/sources/glibc-2.25/build$ readelf -l a.out | grep ': /tools' [Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2] #說明glibc是編譯成功 lfs:/mnt/lfs/sources/glibc-2.25/build$ rm -v dummy.c a.out #刪除歷史文件 lfs:/mnt/lfs/sources/glibc-2.25/build$ cd .. lfs:/mnt/lfs/sources/glibc-2.25$ cd .. lfs:/mnt/lfs/sources$ rm -rf glibc-2.25
4.7.libstdc
描述:標準的C++庫,是gcc源文件中的一部分
lfs:/mnt/lfs/sources$ tar xf ../downloads/gcc-6.3.0.tar.bz2 lfs:/mnt/lfs/sources$ cd gcc-6.3.0/ lfs:/mnt/lfs/sources/gcc-6.3.0$ mkdir build lfs:/mnt/lfs/sources/gcc-6.3.0$ cd build/ lfs:/mnt/lfs/sources/gcc-6.3.0/build$ time ../libstdc++-v3/configure \ --host=$LFS_TGT \ --prefix=/tools \ --disable-multilib \ --disable-nls \ --disable-libstdcxx-threads \ --disable-libstdcxx-pch \ --with-gxx-include-dir=/tools/$LFS_TGT/include/c++/6.3.0 real 1m37.799s user 0m46.485s sys 0m54.102s lfs:/mnt/lfs/sources/gcc-6.3.0/build$ time make real 3m3.254s user 2m31.882s sys 0m31.807s lfs:/mnt/lfs/sources/gcc-6.3.0/build$ time make install real 0m21.459s user 0m7.771s sys 0m14.503s lfs:/mnt/lfs/sources/gcc-6.3.0/build$ cd .. lfs:/mnt/lfs/sources/gcc-6.3.0$ cd .. lfs:/mnt/lfs/sources$ rm -rf gcc-6.3.0 - 編譯binutils(彙編工具) 描述:是第二次,以前使用的預工具鏈,仍是依賴於host系統中的glibc,沒法脫離宿主系統運行,因此 如今有了預工具鏈後,還要編譯binutils,做爲臨時工具鏈,來代替binutils中的工具 lfs:/mnt/lfs/sources$ tar xf ../downloads/binutils-2.27.tar.bz2 lfs:/mnt/lfs/sources$ cd binutils-2.27/ lfs:/mnt/lfs/sources/binutils-2.27$ mkdir build lfs:/mnt/lfs/sources/binutils-2.27$ cd build/ 環境變量的定義 描述:只是針對configure來作的,主要告訴configure,編譯器從那裏來找,指定使用的編譯器而不是宿主系統自有的, lfs:/mnt/lfs/sources/binutils-2.27/build$ CC=$LFS_TGT-gcc \ AR=$LFS_TGT-ar \ RANLIB=$LFS_TGT-ranlib \ ../configure \ --prefix=/tools \ --disable-nls \ --disable-werror \ --with-lib-path=/tools/lib \ --with-sysroot lfs:/mnt/lfs/sources/binutils-2.27/build$ time make real 10m9.743s user 7m24.319s sys 2m55.368s lfs:/mnt/lfs/sources/binutils-2.27/build$ time make install real 0m11.551s user 0m5.900s sys 0m6.266s 進行連接器的調整 描述:-C是指定目錄,對當前ld子目錄來作clean動做, lfs:/mnt/lfs/sources/binutils-2.27/build$ ls -l drwxr-xr-x. 7 lfs lfs 4096 Jan 6 23:38 ld lfs:/mnt/lfs/sources/binutils-2.27/build$ make -C ld clean lfs:/mnt/lfs/sources/binutils-2.27/build$ make -C ld LIB_PATH=/usr/lib:/lib #對ld目錄下文件作make,指定連接器庫的搜索路徑,下面有一個很重要的命令ld-new lfs:/mnt/lfs/sources/binutils-2.27/build$ cp -v ld/ld-new /tools/bin 刪除多餘目錄 lfs:/mnt/lfs/sources/binutils-2.27/build$ cd ../../ lfs:/mnt/lfs/sources$ rm -rf binutils-2.27
4.8.gcc
描述: 第二次編譯gcc,由於以前的gcc是預工具鏈的,如今要建立一個臨時工具鏈的gcc,來替代預工具鏈的,第一次編譯時是會安裝一些系統內部文件,裏面的頭文件不是一個完整的,第二次臨時工具鏈必需要有一個完整的頭文件
lfs:/mnt/lfs/sources$ tar xf ../downloads/gcc-6.3.0.tar.bz2 lfs:/mnt/lfs/sources$ cd gcc-6.3.0/ lfs:/mnt/lfs/sources/gcc-6.3.0$ cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \ `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h lfs:/mnt/lfs/sources/gcc-6.3.0$ for file in gcc/config/{linux,i386/linux{,64}}.h do cp -uv $file{,.orig} sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \ -e 's@/usr@/tools@g' $file.orig > $file echo ' #undef STANDARD_STARTFILE_PREFIX_1 #undef STANDARD_STARTFILE_PREFIX_2 #define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/" #define STANDARD_STARTFILE_PREFIX_2 ""' >> $file touch $file.orig done 是x86_64的要作修改操做 lfs:/mnt/lfs/sources/gcc-6.3.0$ case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' \ -i.orig gcc/config/i386/t-linux64 ;; esac 使用算法的包: lfs:/mnt/lfs/sources/gcc-6.3.0$ tar xf ../../downloads/mpfr-3.1.5.tar.xz lfs:/mnt/lfs/sources/gcc-6.3.0$ mv mpfr-3.1.5 mpfr lfs:/mnt/lfs/sources/gcc-6.3.0$ tar xf ../../downloads/gmp-6.1.2.tar.xz lfs:/mnt/lfs/sources/gcc-6.3.0$ mv gmp-6.1.2 gmp lfs:/mnt/lfs/sources/gcc-6.3.0$ tar xf ../../downloads/mpc-1.0.3.tar.gz lfs:/mnt/lfs/sources/gcc-6.3.0$ mv mpc-1.0.3 mpc configure: lfs:/mnt/lfs/sources/gcc-6.3.0$ mkdir build lfs:/mnt/lfs/sources/gcc-6.3.0$ cd build lfs:/mnt/lfs/sources/gcc-6.3.0/build$ CC=$LFS_TGT-gcc \ CXX=$LFS_TGT-g++ \ AR=$LFS_TGT-ar \ RANLIB=$LFS_TGT-ranlib \ ../configure \ --prefix=/tools \ --with-local-prefix=/tools \ --with-native-system-header-dir=/tools/include \ --enable-languages=c,c++ \ --disable-libstdcxx-pch \ --disable-multilib \ --disable-bootstrap \ --disable-libgomp lfs:/mnt/lfs/sources/gcc-6.3.0/build$ time make #若是失敗,要使用clean來清除下,再操做 lfs:/mnt/lfs/sources/gcc-6.3.0/build$ time make install lfs:/mnt/lfs/sources/gcc-6.3.0/build$ ln -sv gcc /tools/bin/cc # 有些軟件是調用寫死的CC來操做,而不是如今所編譯出來的gcc,爲了讓這此程序能順利運行, # 因此要建立一個軟件鏈接,在這個階段gcc出來後,至關於臨時工具鏈已經完整了,對於臨時 # 工具鏈是否能編譯出來一個正常的程序,會有一個測試,寫一個空的只能主函數的C文件,再 # 使用cc來編譯,對於a.out文件使用readelf來讀下信息,有特定的輸出內容. lfs:/mnt/lfs/sources/gcc-6.3.0/build$ echo 'int main(){}' > dummy.c cc dummy.c readelf -l a.out | grep ': /tools' [Requesting program interpreter: /tools/lib/ld-linux.so.2] #輸出結果 刪除 lfs:/mnt/lfs/sources/gcc-6.3.0/build$ cd ../../ lfs:/mnt/lfs/sources$ rm -rf gcc-6.3.0
4.9.tcl,expect,dejagun,check
描述: 給後續的軟件包提供make check之類測試支持
lfs:/mnt/lfs/sources$ tar xf ../downloads/tcl-core8.6.6-src.tar.gz lfs:/mnt/lfs/sources$ cd tcl8.6.6/unix/ lfs:/mnt/lfs/sources/tcl8.6.6/unix$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/tcl8.6.6/unix$ make 檢測:對於一些重要的安裝包,與編譯是否正常,與系統文件是否一致,可能根據平臺的不同會有一些警告,這時要作些忽略, 傳遞一個變量時區設置爲UTC lfs:/mnt/lfs/sources/tcl8.6.6/unix$ time TZ=UTC make test Tests ended at Sun Jan 06 18:57:04 UTC 2019 all.tcl: Total 31259 Passed 29921 Skipped 1285 Failed 53 Sourced 148 Test Files. Files with failing tests: http.test httpold.test Number of tests skipped for each constraint: 9 !ieeeFloatingPoint 3 asyncPipeChan 76 bigEndian 5 bug-3057639 49 dde 4 dontCopyLinks 63 emptyTest 2 hasIsoLocale 1 knownBadTest 39 knownBug 100 localeRegexp 48 longIs32bit 14 macosxFileAttr 76 memory 46 nonPortable 5 notNetworkFilesystem 9 nt 1 pcOnly 4 readonlyAttr 3 singleTestInterp 1 testexprparser && !ieeeFloatingPoint 1 testwinclock 21 testwordend 189 thread 2 unthreaded 2 wideBiggerThanInt 497 win 4 winVista real 15m48.677s user 1m18.065s sys 0m13.138s lfs:/mnt/lfs/sources/tcl8.6.6/unix$ make install lfs:/mnt/lfs/sources/tcl8.6.6/unix$ chmod -v u+w /tools/lib/libtcl8.6.so lfs:/mnt/lfs/sources/tcl8.6.6/unix$ make install-private-headers lfs:/mnt/lfs/sources/tcl8.6.6/unix$ ln -sv tclsh8.6 /tools/bin/tclsh lfs:/mnt/lfs/sources/tcl8.6.6/unix$ ls -l /tools/bin/tcl* lrwxrwxrwx. 1 lfs lfs 8 Jan 7 03:02 /tools/bin/tclsh -> tclsh8.6 -rwxr-xr-x. 1 lfs lfs 13152 Jan 7 03:01 /tools/bin/tclsh8.6 刪除遺留文件: lfs:/mnt/lfs/sources/tcl8.6.6/unix$ cd ../../ lfs:/mnt/lfs/sources$ rm -rf tcl8.6.6 expect 描述:與當前用戶進行交互時,人無須干預實現自行交互 lfs:/mnt/lfs/sources$ tar xf ../downloads/expect5.45.tar.gz lfs:/mnt/lfs/sources$ cd expect5.45/ lfs:/mnt/lfs/sources/expect5.45$ ##備份與修改配置 cp -v configure{,.orig} sed 's:/usr/local/bin:/bin:' configure.orig > configure configure 指定tcl的庫和include lfs:/mnt/lfs/sources/expect5.45$ ./configure --prefix=/tools \ --with-tcl=/tools/lib \ --with-tclinclude=/tools/include lfs:/mnt/lfs/sources/expect5.45$ time make lfs:/mnt/lfs/sources/expect5.45$ time make test 安裝:SCRIPTS能夠避免安裝一些額外腳本 lfs:/mnt/lfs/sources/expect5.45$ make SCRIPTS="" install lfs:/mnt/lfs/sources/expect5.45$ find /tools/ -name "libexpect*" /tools/lib/expect5.45/libexpect5.45.so /tools/man/man3/libexpect.3 刪除遺留文件: lfs:/mnt/lfs/sources/expect5.45$ cd ../ lfs:/mnt/lfs/sources$ rm -rf expect5.45 dejaGNU 描述: 主要作一些單元測試,把程序run起來向它發送一些字符串,等待程序返回結果,軟件測試時用得比較多, deja是使用expect來作測試,expect使用了tcl,有依賴關係 lfs:/mnt/lfs/sources$ tar xf ../downloads/dejagnu-1.6.tar.gz lfs:/mnt/lfs/sources$ cd dejagnu-1.6/ lfs:/mnt/lfs/sources/dejagnu-1.6$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/dejagnu-1.6$ make install lfs:/mnt/lfs/sources/dejagnu-1.6$ make check lfs:/mnt/lfs/sources/dejagnu-1.6$ type runtest runtest is /tools/bin/runtest lfs:/mnt/lfs/sources/dejagnu-1.6$ cd .. lfs:/mnt/lfs/sources$ rm -rf dejagnu-1.6 check 描述:C語言測試的一個框架,它會測試提供,如fork一個子進程,小的,單元測試的接口 lfs:/mnt/lfs/sources$ tar xf ../downloads/check-0.11.0.tar.gz lfs:/mnt/lfs/sources$ cd check-0.11.0/ lfs:/mnt/lfs/sources/check-0.11.0$ PKG_CONFIG= ./configure --prefix=/tools lfs:/mnt/lfs/sources/check-0.11.0$ make lfs:/mnt/lfs/sources/check-0.11.0$ time make check #要作些單元測試,會有報告 real 5m53.066s user 0m1.275s sys 0m2.017s lfs:/mnt/lfs/sources/check-0.11.0$ make install lfs:/mnt/lfs/sources/check-0.11.0$ type checkmk checkmk is /tools/bin/checkmk lfs:/mnt/lfs/sources/check-0.11.0$ cd .. lfs:/mnt/lfs/sources$ rm -rf check-0.11.0
4.10.ncurse bash bison bzip2
描述: 爲了讓臨時工具鏈完全脫離宿主系統,還須要創建臨時系統,第一類是使用交互環境bash,第二類是程序編譯的命令,第三類是程序使用的函數庫
ncurse: n是new,ncurse是GNU計劃的一部分,來替代curses這個非開源軟件,如開源的vim替代非開源的vi,ncurse是一套編程類庫,它提供的函數是使用來生成文本的界面,vi,screen都是使用ncurses
lfs:/mnt/lfs/sources$ tar xf ../downloads/ncurses-6.0.tar.gz lfs:/mnt/lfs/sources$ cd ncurses-6.0/ lfs:/mnt/lfs/sources/ncurses-6.0$ sed -i s/mawk// configure lfs:/mnt/lfs/sources/ncurses-6.0$ ./configure --prefix=/tools \ --with-shared \ --without-debug \ --without-ada \ --enable-widec \ --enable-overwrite lfs:/mnt/lfs/sources/ncurses-6.0$ make lfs:/mnt/lfs/sources/ncurses-6.0$ make install lfs:/mnt/lfs/sources/ncurses-6.0$ find /tools/ -name "*ncurse*" /tools/share/man/man1/ncursesw6-config.1.gz /tools/share/man/man3/ncurses.3x.gz /tools/include/ncurses.h /tools/include/ncurses_dll.h /tools/lib/libncursesw.so /tools/lib/libncursesw.so.6 /tools/lib/libncursesw.a /tools/lib/libncursesw.so.6.0 /tools/lib/libncurses++w.a /tools/bin/ncursesw6-config lfs:/mnt/lfs/sources/ncurses-6.0$ cd .. lfs:/mnt/lfs/sources$ rm -rf ncurses-6.0 bash 描述:選項--without-bash-malloc是不使用bash自身的內存分配功能,而使用glibc的memory location的函數 lfs:/mnt/lfs/sources$ tar xf ../downloads/bash-4.4.tar.gz lfs:/mnt/lfs/sources$ cd bash-4.4/ lfs:/mnt/lfs/sources/bash-4.4$ ./configure --prefix=/tools --without-bash-malloc lfs:/mnt/lfs/sources/bash-4.4$ make lfs:/mnt/lfs/sources/bash-4.4$ make test lfs:/mnt/lfs/sources/bash-4.4$ make install lfs:/mnt/lfs/sources/bash-4.4$ ln -sv bash /tools/bin/sh '/tools/bin/sh' -> 'bash' lfs:/mnt/lfs/sources/bash-4.4$ ls /tools/lib/bash/ Makefile.inc finfo ln mypid printenv rmdir strftime truefalse unlink basename head logname pathchk push setpgid sync tty whoami dirname id mkdir print realpath sleep tee uname lfs:/mnt/lfs/sources/bash-4.4$ cd .. lfs:/mnt/lfs/sources$ rm -rf bash-4.4 bison 描述:語法分析器,對代碼的語法,方法進行分析,bison與yacc兼容 lfs:/mnt/lfs/sources$ tar xf ../downloads/bison-3.0.4.tar.xz lfs:/mnt/lfs/sources$ cd bison-3.0.4/ lfs:/mnt/lfs/sources/bison-3.0.4$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/bison-3.0.4$ make lfs:/mnt/lfs/sources/bison-3.0.4$ time make check real 5m14.892s user 4m12.633s sys 1m10.166s lfs:/mnt/lfs/sources/bison-3.0.4$ make install lfs:/mnt/lfs/sources/bison-3.0.4$ cd .. lfs:/mnt/lfs/sources$ rm -rf bison-3.0.4 bzip 描述:包含壓縮和觖壓縮的工具,它是獨立的開源項目,它不是GUN計劃的一部分,官網上說明剛修改一個漏洞, CVE,有些公共安全的服務機構,它就是一個公共漏洞的,各個廠商可能會發現一些漏洞,各有各的叫法, 爲了標準化,就成立一個組織把它統一塊兒來,使得發現的漏洞信息,可能各個廠商作法就同樣,就根據CVE 這個標準來作,bzip2是一個著名的壓縮解壓縮軟件,很大發行版本都有它,CVE-2010-0405,它某一個函數 有一個溢出的漏洞,能夠惡意軟件使用ddos把系統搞崩潰,若是閉源,這個問題就不容易發現,只有廠商 知道,若是開源被看到可能就很快修改。 lfs:/mnt/lfs/sources$ tar xf ../downloads/bzip2-1.0.6.tar.gz lfs:/mnt/lfs/sources$ cd bzip2-1.0.6/ lfs:/mnt/lfs/sources/bzip2-1.0.6$ make lfs:/mnt/lfs/sources/bzip2-1.0.6$ make PREFIX=/tools install lfs:/mnt/lfs/sources/bzip2-1.0.6$ cd .. lfs:/mnt/lfs/sources$ rm -rf bzip2-1.0.6
4.11.coreutils Diffutils file find
coreutils: 這個軟件包包含設置基本屬性的工具,經常使用的chown,是GNU項目中一個很重要的組件,解決操做系統最基本問題, 嚴格說最基本是解決柴米油鹽,醬醋茶也不必定是必須的。 lfs:/mnt/lfs/sources$ tar xf ../downloads/coreutils-8.26.tar.xz lfs:/mnt/lfs/sources$ cd coreutils-8.26/ lfs:/mnt/lfs/sources/coreutils-8.26$ ./configure --prefix=/tools --enable-install-program=hostname #coreutils默認不安裝hostname就返回當前,後續有些測試套件要使用hostname命令,因此安裝coretuils時把它也編譯了 lfs:/mnt/lfs/sources/coreutils-8.26$ time make real 4m8.547s user 3m15.379s sys 0m56.197s lfs:/mnt/lfs/sources/coreutils-8.26$ time make RUN_EXPENSIVE_TESTS=yes check real 11m12.658s user 3m30.002s sys 7m55.864s lfs:/mnt/lfs/sources/coreutils-8.26$ time make install real 0m3.360s user 0m2.312s sys 0m1.262s lfs:/mnt/lfs/sources/coreutils-8.26$ type hostname hostname is /tools/bin/hostname lfs:/mnt/lfs/sources/coreutils-8.26$ cd .. lfs:/mnt/lfs/sources$ rm -rf coreutils-8.26 diffutils lfs:/mnt/lfs/sources$ tar xf ../downloads/diffutils-3.5.tar.xz lfs:/mnt/lfs/sources$ cd diffutils-3.5/ lfs:/mnt/lfs/sources/diffutils-3.5$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/diffutils-3.5$ make lfs:/mnt/lfs/sources/diffutils-3.5$ make check lfs:/mnt/lfs/sources/diffutils-3.5$ make install lfs:/mnt/lfs/sources/diffutils-3.5$ cd .. lfs:/mnt/lfs/sources$ rm -rf diffutils-3.5 file lfs:/mnt/lfs/sources$ tar xf ../downloads/file-5.30.tar.gz lfs:/mnt/lfs/sources$ cd file-5.30/ lfs:/mnt/lfs/sources/file-5.30$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/file-5.30$ make lfs:/mnt/lfs/sources/file-5.30$ make install lfs:/mnt/lfs/sources/file-5.30$ type file file is /tools/bin/file lfs:/mnt/lfs/sources/file-5.30$ cd .. lfs:/mnt/lfs/sources$ rm -rf file-5.30 find lfs:/mnt/lfs/sources$ tar xf ../downloads/findutils-4.6.0.tar.gz lfs:/mnt/lfs/sources$ cd findutils-4.6.0/ lfs:/mnt/lfs/sources/findutils-4.6.0$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/findutils-4.6.0$ make lfs:/mnt/lfs/sources/findutils-4.6.0$ type find find is /bin/find lfs:/mnt/lfs/sources/findutils-4.6.0$ echo $PATH 由於環境變量首先找/tools,找不到再找宿主系統的 /tools/bin:/bin:/usr/bin lfs:/mnt/lfs/sources/findutils-4.6.0$ time make check real 1m10.801s user 0m31.105s sys 0m32.145s lfs:/mnt/lfs/sources/findutils-4.6.0$ time make install real 0m1.538s user 0m1.022s sys 0m0.631s lfs:/mnt/lfs/sources/findutils-4.6.0$ cd .. lfs:/mnt/lfs/sources$ rm -rf findutils-4.6.0
4.12.gawk gettext grep
gawk: g是GNU,awk是文本處理工具,生成報告 lfs:/mnt/lfs/sources$ tar xf ../downloads/gawk-4.1.4.tar.xz lfs:/mnt/lfs/sources$ cd gawk-4.1.4/ lfs:/mnt/lfs/sources/gawk-4.1.4$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/gawk-4.1.4$ make lfs:/mnt/lfs/sources/gawk-4.1.4$ make check make[2]: Leaving directory `/mnt/lfs/sources/gawk-4.1.4/test' 有些警告能夠忽略 make[1]: *** [check] Error 1 make[1]: Leaving directory `/mnt/lfs/sources/gawk-4.1.4/test' make: *** [check-recursive] Error lfs:/mnt/lfs/sources/gawk-4.1.4$ make install lfs:/mnt/lfs/sources/gawk-4.1.4$ cd .. lfs:/mnt/lfs/sources$ rm -rf gawk-4.1.4 gettext 描述:多語言支持的函數庫,如手機的操做系統,把語言設置成中文,微信語言會是中文顯示,若是把操做系統修改爲英文, 微信也會變,它默認是根據操做系統來設置的,這就是多語言,gettext是能夠根據用戶當前語言的環境變量來顯示一些 什麼樣的信息,如它一搜索的如今語言的環境變量是英文,如今就直接顯示英文,若是是簡體中文就看看搜索的程序中的 庫裏面是有沒有這個單詞所針對或者變量所針對的中文,若是沒有中文就返回這個原始的英文的內容 gettext比較以前安裝的組件要多,可是如今是臨時工具鏈能夠不安裝這麼多 lfs:/mnt/lfs/sources$ tar xf ../downloads/gettext-0.19.8.1.tar.xz lfs:/mnt/lfs/sources$ cd gettext-0.19.8.1/gettext-tools/ lfs:/mnt/lfs/sources/gettext-0.19.8.1/gettext-tools$ EMACS="no" ./configure --prefix=/tools --disable-shared #解壓後進入一個子目錄進行configure,EMACS="no"把這個字符編譯器一些個性去掉,並且禁用它的一些動態庫,並且編譯時只須要編譯所須要的 lfs:/mnt/lfs/sources/gettext-0.19.8.1/gettext-tools$ make -C gnulib-lib lfs:/mnt/lfs/sources/gettext-0.19.8.1/gettext-tools$ make -C intl pluralx.c lfs:/mnt/lfs/sources/gettext-0.19.8.1/gettext-tools$ make -C src msgfmt lfs:/mnt/lfs/sources/gettext-0.19.8.1/gettext-tools$ make -C src msgmerge lfs:/mnt/lfs/sources/gettext-0.19.8.1/gettext-tools$ make -C src xgettext lfs:/mnt/lfs/sources/gettext-0.19.8.1/gettext-tools$ cp -v src/{msgfmt,msgmerge,xgettext} /tools/bin lfs:/mnt/lfs/sources/gettext-0.19.8.1/gettext-tools$ cd ../.. lfs:/mnt/lfs/sources$ rm -rf gettext-0.19.8.1 grep lfs:/mnt/lfs/sources$ tar xf ../downloads/grep-3.0.tar.xz lfs:/mnt/lfs/sources$ cd grep-3.0/ lfs:/mnt/lfs/sources/grep-3.0$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/grep-3.0$ make lfs:/mnt/lfs/sources/grep-3.0$ time make check real 0m33.926s user 0m19.127s sys 0m18.063s lfs:/mnt/lfs/sources/grep-3.0$ make install lfs:/mnt/lfs/sources/grep-3.0$ cd .. lfs:/mnt/lfs/sources$ rm -rf grep-3.0
4.13.gzip m4 make
gzip 描述:GNU的zip lfs:/mnt/lfs/sources$ tar xf ../downloads/gzip-1.8.tar.xz lfs:/mnt/lfs/sources$ cd gzip-1.8/ lfs:/mnt/lfs/sources/gzip-1.8$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/gzip-1.8$ make lfs:/mnt/lfs/sources/gzip-1.8$ make check lfs:/mnt/lfs/sources/gzip-1.8$ make install lfs:/mnt/lfs/sources/gzip-1.8$ cd .. lfs:/mnt/lfs/sources$ rm -rf gzip-1.8 M4 描述:宏的預處理器,宏如去超市買一顆口香糖,上面有標籤草莓味,蘋果味的,標籤理解爲這盒口香糖, 打開口香糖盒,把它從盒子倒出來,就是宏的展開,能夠把宏理解爲一個標籤,相似於對某種事物 貼了一上標籤,在編程中提升效率,早期對於彙編時,基本是離不開宏的 M4實際就是用戶輸入一些文本將其進行輸出 lfs:/mnt/lfs/sources$ tar xf ../downloads/m4-1.4.18.tar.xz lfs:/mnt/lfs/sources$ cd m4-1.4.18/ lfs:/mnt/lfs/sources/m4-1.4.18$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/m4-1.4.18$ make lfs:/mnt/lfs/sources/m4-1.4.18$ make check lfs:/mnt/lfs/sources/m4-1.4.18$ make install lfs:/mnt/lfs/sources/m4-1.4.18$ cd .. lfs:/mnt/lfs/sources$ rm -rf m4-1.4.18 make 描述:管理員能夠經過它來編譯安裝不少工具,有兩種作法,一種是make直接回車,還有是後面跟一些相似於參數的, 如check,install等等,能夠理解爲像接收命令行參數同樣,接收目標,這些目標會在makefile裏面,有相應的 描述,makefile是經過configure來生成的,也有可能自己就帶有,make在執行時會掃描makefile,找到目標後 可能有依賴關係,若是找到目標後有依賴關係,依賴自己仍是目標,它會再掃描makefile,來肯定這種依賴關係, 一層層地依賴,最後找到最底層的依賴關係表後,而後進行編譯,最後編譯主目標,能夠在大型的開發項目裏, 把它分割成一個個可管理的模塊,可使用make和makefile來管理各個文件之間很是複雜的關係。若是沒有Make 和makefile,每次都要使用gcc來編譯,對於程序員來講簡直就是一場災難。 #--without-guile這個選項最主要是打斷臨時工具鏈和宿主系統之間的關係,若是不加這個,可能連接到宿主系統上一個叫guile的 #庫,這樣可能會出現問題,能夠理解爲是一種隔離機制,保證了臨時系統和宿主系統之間是獨立的無關的。 lfs:/mnt/lfs/sources$ tar xf ../downloads/make-4.2.1.tar.bz2 lfs:/mnt/lfs/sources$ cd make-4.2.1/ lfs:/mnt/lfs/sources/make-4.2.1$ ./configure --prefix=/tools --without-guile lfs:/mnt/lfs/sources/make-4.2.1$ make lfs:/mnt/lfs/sources/make-4.2.1$ make check lfs:/mnt/lfs/sources/make-4.2.1$ make install lfs:/mnt/lfs/sources/make-4.2.1$ type make make is /tools/bin/make lfs:/mnt/lfs/sources/make-4.2.1$ cd .. lfs:/mnt/lfs/sources$ rm -rf make-4.2.1
4.14.patch perl sed tar
patch: 能過補丁命令來修改或者建立文件的一個程序,補丁文件一般是由diff來生成的,windows一般是 解決一些安全,功能的一些Bug問題,這裏的源代碼的補丁是一種高效率修改源代碼的方法,如在 有一個文件夾a,是源代碼的文件,可能下面還有些子目錄,如何進行高效率的修改,假如把一個 新版本的源代碼放置在b中,步驟: 使用diff命令將a,b兩個文件夾進行比較,把比較的差別寫入另外一個文件中,它就是所說的補丁文件 再使用patch命令來進行打補丁 lfs:/mnt/lfs/sources$ tar xf ../downloads/patch-2.7.5.tar.xz lfs:/mnt/lfs/sources$ cd patch-2.7.5/ lfs:/mnt/lfs/sources/patch-2.7.5$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/patch-2.7.5$ make lfs:/mnt/lfs/sources/patch-2.7.5$ make check lfs:/mnt/lfs/sources/patch-2.7.5$ make install lfs:/mnt/lfs/sources/patch-2.7.5$ cd .. lfs:/mnt/lfs/sources$ rm -rf patch-2.7.5 perl 描述:借鑑了C的一些功能特性,最方即是它的正則表達式功能,還有大量第三方的代碼庫, lfs:/mnt/lfs/sources$ tar xf ../downloads/perl-5.24.1.tar.bz2 lfs:/mnt/lfs/sources$ cd perl-5.24.1/ lfs:/mnt/lfs/sources/perl-5.24.1$ sh Configure -des -Dprefix=/tools -Dlibs=-lm lfs:/mnt/lfs/sources/perl-5.24.1$ make #安裝是一般cp對相關的命令進行復制 lfs:/mnt/lfs/sources/perl-5.24.1$ cp -v perl cpan/podlators/scripts/pod2man /tools/bin lfs:/mnt/lfs/sources/perl-5.24.1$ mkdir -pv /tools/lib/perl5/5.24.1 lfs:/mnt/lfs/sources/perl-5.24.1$ cp -Rv lib/* /tools/lib/perl5/5.24.1 lfs:/mnt/lfs/sources/perl-5.24.1$ cd .. lfs:/mnt/lfs/sources$ rm -rf perl-5.24.1 sed lfs:/mnt/lfs/sources$ tar xf ../downloads/sed-4.4.tar.xz lfs:/mnt/lfs/sources$ cd sed-4.4/ lfs:/mnt/lfs/sources/sed-4.4$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/sed-4.4$ make lfs:/mnt/lfs/sources/sed-4.4$ make check lfs:/mnt/lfs/sources/sed-4.4$ make install lfs:/mnt/lfs/sources/sed-4.4$ cd .. lfs:/mnt/lfs/sources$ rm -rf sed-4.4 tar lfs:/mnt/lfs/sources$ tar xf ../downloads/tar-1.29.tar.xz lfs:/mnt/lfs/sources$ cd tar-1.29/ lfs:/mnt/lfs/sources/tar-1.29$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/tar-1.29$ make lfs:/mnt/lfs/sources/tar-1.29$ make check #時間比較長 lfs:/mnt/lfs/sources/tar-1.29$ make install lfs:/mnt/lfs/sources/tar-1.29$ cd .. lfs:/mnt/lfs/sources$ rm -rf tar-1.29
4.15.texinfo util-linux xz
texinfo 描述:是一個文檔系統,能夠根據單一的源文件同時生成多種在線文檔的版本,根據texinfo能夠建立html,pdf等 lfs:/mnt/lfs/sources$ tar xf ../downloads/texinfo-6.3.tar.xz lfs:/mnt/lfs/sources$ cd texinfo-6.3/ lfs:/mnt/lfs/sources/texinfo-6.3$ ./configure --prefix=/tools #會有報錯,可是能夠忽略 lfs:/mnt/lfs/sources/texinfo-6.3$ make lfs:/mnt/lfs/sources/texinfo-6.3$ make check lfs:/mnt/lfs/sources/texinfo-6.3$ make install lfs:/mnt/lfs/sources/texinfo-6.3$ cd .. lfs:/mnt/lfs/sources$ rm -rf texinfo-6.3 util-linux 描述:包含各類各樣的工具,做爲一個臨時系統須要有一個硬盤驅動器的加載,mount或格式化分區之類, 工具裏包含一堆這種命令。 lfs:/mnt/lfs/sources$ tar xf ../downloads/util-linux-2.29.1.tar.xz lfs:/mnt/lfs/sources$ cd util-linux-2.29.1/ lfs:/mnt/lfs/sources/util-linux-2.29.1$ ./configure --prefix=/tools \ --without-python \ --disable-makeinstall-chown \ --without-systemdsystemunitdir \ PKG_CONFIG="" lfs:/mnt/lfs/sources/util-linux-2.29.1$ make lfs:/mnt/lfs/sources/util-linux-2.29.1$ make install lfs:/mnt/lfs/sources/util-linux-2.29.1$ cd .. lfs:/mnt/lfs/sources$ rm -rf util-linux-2.29.1 xz 描述:壓縮和解壓縮工具 lfs:/mnt/lfs/sources$ tar xf ../downloads/xz-5.2.3.tar.xz lfs:/mnt/lfs/sources$ cd xz-5.2.3/ lfs:/mnt/lfs/sources/xz-5.2.3$ ./configure --prefix=/tools lfs:/mnt/lfs/sources/xz-5.2.3$ make lfs:/mnt/lfs/sources/xz-5.2.3$ make check lfs:/mnt/lfs/sources/xz-5.2.3$ make install lfs:/mnt/lfs/sources/xz-5.2.3$ cd .. lfs:/mnt/lfs/sources$ rm -rf xz-5.2.3
4.16.stripping changowner
stripping 描述:打掃,對於以前的編譯對於臨時系統來講是無用的,是可選的操做,主要的目的是節省lfs的目錄空間 lfs:/mnt/lfs/sources$ df $LFS -h Filesystem Size Used Avail Use% Mounted on /dev/sdb2 32G 2.4G 28G 8% /mnt/lfs lfs:/mnt/lfs/sources$ cd /tools/ lfs:/tools$ du -h --max-depth=1 101M ./share 22M ./include 16K ./var 291M ./lib 865M ./libexec 65M ./x86_64-lfs-linux-gnu 8.0K ./etc 230M ./bin 17M ./sbin 832K ./x86_64-pc-linux-gnu 3.8M ./man 1.6G . 打掃: lfs:/tools$ strip --strip-debug /tools/lib/* lfs:/tools$ /usr/bin/strip --strip-unneeded /tools/{,s}bin/* #特地使用宿主系統的命令來打掃,主要防止使用自己的 lfs:/tools$ rm -rf /tools/{,share}/{info,man,doc} lfs:/tools$ df $LFS -h Filesystem Size Used Avail Use% Mounted on /dev/sdb2 32G 1.9G 28G 7% /mnt/lfs lfs:/tools$ du -h --max-depth=1 71M ./share 22M ./include 16K ./var 144M ./lib 865M ./libexec 23M ./x86_64-lfs-linux-gnu 8.0K ./etc 55M ./bin 3.4M ./sbin 832K ./x86_64-pc-linux-gnu 1.2G . changeowner 描述:在隨後的部分中都是使用root的身份來執行命令,而不是lfs這個普通用戶的身份 lfs:/tools$ ls -ld $LFS/tools drwxr-xr-x 12 lfs root 4096 Jan 7 00:45 /mnt/lfs/tools lfs:/tools$ exit exit [root@node ~]# id uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 [root@node ~]# echo $LFS /mnt/lfs [root@node ~]# ls -ld $LFS/tools drwxr-xr-x. 12 lfs root 4096 Jan 7 08:45 /mnt/lfs/tools [root@node ~]# chown -R root:root $LFS/tools [root@node ~]# ls -ld $LFS/tools drwxr-xr-x. 12 root root 4096 Jan 7 08:45 /mnt/lfs/tools [root@node ~]# tar zcf tools.tar.gz /mnt/lfs/tools 作次備份
小結:已經把臨時系統的臨時工具鏈都完成了,下一步開始作目標系統
5.安裝基本系統軟件
5.1準備虛擬內核文件系統
[root@node ~]# echo $LFS /mnt/lfs [root@node ~]# mkdir -pv $LFS/{dev,proc,sys,run} 建立初始設備節點 描述:device下有不少設備文件,是由udev軟件動態建立的,一開始並不須要建立全部的設備節點,有兩個最基本的設備, 它們必需要在udev建立前就要存在,是/dev/console,/dev/null,不然udev相關的命令就沒法啓動,使用mknode來 手工建立這兩個設備,-m指定設備的模式,許可,使用c,u,b,p來指定類型,c表示面向字符文件的設備,b是表明一個 塊設備,後面的數字是主設備編號和輔助編號, [root@node ~]# mknod -m 600 $LFS/dev/console c 5 1 [root@node ~]# mknod -m 666 $LFS/dev/null c 1 3 [root@node ~]# ls -l $LFS/dev total 0 crw-------. 1 root root 5, 1 Jan 7 09:03 console crw-rw-rw-. 1 root root 1, 3 Jan 7 09:04 null Mounting and Populating /dev 描述:由於沒有udev和引導,要手工進行mount [root@node ~]# mount -v --bind /dev $LFS/dev #在另外一人點建立某個目錄,或掛載點的鏡像 [root@node ~]# ls $LFS/dev 至關於嫁接 agpgart fb0 network_latency sdb2 tty15 tty32 tty5 ttyS0 vcsa2 autofs fd network_throughput sg0 tty16 tty33 tty50 ttyS1 vcsa3 block full null sg1 tty17 tty34 tty51 ttyS2 vcsa4 bsg fuse nvram sg2 tty18 tty35 tty52 ttyS3 vcsa5 btrfs-control hidraw0 oldmem shm tty19 tty36 tty53 uhid vcsa6 bus hpet port snapshot tty2 tty37 tty54 uinput vfio cdrom hugepages ppp snd tty20 tty38 tty55 urandom vga_arbiter char hwrng ptmx sr0 tty21 tty39 tty56 usbmon0 vhci cl initctl pts stderr tty22 tty4 tty57 usbmon1 vhost-net console input random stdin tty23 tty40 tty58 usbmon2 vmci core kmsg raw stdout tty24 tty41 tty59 vcs zero cpu log rfkill tty tty25 tty42 tty6 vcs1 cpu_dma_latency loop-control rtc tty0 tty26 tty43 tty60 vcs2 crash mapper rtc0 tty1 tty27 tty44 tty61 vcs3 disk mcelog sda tty10 tty28 tty45 tty62 vcs4 dm-0 mem sda1 tty11 tty29 tty46 tty63 vcs5 dm-1 midi sda2 tty12 tty3 tty47 tty7 vcs6 dmmidi mqueue sdb tty13 tty30 tty48 tty8 vcsa dri net sdb1 tty14 tty31 tty49 tty9 vcsa1 掛載虛擬文件系統 注:pts是遠程虛擬終端,devpts是遠程虛擬終端設備,這種文件系統與proc文件系統同樣, [root@node ~]# mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620 mount -vt proc proc $LFS/proc mount -vt sysfs sysfs $LFS/sys mount -vt tmpfs tmpfs $LFS/run 注:shm是共享內存,這個目錄是在內存下虛擬出來一個目錄,至關於直接寫內存,
5.2.PkgManagement chroot
軟件包管理 chroot 描述:能夠將製做目錄mount lfs改變爲根目錄,改變程序執行時,所參考的位置,與dns,vsftp中的高級配置有關, 使用chroot來提升守護程序的安全性,這種做法叫作把權利關籠子裏,把系統與其餘文件分開,如運行一個 有可能影響系統或安全的軟件時,這種方法仍是頗有用的。 這裏的chroot是另一個場景:在製做linux操做系統時,會啓宿主操做系統,根據linux的特色,它須要存儲 根,因爲宿主系統始終是在運行的,須要有不少要運行目標系統的命令,就造成了矛盾,爲了解決這個問題就 可使用chroot來更改根目錄的環境,能夠稱爲虛擬根目錄,linux內核在真正啓動時,創建根目錄成爲一個 真正的根目錄,而虛擬根目錄,簡單看就是一個運行的linux系統中能夠存儲多個運行環境,每一個運行環境都 有本身的根目錄,這些運行環境中根目錄稱爲虛擬根目錄,能夠把任何目錄定義爲這個環境的根目錄,好比說 /mnt/lfs這個文件夾,若是在宿主系統中創建一個目錄,在其中存放系統的一些基本的命令,就能夠把這個目 錄稱爲虛擬根目錄,啓用一個新的運行環境,如把宿主系統稱爲環境a,能夠在環境a中創建起新的環境b,環境b 就成爲宿主系統環境a的一個子環境,把a稱爲環境b的一個父環境。 [root@node ~]# mkdir /tom [root@node ~]# ls / bin dev home lib64 mnt proc run srv tmp tools var boot etc lib media opt root sbin sys tom usr ===============================================================================================下一次開始 [root@node ~]# 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 注1:$LFS就是/mnt/lfs,告訴系統說要切換目錄,把/mnt/lfs做爲工做目錄,/tools/bin/env -i是切換到一個新的環境中, 與之前沒有任何關係,避免之前宿主系統中很複雜的環境變量的影響,下面是設置自身的環境變量,把這home目錄, 指定TERM的環境變量,也就是保持原有的默認值,設定一些對終端操做比較緊密的程序,如vim,more,less可以正常 執行,PS1='\u:\w\$ '設置提示符,PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin把/tools放在最後,把/bin 放在最前,由於已經作chroot,/tools/bin/bash --login +h是切換後運行的命令,bash的登陸方式,登陸會運行 /etc/profile文件,和當前用戶下隱藏的.bash_profile的文件,+號是關閉shell中的hash功能,使用shell不要記住 每一個可執行程序的位置,是避免shell緩存影響編譯出來的東西,不是當即生效。 I have no name!:/# ls / #提示沒有名字,chroot後,PS1啓動就是當前用戶,是root,因爲沒有passwd文件,因此不能把id轉換成名稱 dev downloads lost+found proc run sources sys tools 注2:若是作到這裏要重啓過宿主機後,要把掛載和激活/dev,掛載虛擬內核文件系統,和chroot新操做下。
5.3.CreateDir CreateEssFiles
建立目錄 描述:按照LFS系統規範來建立系統,linux與unix的文件系統是一個以正斜槓爲根的樹狀文件結構,正斜槓所以被稱爲根目錄, 全部的文件和目錄都在根下,根目錄下有bin,usr,home等子目錄,在早期unix系統中,各大廠商本身定義本身文件系統的 樹狀結構,比較混亂,爲了不linux也產生了一樣的問題,因此進行FHS文件系統層級標準化的設置,使得linux的發行 版本有一個可追行的標準,使得能夠預測軟件安裝的位置,這個標準就是定義了每一個區域的用途,定義所須要的文件構成 和目錄。 I have no name!:/# #在chroot下作 mkdir -pv /{bin,boot,etc/{opt,sysconfig},home,lib/firmware,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/{color,dict,doc,info,locale,man} mkdir -v /usr/{,local/}share/{misc,terminfo,zoneinfo} mkdir -v /usr/libexec mkdir -pv /usr/{,local/}share/man/man{1..8} case $(uname -m) in x86_64) mkdir -v /lib64 ;; esac mkdir -v /var/{log,mail,spool} ln -sv /run /var/run ln -sv /run/lock /var/lock mkdir -pv /var/{opt,cache,lib/{color,misc,locate},local} 建立必需的文件和符號連接 描述:linux的程序會在代碼裏寫死一些調用,即便這些程序沒有安裝,因此爲了知足這些應用程序的調用須要建立一些文件和符號連接, 後面文件編譯安裝好後,直接經過文件替換這些文件就能夠。 I have no name!:/# ln -sv /tools/bin/{bash,cat,echo,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 sed 's/tools/usr/' /tools/lib/libstdc++.la > /usr/lib/libstdc++.la ln -sv bash /bin/sh I have no name!:/# ln -sv /proc/self/mounts /etc/mtab '/etc/mtab' -> '/proc/self/mounts' 從內核獲取信息,因此這個文件會按期更新 建立passwd文件 I have no name!:/# id 沒有名稱是因爲一直沒找到/etc/passwd這個文件 uid=0 gid=0 groups=0 I have no name!:/# cat > /etc/passwd << "EOF" root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/dev/null:/bin/false daemon:x:6:6:Daemon User:/dev/null:/bin/false messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false nobody:x:99:99:Unprivileged User:/dev/null:/bin/false EOF I have no name!:/# cat > /etc/group << "EOF" root:x:0: bin:x:1:daemon sys:x:2: kmem:x:3: tape:x:4: tty: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: adm:x:16: messagebus:x:18: systemd-journal:x:23: input:x:24: mail:x:34: nogroup:x:99: users:x:999: EOF I have no name!:/# exec /tools/bin/bash --login +h root:/# id uid=0(root) gid=0(root) groups=0(root) 設置日誌文件權限 root:/# touch /var/log/{btmp,lastlog,faillog,wtmp} chgrp -v utmp /var/log/lastlog chmod -v 664 /var/log/lastlog chmod -v 600 /var/log/btmp
5.4.APIHeaders man
描述:編譯安裝linux下各類軟件包,組成所須要的linux系統,須要完成工具鏈而後再經過工具鏈來製做其餘的軟件包, 安裝linux頭文件是由於爲glibc與其餘與內核相關的軟件時,就須要這個平臺的結合的接口信息,保證全部編譯 出來的程序和函數,能夠運行在這個平臺的內核上,因此須要從內核的源代碼中抽取描述內核接口的頭文件。 首先對環境的打掃,而後進行檢查 root:/# cd /sources/ root:/sources# tar xf /downloads/linux-4.9.9.tar.xz root:/sources# cd linux-4.9.9/ root:/sources/linux-4.9.9# make mrproper #清理主要是保證沒有遺留文件和錯誤的依賴關係 root:/sources/linux-4.9.9# make INSTALL_HDR_PATH=dest headers_install #若是直接使用頭的安裝會把目標文件夾裏都清除後才安裝,爲了穩定INSTALL_HDR_PATH=dest建立這個文件夾,把頭文件抽取到裏面 root:/sources/linux-4.9.9# find dest/include \( -name .install -o -name ..install.cmd \) -delete #刪除一些無用的命令 root:/sources/linux-4.9.9# cp -rv dest/include/* /usr/include root:/sources/linux-4.9.9# cd .. root:/sources# rm -rf linux-4.9.9 man安裝 root:/sources# tar xf /downloads/man-pages-4.09.tar.xz root:/sources# cd man-pages-4.09/ root:/sources/man-pages-4.09# make install root:/sources/man-pages-4.09# cd .. root:/sources# rm -rf man-pages-4.09
5.5.glibc
描述:linux的基本C庫,linux中不少軟件都是由C來寫的,要編譯運行這些軟件就要的一個C庫,glibc提供的C庫是一個最全面的 C庫,包含主要的C函數實現,如分配內核搜索目錄,打開關閉文件, root:/sources# time tar xf /downloads/glibc-2.25.tar.xz real 0m2.831s user 0m0.169s sys 0m3.303s root:/sources# cd glibc-2.25/ root:/sources/glibc-2.25# patch -Np1 -i /downloads/glibc-2.25-fhs-1.patch 先打補丁 #case是根據LSB的要求,來建立一些符號連接, root:/sources/glibc-2.25# case $(uname -m) in x86) ln -s ld-linux.so.2 /lib/ld-lsb.so.3 ;; x86_64) ln -s ../lib/ld-linux-x86-64.so.2 /lib64 ln -s ../lib/ld-linux-x86-64.so.2 /lib64/ld-lsb-x86-64.so.3 ;; esac root:/sources/glibc-2.25# mkdir build root:/sources/glibc-2.25# cd build/ root:/sources/glibc-2.25/build# time ../configure --prefix=/usr \ --enable-kernel=2.6.32 \ --enable-obsolete-rpc \ --enable-stack-protector=strong \ libc_cv_slibdir=/lib root:/sources/glibc-2.25/build# time make root:/sources/glibc-2.25/build# time make check #因爲glibc很重要,因此在任何狀況下都不要跳過這個測試 real 140m11.009s user 84m37.000s sys 57m50.732s root:/sources/glibc-2.25/build# touch /etc/ld.so.conf #建立一個空的文件,避免安裝glibc時有警告 root:/sources/glibc-2.25/build# time make install real 4m17.216s user 3m5.504s sys 1m0.080s root:/sources/glibc-2.25/build# cp -v ../nscd/nscd.conf /etc/nscd.conf root:/sources/glibc-2.25/build# mkdir -pv /var/cache/nscd #nscd: name service cache daemon名稱服務調整緩存守護進程,爲名稱解析服務提供調整緩存 #linux有大量的語言是國際化的信息顯示,它能夠根據不一樣的語言設置顯示出對應的語言信息,不一樣的語言有各自的編碼方式, #如中文gbk,國際通行的utf-8等,多種編碼方式,爲了在不一樣編碼中正確顯示文字,glibc提供編碼映射文件localedef root:/sources/glibc-2.25/build# mkdir -pv /usr/lib/locale localedef -i cs_CZ -f UTF-8 cs_CZ.UTF-8 localedef -i de_DE -f ISO-8859-1 de_DE localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro localedef -i de_DE -f UTF-8 de_DE.UTF-8 localedef -i en_GB -f UTF-8 en_GB.UTF-8 localedef -i en_HK -f ISO-8859-1 en_HK localedef -i en_PH -f ISO-8859-1 en_PH localedef -i en_US -f ISO-8859-1 en_US localedef -i en_US -f UTF-8 en_US.UTF-8 localedef -i es_MX -f ISO-8859-1 es_MX localedef -i fa_IR -f UTF-8 fa_IR localedef -i fr_FR -f ISO-8859-1 fr_FR localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro localedef -i fr_FR -f UTF-8 fr_FR.UTF-8 localedef -i it_IT -f ISO-8859-1 it_IT localedef -i it_IT -f UTF-8 it_IT.UTF-8 localedef -i ja_JP -f EUC-JP ja_JP localedef -i ru_RU -f KOI8-R ru_RU.KOI8-R localedef -i ru_RU -f UTF-8 ru_RU.UTF-8 localedef -i tr_TR -f UTF-8 tr_TR.UTF-8 localedef -i zh_CN -f GB18030 zh_CN.GB18030 root:/sources/glibc-2.25/build# head ../localedata/SUPPORTED # This file names the currently supported and somewhat tested locales. # If you have any additions please file a glibc bug report. SUPPORTED-LOCALES=\ aa_DJ.UTF-8/UTF-8 \ aa_DJ/ISO-8859-1 \ aa_ER/UTF-8 \ aa_ER@saaho/UTF-8 \ aa_ET/UTF-8 \ af_ZA.UTF-8/UTF-8 \ af_ZA/ISO-8859-1 \ root:/sources/glibc-2.25/build# make localedata/install-locales zu_ZA.ISO-8859-1... done make[2]: Leaving directory '/sources/glibc-2.25/localedata' make[1]: Leaving directory '/sources/glibc-2.25' #對於glibc的安裝有兩個,一個是make install安裝glibc核心組件自己,這個是安裝一些國際化支持的 nsswitch 描述:名稱服務切換的配置,它決定按什麼樣的方式,信息來查找特定信息,如查找用戶在passwd中,口令在shadow中, 經過什麼來作,這是nsswitch. root:/sources/glibc-2.25/build# 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 time zone 描述: 添加時區 root:/sources/glibc-2.25/build# root:/sources/glibc-2.25/build# tar xf /downloads/tzdata2016j.tar.gz ZONEINFO=/usr/share/zoneinfo mkdir -pv $ZONEINFO/{posix,right} for tz in etcetera southamerica northamerica europe africa antarctica \ asia australasia backward pacificnew systemv; do zic -L /dev/null -d $ZONEINFO -y "sh yearistype.sh" ${tz} zic -L /dev/null -d $ZONEINFO/posix -y "sh yearistype.sh" ${tz} zic -L leapseconds -d $ZONEINFO/right -y "sh yearistype.sh" ${tz} done cp -v zone.tab zone1970.tab iso3166.tab $ZONEINFO zic -d $ZONEINFO -p America/New_York unset ZONEINFO 選擇與本身匹配的時區: root:/sources/glibc-2.25/build# tzselect #? 4 #? 9 #? 1 #? 1 can use the /usr/bin/tzselect command in shell scripts: Asia/Shanghai root:/sources/glibc-2.25/build# cp -v /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 動態加載器 描述:glibc共享庫查詢的目錄是/lib或/usr/lib,若是不在這個下面,動態加載器爲搜索/etc/ld.so.conf這個配置文件 root:/sources/glibc-2.25/build# cat > /etc/ld.so.conf << "EOF" # Begin /etc/ld.so.conf /usr/local/lib /opt/lib EOF
5.6.調整工具鏈
描述:讓新的程序都鏈接到這個新的glibc上,把/tools下lib恢復到根下的lib下,要調整頭文件,把修改好的配置文件放置到這個目錄中,要覆蓋默認配置的目錄中,如今使用的gcc仍是臨時系統的gcc, #先作備份: root:/# mv -v /tools/bin/{ld,ld-old} mv -v /tools/$(uname -m)-pc-linux-gnu/bin/{ld,ld-old} mv -v /tools/bin/{ld-new,ld} ln -sv /tools/bin/ld /tools/$(uname -m)-pc-linux-gnu/bin/ld #在dirname $(gcc --print-libgcc-file-name)這個目錄下建立gcc的定義文件,在specs目錄中修改配置 #就是把原有的gcc默認配置都指向根下的東西,所有修改成根下lib,/usr/include等 root:/# gcc -dumpspecs | sed -e 's@/tools@@g' \ -e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \ -e '/\*cpp:/{n;s@$@ -isystem /usr/include@}' > \ `dirname $(gcc --print-libgcc-file-name)`/specs root:/# cat `dirname $(gcc --print-libgcc-file-name)`/specs | grep tools #檢查,沒返回,證實正確 測試: root:/# echo 'int main(){}' > dummy.c cc dummy.c -v -Wl,--verbose &> dummy.log readelf -l a.out | grep ': /lib' 結果: [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] 已經不是/tools下是根下 root:/# grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log /usr/lib/../lib/crt1.o succeeded /usr/lib/../lib/crti.o succeeded /usr/lib/../lib/crtn.o succeeded root:/# grep -B1 '^ /usr/include' dummy.log #include <...> search starts here: /usr/include ### root:/# grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g' SEARCH_DIR("=/tools/x86_64-pc-linux-gnu/lib64") SEARCH_DIR("/usr/lib") SEARCH_DIR("/lib") SEARCH_DIR("=/tools/x86_64-pc-linux-gnu/lib"); root:/# grep "/lib.*/libc.so.6 " dummy.log attempt to open /lib/libc.so.6 succeeded root:/# grep found dummy.log found ld-linux-x86-64.so.2 at /lib/ld-linux-x86-64.so.2 刪除無用的文件: root:/# rm -v dummy.c a.out dummy.log removed 'dummy.c' removed 'a.out' removed 'dummy.log' zlib 描述:zip格式的支持庫,在GNU的linux包括有大量zip格式的應用,有不少學有源碼包採用zip的壓縮格式, 如今要安裝是由於在後面的binutils中會使用zip的壓縮,還會使用一些判斷文件類型的file. root:~# cd /sources/ root:/sources# ls root:/sources# tar xf /downloads/zlib-1.2.11.tar.xz root:/sources# cd zlib-1.2.11/ root:/sources/zlib-1.2.11# ./configure --prefix=/usr root:/sources/zlib-1.2.11# make root:/sources/zlib-1.2.11# make check root:/sources/zlib-1.2.11# make install root:/sources/zlib-1.2.11# mv -v /usr/lib/libz.so.* /lib root:/sources/zlib-1.2.11# ln -sfv ../../lib/$(readlink /usr/lib/libz.so) /usr/lib/libz.so root:/sources/zlib-1.2.11# cd .. root:/sources# rm -rf zlib-1.2.11/ file 描述:對文件類型檢查,主要是binutils要使用 root:/sources# tar xf /downloads/file-5.30.tar.gz root:/sources# cd file-5.30/ root:/sources/file-5.30# ./configure --prefix=/usr root:/sources/file-5.30# make root:/sources/file-5.30# make check root:/sources/file-5.30# make install root:/sources/file-5.30# cd .. root:/sources# rm -rf file-5.30
5.7.binutils
描述:二進制的處理工具,包括鏈接器,彙編器等一些處理工具,gcc對源文件進行編譯產生彙編文件, 就須要有bintuils等工具來把彙編文件進行編碼和連接函數庫,最終可以實現計算機能識別的 二進制文件,此次編譯正式替代臨時系統中的bintuils root:/sources# tar xf /downloads/binutils-2.27.tar.bz2 root:/sources# expect -c "spawn ls" spawn ls #結果正常,測試在chroot的環境中pdy是否正常 root:/sources# cd binutils-2.27/ root:/sources/binutils-2.27# mkdir build root:/sources/binutils-2.27# cd build root:/sources/binutils-2.27/build# ../configure --prefix=/usr \ --enable-gold \ --enable-ld=default \ --enable-plugins \ --enable-shared \ --disable-werror \ --with-system-zlib #使用系統安裝的zlib庫,而不是使用binutils的 root:/sources/binutils-2.27/build# make tooldir=/usr root:/sources/binutils-2.27/build# time make -k check real 7m32.870s user 3m50.012s sys 3m6.732s root:/sources/binutils-2.27/build# make tooldir=/usr install
5.8.GMP mpfr mpc
描述:三個數學算法庫 GMP root:/sources# tar xf /downloads/gmp-6.1.2.tar.xz root:/sources# cd gmp-6.1.2/ root:/sources/gmp-6.1.2# ./configure --prefix=/usr \ --enable-cxx \ --disable-static \ --docdir=/usr/share/doc/gmp-6.1.2 root:/sources/gmp-6.1.2# make root:/sources/gmp-6.1.2# make html #生成html文檔 #檢查 root:/sources/gmp-6.1.2# make check 2>&1 | tee gmp-check-log root:/sources/gmp-6.1.2# awk '/# PASS:/{total+=$3} ; END{print total}' gmp-check-log 190 #正常是190 #安裝 root:/sources/gmp-6.1.2# make install root:/sources/gmp-6.1.2# make install-html 清除文件: root:/sources/gmp-6.1.2# cd .. root:/sources# rm -rf gmp-6.1.2 mpfr: 多精度的數據函數 root:/sources# tar xf /downloads/mpfr-3.1.5.tar.xz root:/sources# cd mpfr-3.1.5/ root:/sources/mpfr-3.1.5# time ./configure --prefix=/usr \ --disable-static \ --enable-thread-safe \ --docdir=/usr/share/doc/mpfr-3.1.5 root:/sources/mpfr-3.1.5# make root:/sources/mpfr-3.1.5# make html root:/sources/mpfr-3.1.5# make check root:/sources/mpfr-3.1.5# make install root:/sources/mpfr-3.1.5# make install-html root:/sources/mpfr-3.1.5# cd .. root:/sources# rm -rf mpfr-3.1.5/ mpc root:/sources# tar xf /downloads/mpc-1.0.3.tar.gz root:/sources# cd mpc-1.0.3/ root:/sources/mpc-1.0.3# ./configure --prefix=/usr \ --disable-static \ --docdir=/usr/share/doc/mpc-1.0.3 root:/sources/mpc-1.0.3# make root:/sources/mpc-1.0.3# make html root:/sources/mpc-1.0.3# make check root:/sources/mpc-1.0.3# make install root:/sources/mpc-1.0.3# make install-html root:/sources/mpc-1.0.3# cd .. root:/sources# rm -rf mpc-1.0.3/
5.9.gcc
描述:爲目錄系統提供一個長期的編譯器,它是目標系統工具鏈製做中關鍵的一環 root:/sources# time tar xf /downloads/gcc-6.3.0.tar.bz2 real 0m40.585s user 0m16.110s sys 0m28.022s root:/sources# cd gcc-6.3.0/ root:/sources/gcc-6.3.0# #做檢查:是x86_64須要經過sed來修改庫認證的路徑來搜索 case $(uname -m) in x86_64) sed -e '/m64=/s/lib64/lib/' \ -i.orig gcc/config/i386/t-linux64 ;; esac root:/sources/gcc-6.3.0# mkdir -v build root:/sources/gcc-6.3.0# cd build root:/sources/gcc-6.3.0/build# time SED=sed \ ../configure --prefix=/usr \ --enable-languages=c,c++ \ --disable-multilib \ --disable-bootstrap \ --with-system-zlib real 0m7.363s user 0m1.456s sys 0m1.770s root:/sources/gcc-6.3.0/build# time make real 25m51.756s user 21m42.762s sys 3m29.609s 第二次嘗試: real 92m23.528s user 80m29.269s sys 11m39.052s 第三次嘗試:把內存加大到8G real 26m54.116s user 21m42.774s sys 4m57.316s 第四次嘗試:make clean後執行 real 20m25.829s user 18m23.791s sys 1m45.858s root:/sources/gcc-6.3.0/build# ulimit -s 32768 root:/sources/gcc-6.3.0/build# time make -k check #估計大概140多分鐘 real 186m43.917s user 133m29.693s sys 55m32.102s root:/sources/gcc-6.3.0/build# ../contrib/test_summary #查看測試結果組件,若是結果與url差異比較大可能要做檢查 root:/sources/gcc-6.3.0/build# time make install real 0m34.150s user 0m5.520s sys 0m10.209s root:/sources/gcc-6.3.0/build# ln -sv ../usr/bin/cpp /lib #gcc有些組件指望安裝在lib下,因此要作軟連接 root:/sources/gcc-6.3.0/build# ln -sv gcc /usr/bin/cc root:/sources/gcc-6.3.0/build# install -v -dm755 /usr/lib/bfd-plugins ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/6.3.0/liblto_plugin.so \ /usr/lib/bfd-plugins/ #測試: echo 'int main(){}' > dummy.c cc dummy.c -v -Wl,--verbose &> dummy.log readelf -l a.out | grep ': /lib' 結果:[Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] #分析log root:/sources/gcc-6.3.0/build# grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../lib/crt1.o succeeded /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../lib/crti.o succeeded /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../lib/crtn.o succeeded root:/sources/gcc-6.3.0/build# grep -B4 '^ /usr/include' dummy.log #include <...> search starts here: /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include /usr/local/include /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include-fixed /usr/include root:/sources/gcc-6.3.0/build# rm -v dummy.c a.out dummy.log #刪除無用的文件 root:/sources/gcc-6.3.0/build# mkdir -pv /usr/share/gdb/auto-load/usr/lib root:/sources/gcc-6.3.0/build# mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib 清除目錄: root:/sources/gcc-6.3.0/build# cd ../../ root:/sources# rm -rf gcc-6.3.0
5.10.bzip2 pkgconfig ncurse
bzip2是用來壓縮和解壓縮 root:/sources# tar xf /downloads/bzip2-1.0.6.tar.gz root:/sources# cd bzip2-1.0.6/ root:/sources/bzip2-1.0.6# patch -Np1 -i /downloads/bzip2-1.0.6-install_docs-1.patch patching file Makefile #先打補丁 root:/sources/bzip2-1.0.6# sed -i 's@\(ln -s -f \)$(PREFIX)/bin/@\1@' Makefile #修改Makefile,保證符號連接是一個相對連接 root:/sources/bzip2-1.0.6# sed -i "s@(PREFIX)/man@(PREFIX)/share/man@g" Makefile #修改man的按位置 root:/sources/bzip2-1.0.6# make -f Makefile-libbz2_so #編譯出來libz2.so的庫,並連接到bzip2中 root:/sources/bzip2-1.0.6# ls -l libbz2.so.1.0 lrwxrwxrwx 1 root root 15 Jan 7 16:32 libbz2.so.1.0 -> libbz2.so.1.0.6 root:/sources/bzip2-1.0.6# ls -l bzip2-shared -rwxr-xr-x 1 root root 83272 Jan 7 16:32 bzip2-shared root:/sources/bzip2-1.0.6# make clean #須要後續有一個乾淨的環境 root:/sources/bzip2-1.0.6# make root:/sources/bzip2-1.0.6# make PREFIX=/usr install #安裝,並指定安裝目錄 root:/sources/bzip2-1.0.6# 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 root:/sources/bzip2-1.0.6# cd .. root:/sources# rm -rf bzip2-1.0.6 Pkg-config: 是一個軟件包安裝信息的讀取工具,這些信息是包含在.pc後綴的文件中,pkg-config能夠 很方便獲取某個軟件的安裝配置信息,對於lfs來講只是使用其中的一個文件,這個文件能夠配置與makefile 運行時把include和tool的路徑傳遞給編譯工具。 root:/sources# tar xf /downloads/pkg-config-0.29.1.tar.gz root:/sources# cd pkg-config-0.29.1/ root:/sources/pkg-config-0.29.1# ./configure --prefix=/usr \ --with-internal-glib \ --disable-compile-warnings \ --disable-host-tool \ --docdir=/usr/share/doc/pkg-config-0.29.1 root:/sources/pkg-config-0.29.1# time make real 0m29.965s user 0m24.769s sys 0m5.832s root:/sources/pkg-config-0.29.1# time make check real 0m2.076s user 0m1.152s sys 0m1.256s root:/sources/pkg-config-0.29.1# time make install real 0m0.383s user 0m0.238s sys 0m0.213s root:/sources/pkg-config-0.29.1# cd .. root:/sources# rm -rf pkg-config-0.29.1/ Ncurses:窗口的一些函數庫,提供一些窗口,按鈕等界面元素 root:/sources# tar xf /downloads/ncurses-6.0.tar.gz root:/sources# cd ncurses-6.0/ root:/sources/ncurses-6.0# sed -i '/LIBTOOL_INSTALL/d' c++/Makefile.in #不安裝靜態連接庫 root:/sources/ncurses-6.0# ./configure --prefix=/usr \ --mandir=/usr/share/man \ --with-shared \ --without-debug \ --without-normal \ --enable-pc-files \ --enable-widec root:/sources/ncurses-6.0# make root:/sources/ncurses-6.0# make install root:/sources/ncurses-6.0# mv -v /usr/lib/libncursesw.so.6* /lib #對一些文件位置的調整 root:/sources/ncurses-6.0# ln -sfv ../../lib/$(readlink /usr/lib/libncursesw.so) /usr/lib/libncursesw.so root:/sources/ncurses-6.0# 有些小程序搜索些非寬字符的ncurses的庫,因此經過符號連接來解決這個問題 for lib in 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}w.pc /usr/lib/pkgconfig/${lib}.pc done #如下是與早期應用相關聯的 root:/sources/ncurses-6.0# rm -vf /usr/lib/libcursesw.so echo "INPUT(-lncursesw)" > /usr/lib/libcursesw.so ln -sfv libncurses.so /usr/lib/libcurses.so #安裝相應ncureses的文檔 root:/sources/ncurses-6.0# mkdir -v /usr/share/doc/ncurses-6.0 cp -v -R doc/* /usr/share/doc/ncurses-6.0 清除目錄: root:/sources/ncurses-6.0# cd .. root:/sources# rm -rf ncurses-6.0
5.11.Attr acl libcap sed
attr: 管理文件系統的擴展屬性 root:/sources# tar xf /downloads/attr-2.4.47.src.tar.gz root:/sources# cd attr-2.4.47/ root:/sources/attr-2.4.47# sed -i -e 's|/@pkg_name@|&-@pkg_version@|' include/builddefs.in ##加些版本信息 root:/sources/attr-2.4.47# sed -i -e "/SUBDIRS/s|man[25]||g" man/Makefile #中止再次安裝man幫助 root:/sources/attr-2.4.47# ./configure --prefix=/usr \ --bindir=/bin \ --disable-static root:/sources/attr-2.4.47# make root:/sources/attr-2.4.47# make -j1 tests root-tests 29 commands (14 passed, 15 failed) ##check,這些錯誤能夠先忽略 make[1]: *** [Makefile:46: root/getfattr.test] Error 15 make[1]: Leaving directory '/sources/attr-2.4.47/test' make: *** [Makefile:116: root-tests] Error 2 root:/sources/attr-2.4.47# make install install-dev install-lib root:/sources/attr-2.4.47# chmod -v 755 /usr/lib/libattr.so mode of '/usr/lib/libattr.so' changed from 0644 (rw-r--r--) to 0755 (rwxr-xr-x) root:/sources/attr-2.4.47# mv -v /usr/lib/libattr.so.* /lib #把庫修改到所但願的/lib下 root:/sources/attr-2.4.47# ln -sfv ../../lib/$(readlink /usr/lib/libattr.so) /usr/lib/libattr.so root:/sources/attr-2.4.47# cd .. root:/sources# rm -rf attr-2.4.47 Acl:控制文件訪問列表工具,linux中是經過owner,group,others來控制的,若是要經過更細粒度控制就要使用acl root:/sources# tar xf /downloads/acl-2.2.52.src.tar.gz root:/sources# cd acl-2.2.52/ root:/sources/acl-2.2.52# sed -i -e 's|/@pkg_name@|&-@pkg_version@|' include/builddefs.in root:/sources/acl-2.2.52# sed -i "s:| sed.*::g" test/{sbits-restore,cp,misc}.test root:/sources/acl-2.2.52# sed -i -e "/TABS-1;/a if (x > (TABS-1)) x = (TABS-1);" \ libacl/__acl_to_any_text.c root:/sources/acl-2.2.52# ./configure --prefix=/usr \ --bindir=/bin \ --disable-static \ --libexecdir=/usr/lib root:/sources/acl-2.2.52# make root:/sources/acl-2.2.52# make install install-dev install-lib root:/sources/acl-2.2.52# chmod -v 755 /usr/lib/libacl.so mode of '/usr/lib/libacl.so' changed from 0644 (rw-r--r--) to 0755 (rwxr-xr-x) root:/sources/acl-2.2.52# mv -v /usr/lib/libacl.so.* /lib root:/sources/acl-2.2.52# ln -sfv ../../lib/$(readlink /usr/lib/libacl.so) /usr/lib/libacl.so root:/sources/acl-2.2.52# cd .. root:/sources# rm -rf acl-2.2.52/ libcap: cap是capture前三個字母,是在linux與unix下對網絡抓包的一個函數庫,不少的網絡軟件都是 以它爲基礎的,使用的tcpdump,wireshark都是使用這個包。 root:/sources# tar xf /downloads/libcap-2.25.tar.xz root:/sources# cd libcap-2.25/ root:/sources/libcap-2.25# sed -i '/install.*STALIBNAME/d' libcap/Makefile root:/sources/libcap-2.25# make root:/sources/libcap-2.25# make RAISE_SETFCAP=no lib=lib prefix=/usr install root:/sources/libcap-2.25# chmod -v 755 /usr/lib/libcap.so root:/sources/libcap-2.25# mv -v /usr/lib/libcap.so.* /lib root:/sources/libcap-2.25# ln -sfv ../../lib/$(readlink /usr/lib/libcap.so) /usr/lib/libcap.so root:/sources/libcap-2.25# cd .. root:/sources# rm -rf libcap-2.25/ sed: 文本流的編輯器,能夠將文本文件,字符串編輯後一系列的輸出,在整個製做過程當中是最經常使用的工具, 因此要在目標系統中安裝sed. root:/sources# tar xf /downloads/sed-4.4.tar.xz root:/sources# cd sed-4.4/ root:/sources/sed-4.4# sed -i 's/usr/tools/' build-aux/help2man root:/sources/sed-4.4# sed -i 's/panic-tests.sh//' Makefile.in root:/sources/sed-4.4# ./configure --prefix=/usr --bindir=/bin root:/sources/sed-4.4# make root:/sources/sed-4.4# make html root:/sources/sed-4.4# make check root:/sources/sed-4.4# make install #調整文件對象的權限 root:/sources/sed-4.4# install -d -m755 /usr/share/doc/sed-4.4 root:/sources/sed-4.4# install -m644 doc/sed.html /usr/share/doc/sed-4.4 root:/sources/sed-4.4# cd .. root:/sources# rm -rf sed-4.4/
5.12.shadow psmis ianaetc m4
shadow: /etc/shadow是存放密碼的地方,與它相關的軟件都在shadow的文件包中。 root:/sources# tar xf /downloads/shadow-4.4.tar.xz root:/sources# cd shadow-4.4/ root:/sources/shadow-4.4# sed -i 's/groups$(EXEEXT) //' src/Makefile.in #不安裝group程序,隨後安裝的,比這個group更好 find man -name Makefile.in -exec sed -i 's/groups\.1 / /' {} \; find man -name Makefile.in -exec sed -i 's/getspnam\.3 / /' {} \; find man -name Makefile.in -exec sed -i 's/passwd\.5 / /' {} \; #加密算法的調整: root:/sources/shadow-4.4# sed -i -e 's@#ENCRYPT_METHOD DES@ENCRYPT_METHOD SHA512@' \ -e 's@/var/spool/mail@/var/mail@' etc/login.defs #修改src下的useradd.c的文件,解決一個bug問題 root:/sources/shadow-4.4# echo '--- src/useradd.c (old) +++ src/useradd.c (new) @@ -2027,6 +2027,8 @@ is_shadow_grp = sgr_file_present (); #endif + get_defaults (); + process_flags (argc, argv); #ifdef ENABLE_SUBIDS @@ -2036,8 +2038,6 @@ (!user_id || (user_id <= uid_max && user_id >= uid_min)); #endif /* ENABLE_SUBIDS */ - get_defaults (); - #ifdef ACCT_TOOLS_SETUID #ifdef USE_PAM {' | patch -p0 -l #可選操做,若是要啓用cracklib就作 sed -i 's@DICTPATH.*@DICTPATH\t/lib/cracklib/pw_dict@' etc/login.defs root:/sources/shadow-4.4# sed -i 's/1000/999/' etc/useradd root:/sources/shadow-4.4# sed -i -e '47 d' -e '60,65 d' libmisc/myname.c #修復一些安全性問題 root:/sources/shadow-4.4# ./configure --sysconfdir=/etc --with-group-name-max-length=32 root:/sources/shadow-4.4# make root:/sources/shadow-4.4# make install root:/sources/shadow-4.4# mv -v /usr/bin/passwd /bin #調整文件的位置 #啓用shadow密碼 root:/sources/shadow-4.4# pwconv root:/sources/shadow-4.4# grpconv root:/sources/shadow-4.4# sed -i 's/yes/no/' /etc/default/useradd root:/sources/shadow-4.4# grep POOL /etc/default/useradd CREATE_MAIL_SPOOL=no #把yes修改爲no #設置lfs目標系統的root密碼: root:/sources/shadow-4.4# passwd root root:/sources/shadow-4.4# cd .. root:/sources# rm -rf shadow-4.4/ psmisc: ps是進程,misc是雜項,pstree,killall都是這個軟件包 root:/sources# tar xf /downloads/psmisc-22.21.tar.gz root:/sources# cd psmisc-22.21/ root:/sources/psmisc-22.21# ./configure --prefix=/usr root:/sources/psmisc-22.21# make root:/sources/psmisc-22.21# make install root:/sources/psmisc-22.21# mv -v /usr/bin/fuser /bin root:/sources/psmisc-22.21# mv -v /usr/bin/killall /bin root:/sources/psmisc-22.21# cd .. root:/sources# rm -rf psmisc-22.21 iana-etc: iana是一個很牛的機構,全名是互聯網數字分配機構,負責協調互聯網上的一些運行,衝突的協商, 域名是它們負責,一些數字資源包括IP,一些關於協議的分配,如協議使用什麼端口號,因此這個 文件主要是拷/etc的協議文件和服務文件。 root:/sources# tar xf /downloads/iana-etc-2.30.tar.bz2 root:/sources# cd iana-etc-2.30/ root:/sources/iana-etc-2.30# make root:/sources/iana-etc-2.30# make install root:/sources/iana-etc-2.30# cd .. root:/sources# rm -rf iana-etc-2.30/ M4: 包含宏的處理器 root:/sources# tar xf /downloads/m4-1.4.18.tar.xz root:/sources# cd m4-1.4.18/ root:/sources/m4-1.4.18# ./configure --prefix=/usr root:/sources/m4-1.4.18# make root:/sources/m4-1.4.18# make check root:/sources/m4-1.4.18# make install root:/sources/m4-1.4.18# cd .. root:/sources# rm -rf m4-1.4.18/
5.13. bison flex grep readline
bison: 文本結構的分析程序,用來替代yacc,語法分析 root:/sources# tar xf /downloads/bison-3.0.4.tar.xz root:/sources# cd bison-3.0.4/ root:/sources/bison-3.0.4# ./configure --prefix=/usr --docdir=/usr/share/doc/bison-3.0.4 root:/sources/bison-3.0.4# make root:/sources/bison-3.0.4# make install root:/sources/bison-3.0.4# cd .. root:/sources# rm -rf bison-3.0.4/ flex: 包含識別文本模式的程序 root:/sources# tar xf /downloads/flex-2.6.3.tar.gz root:/sources# cd flex-2.6.3/ root:/sources/flex-2.6.3# HELP2MAN=/tools/bin/true \ ./configure --prefix=/usr --docdir=/usr/share/doc/flex-2.6.3 root:/sources/flex-2.6.3# make root:/sources/flex-2.6.3# make check #會有一些已經的測試問題,能夠忽略 root:/sources/flex-2.6.3# make install root:/sources/flex-2.6.3# ln -sv flex /usr/bin/lex root:/sources/flex-2.6.3# cd .. root:/sources# rm -rf flex-2.6.3/ grep root:/sources# tar xf /downloads/grep-3.0.tar.xz root:/sources# cd grep-3.0/ root:/sources/grep-3.0# ./configure --prefix=/usr --bindir=/bin root:/sources/grep-3.0# make root:/sources/grep-3.0# make check root:/sources/grep-3.0# make install root:/sources/grep-3.0# cd .. root:/sources# rm -rf grep-3.0/ readline: 提供命令,歷史功能的庫的集合 root:/sources# tar xf /downloads/readline-7.0.tar.gz root:/sources# cd readline-7.0/ root:/sources/readline-7.0# sed -i '/MV.*old/d' Makefile.in root:/sources/readline-7.0# sed -i '/{OLDSUFF}/c:' support/shlib-install root:/sources/readline-7.0# ./configure --prefix=/usr \ --disable-static \ --docdir=/usr/share/doc/readline-7.0 root:/sources/readline-7.0# make SHLIB_LIBS=-lncurses root:/sources/readline-7.0# make SHLIB_LIBS=-lncurses install root:/sources/readline-7.0# 把庫文件移動了,因此要把相應的符號連接進行調整 mv -v /usr/lib/lib{readline,history}.so.* /lib ln -sfv ../../lib/$(readlink /usr/lib/libreadline.so) /usr/lib/libreadline.so ln -sfv ../../lib/$(readlink /usr/lib/libhistory.so ) /usr/lib/libhistory.so #可選,與文檔相關 root:/sources/readline-7.0# install -v -m644 doc/*.{ps,pdf,html,dvi} /usr/share/doc/readline-7.0 root:/sources/readline-7.0# cd .. root:/sources# rm -rf readline-7.0/
5.14.bash bc libtool gdbm
bash: 用戶在linux終端下操做系統,須要使用shell交互環境,bash就是一種經常使用的shell,如今製做是目標系統所使用的bash shell root:/sources# tar xf /downloads/bash-4.4.tar.gz root:/sources# cd bash-4.4/ root:/sources/bash-4.4# patch -Np1 -i /downloads/bash-4.4-upstream_fixes-1.patch #打補丁 root:/sources/bash-4.4# 不使用bash自帶的內存分配的函數,而使用glibc的,使用系統安裝的readline,不使用自帶的 ./configure --prefix=/usr \ --docdir=/usr/share/doc/bash-4.4 \ --without-bash-malloc \ --with-installed-readline root:/sources/bash-4.4# make root:/sources/bash-4.4# chown -Rv nobody . #nobody有寫權限 root:/sources/bash-4.4# time su nobody -s /bin/bash -c "PATH=$PATH make tests" #以nobody進行測試 real 2m45.276s user 0m6.333s sys 0m7.901s root:/sources/bash-4.4# time make install real 0m3.499s user 0m2.102s sys 0m1.465s root:/sources/bash-4.4# mv -vf /usr/bin/bash /bin #使用新安裝的bash環境來替換舊的環境: root:/sources/bash-4.4# exec /bin/bash --login +h root:/sources/bash-4.4# cd .. root:/sources# rm -rf bash-4.4/ Bc: 除了計算器,還包含任意精度的數字處理語言 root:/sources# tar xf /downloads/bc-1.06.95.tar.bz2 root:/sources# cd bc-1.06.95/ root:/sources/bc-1.06.95# patch -Np1 -i /downloads/bc-1.06.95-memory_leak-1.patch root:/sources/bc-1.06.95# ./configure --prefix=/usr \ --with-readline \ --mandir=/usr/share/man \ --infodir=/usr/share/info root:/sources/bc-1.06.95# make #檢測 root:/sources/bc-1.06.95# echo "quit" | ./bc/bc -l Test/checklib.b root:/sources/bc-1.06.95# make install root:/sources/bc-1.06.95# cd .. root:/sources# rm -rf bc-1.06.95/ Libtool: 包含處理通用函數的命令,將使用共享函數的複雜性隱藏在一個統一的可移植的接口中 root:/sources# tar xf /downloads/libtool-2.4.6.tar.xz root:/sources# cd libtool-2.4.6/ root:/sources/libtool-2.4.6# ./configure --prefix=/usr root:/sources/libtool-2.4.6# make root:/sources/libtool-2.4.6# make check make: *** [Makefile:1899: check] Error 2 有錯誤能夠忽略 root:/sources/libtool-2.4.6# make install root:/sources/libtool-2.4.6# cd .. root:/sources# rm -rf libtool-2.4.6/ GDBM: GNU的database manager,提供一個小型的數據庫,系統中不少軟件都須要這個小型數據庫的功能 root:/sources# tar xf /downloads/gdbm-1.12.tar.gz root:/sources# cd gdbm-1.12/ root:/sources/gdbm-1.12# ./configure --prefix=/usr \ --disable-static \ --enable-libgdbm-compat root:/sources/gdbm-1.12# make root:/sources/gdbm-1.12# make check root:/sources/gdbm-1.12# make install root:/sources/gdbm-1.12# cd .. root:/sources# rm -rf gdbm-1.12/
5.15. 其餘
gperf: 一種完美的散列函數,能夠爲用戶提供由特定字符串生成的,散列表,散列函數,和C++提供的一些代碼 root:/sources# tar xf /downloads/gperf-3.0.4.tar.gz root:/sources# cd gperf-3.0.4/ root:/sources/gperf-3.0.4# ./configure --prefix=/usr --docdir=/usr/share/doc/gperf-3.0.4 root:/sources/gperf-3.0.4# make root:/sources/gperf-3.0.4# make -j1 check root:/sources/gperf-3.0.4# make install root:/sources/gperf-3.0.4# cd .. root:/sources# rm -rf gperf-3.0.4/ expat: 包含一個解析xml的面向流的C庫 root:/sources# tar xf /downloads/expat-2.2.0.tar.bz2 root:/sources# cd expat-2.2.0/ root:/sources/expat-2.2.0# ./configure --prefix=/usr --disable-static root:/sources/expat-2.2.0# make root:/sources/expat-2.2.0# make check root:/sources/expat-2.2.0# make install root:/sources/expat-2.2.0# install -v -dm755 /usr/share/doc/expat-2.2.0 root:/sources/expat-2.2.0# install -v -m644 doc/*.{html,png,css} /usr/share/doc/expat-2.2.0 root:~# cd /sources/ root:/sources# rm -rf expat-2.2.0/ inetuilts: 經常使用網絡工具集,如ping之類的 root:/sources# tar xf /downloads/inetutils-1.9.4.tar.xz root:/sources# cd inetutils-1.9.4/ root:/sources/inetutils-1.9.4# 針對環境裏那些工具沒用,如rlogin有安全風險的 ./configure --prefix=/usr \ --localstatedir=/var \ --disable-logger \ --disable-whois \ --disable-rcp \ --disable-rexec \ --disable-rlogin \ --disable-rsh \ --disable-servers root:/sources/inetutils-1.9.4# make root:/sources/inetutils-1.9.4# make check root:/sources/inetutils-1.9.4# make install root:/sources/inetutils-1.9.4# mv -v /usr/bin/{hostname,ping,ping6,traceroute} /bin root:/sources/inetutils-1.9.4# mv -v /usr/bin/ifconfig /sbin root:/sources/inetutils-1.9.4# ping 127.0.0.1 #沒安裝前是,not found PING 127.0.0.1 (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.032 ms root:/sources/inetutils-1.9.4# cd .. root:/sources# rm -rf inetutils-1.9.4/ perl root:/sources# tar xf /downloads/perl-5.24.1.tar.bz2 root:/sources# cd perl-5.24.1/ root:/sources/perl-5.24.1# echo "127.0.0.1 localhost $(hostname)" > /etc/hosts root:/sources/perl-5.24.1# export BUILD_ZLIB=False root:/sources/perl-5.24.1# export BUILD_BZIP2=0 root:/sources/perl-5.24.1# time sh Configure -des -Dprefix=/usr \ -Dvendorprefix=/usr \ -Dman1dir=/usr/share/man/man1 \ -Dman3dir=/usr/share/man/man3 \ -Dpager="/usr/bin/less -isR" \ -Duseshrplib real 2m52.001s user 1m48.669s sys 1m14.907s root:/sources/perl-5.24.1# time make real 11m11.519s user 10m4.397s sys 1m16.577s root:/sources/perl-5.24.1#time make -k test 測試時,遇到錯誤繼續,不停止 real 25m41.594s user 18m57.928s sys 4m24.154s root:/sources/perl-5.24.1# time make install real 2m22.215s user 2m9.332s sys 0m12.790s root:/sources/perl-5.24.1# unset BUILD_ZLIB BUILD_BZIP2 root:/sources/perl-5.24.1# cd .. root:/sources# rm -rf perl-5.24.1/ XML-Parser 描述: 是使用C語言寫的XML分析器,因此比其餘語言寫的XML效率高不少。 root:/sources# tar xf /downloads/XML-Parser-2.44.tar.gz root:/sources# cd XML-Parser-2.44/ root:/sources/XML-Parser-2.44# perl Makefile.PL root:/sources/XML-Parser-2.44# make root:/sources/XML-Parser-2.44# make test root:/sources/XML-Parser-2.44# make install root:/sources/XML-Parser-2.44# cd .. root:/sources# rm -rf XML-Parser-2.44/ Intltool 描述:中間的l是language,它是能夠從源代碼中抽取能夠翻譯成字符串的國際化工具 root:/sources# tar xf /downloads/intltool-0.51.0.tar.gz root:/sources# cd intltool-0.51.0/ root:/sources/intltool-0.51.0# sed -i 's:\\\${:\\\$\\{:' intltool-update.in root:/sources/intltool-0.51.0# ./configure --prefix=/usr root:/sources/intltool-0.51.0# make root:/sources/intltool-0.51.0# make check root:/sources/intltool-0.51.0# make install root:/sources/intltool-0.51.0# install -v -Dm644 doc/I18N-HOWTO /usr/share/doc/intltool-0.51.0/I18N-HOWTO root:/sources/intltool-0.51.0# cd .. root:/sources# rm -rf intltool-0.51.0/ autoconf 描述: 與下面的automake配合使用,自動化配置工具autoconf,開發者可使用它命令來自動生成軟件的腳本 root:/sources# tar xf /downloads/autoconf-2.69.tar.xz root:/sources# cd autoconf-2.69/ root:/sources/autoconf-2.69# ./configure --prefix=/usr root:/sources/autoconf-2.69# time make real 0m4.985s user 0m3.216s sys 0m1.992s root:/sources/autoconf-2.69# time make check real 34m8.330s user 18m43.765s sys 16m51.853s root:/sources/autoconf-2.69# time make install real 0m3.669s user 0m0.567s sys 0m1.105s root:/sources/autoconf-2.69# cd .. root:/sources# rm -rf autoconf-2.69/ automake 描述:包含與autoconf一塊兒使用makefile的程序 root:/sources# tar xf /downloads/automake-1.15.tar.xz root:/sources# cd automake-1.15/ root:/sources/automake-1.15# sed -i 's:/\\\${:/\\\$\\{:' bin/automake.in root:/sources/automake-1.15# ./configure --prefix=/usr --docdir=/usr/share/doc/automake-1.15 root:/sources/automake-1.15# make root:/sources/automake-1.15# sed -i "s:./configure:LEXLIB=/usr/lib/libfl.a &:" t/lex-{clean,depend}-cxx.sh root:/sources/automake-1.15# time make -j4 check real 103m48.442s user 122m33.109s sys 81m55.056s root:/sources/automake-1.15# make install root:/sources/automake-1.15# cd .. root:/sources# rm -rf automake-1.15/ xz 描述: 包含壓縮和解壓縮的程序,壓縮率高於傳統的zip,bzip2 root:/sources# tar xf /downloads/xz-5.2.3.tar.xz root:/sources# cd xz-5.2.3/ root:/sources/xz-5.2.3# ./configure --prefix=/usr \ --disable-static \ --docdir=/usr/share/doc/xz-5.2.3 root:/sources/xz-5.2.3# make root:/sources/xz-5.2.3# time make check real 0m13.487s user 0m8.249s sys 0m7.012s root:/sources/xz-5.2.3# make install root:/sources/xz-5.2.3# mv -v /usr/bin/{lzma,unlzma,lzcat,xz,unxz,xzcat} /bin mv -v /usr/lib/liblzma.so.* /lib ln -svf ../../lib/$(readlink /usr/lib/liblzma.so) /usr/lib/liblzma.so root:/sources/xz-5.2.3# cd .. root:/sources# rm -rf xz-5.2.3/ kmod 描述:kernel,包含加載內核模塊的庫和工具 root:/sources# tar xf /downloads/kmod-23.tar.xz root:/sources# cd kmod-23/ root:/sources/kmod-23# ./configure --prefix=/usr \ --bindir=/bin \ --sysconfdir=/etc \ --with-rootlibdir=/lib \ --with-xz \ --with-zlib root:/sources/kmod-23# make root:/sources/kmod-23# make install root:/sources/kmod-23# for target in depmod insmod lsmod modinfo modprobe rmmod; do ln -sfv ../bin/kmod /sbin/$target done root:/sources/kmod-23# ln -sfv kmod /bin/lsmod root:/sources/kmod-23# cd .. root:/sources# rm -rf kmod-23/ gettext 描述:包含軟件包用於國際化和本地化的工具,容許國際語言支持的,使得用戶能夠本地語言的來輸出信息,顯示信息 root:/sources# tar xf /downloads/gettext-0.19.8.1.tar.xz root:/sources# cd gettext-0.19.8.1/ sed -i '/^TESTS =/d' gettext-runtime/tests/Makefile.in && sed -i 's/test-lock..EXEEXT.//' gettext-tools/gnulib-tests/Makefile.in root:/sources# cd gettext-0.19.8.1/ ./configure --prefix=/usr \ --disable-static \ --docdir=/usr/share/doc/gettext-0.19.8.1 root:/sources/gettext-0.19.8.1# time make real 2m53.527s user 2m9.393s sys 0m58.776s root:/sources/gettext-0.19.8.1# time make check real 3m20.158s user 1m52.776s sys 1m48.398s root:/sources/gettext-0.19.8.1# make install root:/sources/gettext-0.19.8.1# chmod -v 0755 /usr/lib/preloadable_libintl.so root:/sources/gettext-0.19.8.1# cd .. root:/sources# rm -rf gettext-0.19.8.1/ procps-ng 描述:包含有進程監視的程序,如使用top的命令 root:/sources# tar xf /downloads/procps-ng-3.3.12.tar.xz root:/sources# cd procps-ng-3.3.12/ root:/sources/procps-ng-3.3.12# ./configure --prefix=/usr \ --exec-prefix= \ --libdir=/usr/lib \ --docdir=/usr/share/doc/procps-ng-3.3.12 \ --disable-static \ --disable-kill root:/sources/procps-ng-3.3.12# time make real 0m12.435s user 0m10.037s sys 0m2.848s root:/sources/procps-ng-3.3.12# sed -i -r 's|(pmap_initname)\\\$|\1|' testsuite/pmap.test/pmap.exp root:/sources/procps-ng-3.3.12# time make check real 0m4.453s user 0m0.761s sys 0m0.803s root:/sources/procps-ng-3.3.12# make install root:/sources/procps-ng-3.3.12# mv -v /usr/lib/libprocps.so.* /lib root:/sources/procps-ng-3.3.12# ln -sfv ../../lib/$(readlink /usr/lib/libprocps.so) /usr/lib/libprocps.so root:/sources/procps-ng-3.3.12# cd .. root:/sources# rm -rf procps-ng-3.3.12/ e2fsprogs 描述:文件系統管理工具,ext2,3,4 root:/sources# tar xf /downloads/e2fsprogs-1.43.4.tar.gz root:/sources# cd e2fsprogs-1.43.4/ root:/sources/e2fsprogs-1.43.4# mkdir build root:/sources/e2fsprogs-1.43.4# cd build root:/sources/e2fsprogs-1.43.4/build# time LIBS=-L/tools/lib \ CFLAGS=-I/tools/include \ PKG_CONFIG_PATH=/tools/lib/pkgconfig \ ../configure --prefix=/usr \ --bindir=/bin \ --with-root-prefix="" \ --enable-elf-shlibs \ --disable-libblkid \ --disable-libuuid \ --disable-uuidd \ --disable-fsck 注:--with-root-prefix=""爲空,有些程序與函數庫很重要,要安裝在/sbin /lib目錄中,空是指定不要考慮以前的/usr real 0m19.475s user 0m7.579s sys 0m8.904s root:/sources/e2fsprogs-1.43.4/build# time make real 0m25.884s user 0m18.612s sys 0m7.404s root:/sources/e2fsprogs-1.43.4/build# ln -sfv /tools/lib/lib{blk,uu}id.so.1 lib root:/sources/e2fsprogs-1.43.4/build# time make LD_LIBRARY_PATH=/tools/lib check real 6m32.414s #測試時,有個可能比較消耗內存,要調整好足夠內存 user 3m34.858s sys 0m28.002s root:/sources/e2fsprogs-1.43.4/build# make install root:/sources/e2fsprogs-1.43.4/build# make install-libs #安裝一些靜態的庫和頭文件 root:/sources/e2fsprogs-1.43.4/build# chmod -v u+w /usr/lib/{libcom_err,libe2p,libext2fs,libss}.a root:/sources/e2fsprogs-1.43.4/build# gunzip -v /usr/share/info/libext2fs.info.gz root:/sources/e2fsprogs-1.43.4/build# install-info --dir-file=/usr/share/info/dir /usr/share/info/libext2fs.info root:/sources/e2fsprogs-1.43.4/build# makeinfo -o doc/com_err.info ../lib/et/com_err.texinfo root:/sources/e2fsprogs-1.43.4/build# install -v -m644 doc/com_err.info /usr/share/info root:/sources/e2fsprogs-1.43.4/build# install-info --dir-file=/usr/share/info/dir /usr/share/info/com_err.info root:/sources/e2fsprogs-1.43.4/build# cd ../.. root:/sources# rm -rf e2fsprogs-1.43.4/ coreutils 描述:linux下一些必不可少的命令,如ls,copy root:/sources# tar xf /downloads/coreutils-8.26.tar.xz root:/sources# cd coreutils-8.26/ root:/sources/coreutils-8.26# patch -Np1 -i /downloads/coreutils-8.26-i18n-1.patch root:/sources/coreutils-8.26# sed -i '/test.lock/s/^/#/' gnulib-tests/gnulib.mk root:/sources/coreutils-8.26# time FORCE_UNSAFE_CONFIGURE=1 ./configure \ --prefix=/usr \ --enable-no-install-program=kill,uptime real 0m59.361s user 0m27.470s sys 0m28.010s root:/sources/coreutils-8.26# FORCE_UNSAFE_CONFIGURE=1 make root:/sources/coreutils-8.26# time make NON_ROOT_USERNAME=nobody check-root real 0m4.610s user 0m2.371s sys 0m2.332s root:/sources/coreutils-8.26# echo "dummy:x:1000:nobody" >> /etc/group #有些用戶測試要求多組 root:/sources/coreutils-8.26# chown -Rv nobody . root:/sources/coreutils-8.26# su nobody -s /bin/bash \ -c "PATH=$PATH make RUN_EXPENSIVE_TESTS=yes check" root:/sources/coreutils-8.26# sed -i '/dummy/d' /etc/group root:/sources/coreutils-8.26# make install root:/sources/coreutils-8.26# mv -v /usr/bin/{cat,chgrp,chmod,chown,cp,date,dd,df,echo} /bin mv -v /usr/bin/{false,ln,ls,mkdir,mknod,mv,pwd,rm} /bin mv -v /usr/bin/{rmdir,stty,sync,true,uname} /bin mv -v /usr/bin/chroot /usr/sbin mv -v /usr/share/man/man1/chroot.1 /usr/share/man/man8/chroot.8 sed -i s/\"1\"/\"8\"/1 /usr/share/man/man8/chroot.8 root:/sources/coreutils-8.26# mv -v /usr/bin/{head,sleep,nice,test,[} /bin root:/sources/coreutils-8.26# cd .. root:/sources# rm -rf coreutils-8.26/ diffutils 描述:包含diff命令,經常使用於製做補丁文件 root:/sources# tar xf /downloads/diffutils-3.5.tar.xz root:/sources# cd diffutils-3.5/ root:/sources/diffutils-3.5# sed -i 's:= @mkdir_p@:= /bin/mkdir -p:' po/Makefile.in.in root:/sources/diffutils-3.5# ./configure --prefix=/usr root:/sources/diffutils-3.5# make root:/sources/diffutils-3.5# make check root:/sources/diffutils-3.5# make install root:/sources/diffutils-3.5# cd .. root:/sources# rm -rf diffutils-3.5/ gawk 描述:GNU的awk,包含多個文本操做的工具 root:/sources# tar xf /downloads/gawk-4.1.4.tar.xz root:/sources# cd gawk-4.1.4/ root:/sources/gawk-4.1.4# ./configure --prefix=/usr root:/sources/gawk-4.1.4# make root:/sources/gawk-4.1.4# time make check real 0m15.656s user 0m2.598s sys 0m3.844s root:/sources/gawk-4.1.4# make install root:/sources/gawk-4.1.4# mkdir -v /usr/share/doc/gawk-4.1.4 cp -v doc/{awkforai.txt,*.{eps,pdf,jpg}} /usr/share/doc/gawk-4.1.4 root:/sources/gawk-4.1.4# cd .. root:/sources# rm -rf gawk-4.1.4/ findutils 描述:包含find,locate之類的命令 root:/sources# tar xf /downloads/findutils-4.6.0.tar.gz root:/sources# cd findutils-4.6.0/ root:/sources/findutils-4.6.0# sed -i 's/test-lock..EXEEXT.//' tests/Makefile.in #主要避免test一些循環問題 root:/sources/findutils-4.6.0# ./configure --prefix=/usr --localstatedir=/var/lib/locate #並指定locate數據庫 root:/sources/findutils-4.6.0# make root:/sources/findutils-4.6.0# time make check real 1m4.633s user 0m29.734s sys 0m26.683s root:/sources/findutils-4.6.0# make install mv -v /usr/bin/find /bin sed -i 's|find:=${BINDIR}|find:=/bin|' /usr/bin/updatedb root:/sources/findutils-4.6.0# cd .. root:/sources# rm -rf findutils-4.6.0/ groff 描述:包含處理和格式化文本的工具,這些工具會在程序製做過程當中用到 root:/sources# tar xf /downloads/groff-1.22.3.tar.gz root:/sources# cd groff-1.22.3/ root:/sources/groff-1.22.3# PAGE=A4 ./configure --prefix=/usr root:/sources/groff-1.22.3# make root:/sources/groff-1.22.3# make install root:/sources/groff-1.22.3# cd .. root:/sources# rm -rf groff-1.22.3/ GRUB 描述:啓動器 root:/sources# tar xf /downloads/grub-2.02~beta3.tar.xz root:/sources# cd grub-2.02~beta3/ root:/sources/grub-2.02~beta3# ./configure --prefix=/usr \ --sbindir=/sbin \ --sysconfdir=/etc \ --disable-efiemu \ --disable-werror root:/sources/grub-2.02~beta3# make root:/sources/grub-2.02~beta3# make install root:/sources/grub-2.02~beta3# cd .. root:/sources# rm -rf grub-2.02~beta3/ less 描述:包含文本查看的工具,如less root:/sources# tar xf /downloads/less-481.tar.gz root:/sources# cd less-481/ root:/sources/less-481# ./configure --prefix=/usr --sysconfdir=/etc root:/sources/less-481# time make root:/sources/less-481# make install root:/sources/less-481# cd .. root:/sources# rm -rf less-481/ gzip 描述:包含壓縮和解壓縮 root:/sources# tar xf /downloads/gzip-1.8.tar.xz root:/sources# cd gzip-1.8/ root:/sources/gzip-1.8# ./configure --prefix=/usr root:/sources/gzip-1.8# make root:/sources/gzip-1.8# time make check real 0m17.732s user 0m7.737s sys 0m11.431s root:/sources/gzip-1.8# make install root:/sources/gzip-1.8# mv -v /usr/bin/gzip /bin root:/sources/gzip-1.8# cd .. root:/sources# rm -rf gzip-1.8/ iproute 描述:包含ipv4版本相關的命令 root:/sources# tar xf /downloads/iproute2-4.9.0.tar.xz root:/sources# cd iproute2-4.9.0/ root:/sources/iproute2-4.9.0# sed -i /ARPD/d Makefile root:/sources/iproute2-4.9.0# sed -i 's/arpd.8//' man/man8/Makefile root:/sources/iproute2-4.9.0# rm -v doc/arpd.sgml root:/sources/iproute2-4.9.0# sed -i 's/m_ipt.o//' tc/Makefile root:/sources/iproute2-4.9.0# time make real 1m38.237s user 1m22.381s sys 0m15.773s root:/sources/iproute2-4.9.0# time make DOCDIR=/usr/share/doc/iproute2-4.9.0 install real 0m0.810s user 0m0.344s sys 0m0.479s root:/sources/iproute2-4.9.0# cd .. root:/sources# rm -rf iproute2-4.9.0/ kbd 描述:包含鍵盤映射表和工具,在目標系統啓動過程當中要設定鍵盤映射表 root:/sources# tar xf /downloads/kbd-2.0.4.tar.xz root:/sources# cd kbd-2.0.4/ root:/sources/kbd-2.0.4# patch -Np1 -i /downloads/kbd-2.0.4-backspace-1.patch root:/sources/kbd-2.0.4# sed -i 's/\(RESIZECONS_PROGS=\)yes/\1no/g' configure root:/sources/kbd-2.0.4# sed -i 's/resizecons.8 //' docs/man/man8/Makefile.in root:/sources/kbd-2.0.4# time PKG_CONFIG_PATH=/tools/lib/pkgconfig ./configure --prefix=/usr --disable-vlock real 0m42.199s user 0m21.372s sys 0m22.876s root:/sources/kbd-2.0.4# time make real 0m58.345s user 0m44.493s sys 0m14.629s root:/sources/kbd-2.0.4# time make check root:/sources/kbd-2.0.4# make install root:/sources/kbd-2.0.4# mkdir -v /usr/share/doc/kbd-2.0.4 cp -R -v docs/doc/* /usr/share/doc/kbd-2.0.4 root:/sources/kbd-2.0.4# cd .. root:/sources# rm -rf kbd-2.0.4/ libpipeline 描述:管理管道和子進程的一些庫 root:/sources# tar xf /downloads/libpipeline-1.4.1.tar.gz root:/sources# cd libpipeline-1.4.1/ root:/sources/libpipeline-1.4.1# PKG_CONFIG_PATH=/tools/lib/pkgconfig ./configure --prefix=/usr root:/sources/libpipeline-1.4.1# time make real 0m16.814s user 0m12.371s sys 0m5.079s root:/sources/libpipeline-1.4.1# time make check real 0m11.462s user 0m7.216s sys 0m4.958s root:/sources/libpipeline-1.4.1# make install root:/sources/libpipeline-1.4.1# cd .. root:/sources# rm -rf libpipeline-1.4.1/ make 描述:包含處理makefile的命令,makefile格式文件中包含不少控制流程,可使用任務處理自動化 root:/sources# tar xf /downloads/make-4.2.1.tar.bz2 root:/sources# cd make-4.2.1/ root:/sources/make-4.2.1# ./configure --prefix=/usr root:/sources/make-4.2.1# time make real 0m25.908s user 0m22.953s sys 0m2.927s root:/sources/make-4.2.1# time make check real 2m27.315s #有已知的錯誤,能夠忽略 user 0m7.149s sys 0m8.771s root:/sources/make-4.2.1# time make install real 0m1.272s user 0m0.452s sys 0m0.966s root:/sources/make-4.2.1# cd .. root:/sources# rm -rf make-4.2.1/ patch 描述:包含打補丁工具 root:/sources# tar xf /downloads/patch-2.7.5.tar.xz root:/sources# cd patch-2.7.5/ root:/sources/patch-2.7.5# ./configure --prefix=/usr root:/sources/patch-2.7.5# time make real 0m29.880s user 0m24.488s sys 0m5.722s root:/sources/patch-2.7.5# time make check real 0m12.076s user 0m3.727s sys 0m9.927s root:/sources/patch-2.7.5# make install root:/sources/patch-2.7.5# cd .. root:/sources# rm -rf patch-2.7.5/ sysklogd 描述:日誌系統,記錄與內核異常有關的事件 root:/sources# tar xf /downloads/sysklogd-1.5.1.tar.gz root:/sources# cd sysklogd-1.5.1/ root:/sources/sysklogd-1.5.1# sed -i '/Error loading kernel symbols/{n;n;d}' ksym_mod.c root:/sources/sysklogd-1.5.1# sed -i 's/union wait/int/' syslogd.c root:/sources/sysklogd-1.5.1# time make real 0m5.959s user 0m5.220s sys 0m0.646s root:/sources/sysklogd-1.5.1# time make BINDIR=/sbin install real 0m0.059s user 0m0.018s sys 0m0.040s 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 root:/sources/sysklogd-1.5.1# cd .. root:/sources# rm -rf sysklogd-1.5.1/ sysvinit 描述:包含控制系統啓動,運行,關閉的程序,如init,shutdown root:/sources# tar xf /downloads/sysvinit-2.88dsf.tar.bz2 root:/sources# cd sysvinit-2.88dsf/ root:/sources/sysvinit-2.88dsf# patch -Np1 -i /downloads/sysvinit-2.88dsf-consolidated-1.patch root:/sources/sysvinit-2.88dsf# time make -C src real 0m8.543s user 0m7.259s sys 0m1.271s root:/sources/sysvinit-2.88dsf# time make -C src install real 0m0.279s user 0m0.085s sys 0m0.188s root:/sources/sysvinit-2.88dsf# cd .. root:/sources# rm -rf sysvinit-2.88dsf/ eudev 描述: 包含動態建立設備的程序,用它來管理/dev下的設備文件,會自動檢測並生成設備文件,還有一些設備熱 插撥的管理程序,能夠根據設備狀況動態調整,大大提升管理設備的效率 root:/sources# tar xf /downloads/eudev-3.2.1.tar.gz root:/sources# cd eudev-3.2.1/ root:/sources/eudev-3.2.1# sed -r -i 's|/usr(/bin/test)|\1|' test/udev-test.pl root:/sources/eudev-3.2.1# sed -i '/keyboard_lookup_key/d' src/udev/udev-builtin-keyboard.c cat > config.cache << "EOF" HAVE_BLKID=1 BLKID_LIBS="-lblkid" BLKID_CFLAGS="-I/tools/include" EOF time ./configure --prefix=/usr \ --bindir=/sbin \ --sbindir=/sbin \ --libdir=/usr/lib \ --sysconfdir=/etc \ --libexecdir=/lib \ --with-rootprefix= \ --with-rootlibdir=/lib \ --enable-manpages \ --disable-static \ --config-cache real 0m37.073s user 0m18.716s sys 0m21.060s root:/sources/eudev-3.2.1# time LIBRARY_PATH=/tools/lib make real 1m49.553s user 1m17.638s sys 0m40.503s mkdir -pv /lib/udev/rules.d mkdir -pv /etc/udev/rules.d root:/sources/eudev-3.2.1# time make LD_LIBRARY_PATH=/tools/lib check real 0m9.865s user 0m2.221s sys 0m6.750s root:/sources/eudev-3.2.1# time make LD_LIBRARY_PATH=/tools/lib install real 0m3.606s user 0m2.260s sys 0m1.715s root:/sources/eudev-3.2.1# tar -xvf /downloads/udev-lfs-20140408.tar.bz2 #設備發現規則 root:/sources/eudev-3.2.1# make -f udev-lfs-20140408/Makefile.lfs install root:/sources/eudev-3.2.1# LD_LIBRARY_PATH=/tools/lib udevadm hwdb --update root:/sources/eudev-3.2.1# cd .. root:/sources# rm -rf eudev-3.2.1/ util-linux 描述:包含linux下不少經常使用的工具,文件系統操做,硬盤分區等 root:/sources# tar xf /downloads/util-linux-2.29.1.tar.xz root:/sources# cd util-linux-2.29.1/ root:/sources/util-linux-2.29.1# mkdir -pv /var/lib/hwclock time ./configure ADJTIME_PATH=/var/lib/hwclock/adjtime \ --docdir=/usr/share/doc/util-linux-2.29.1 \ --disable-chfn-chsh \ --disable-login \ --disable-nologin \ --disable-su \ --disable-setpriv \ --disable-runuser \ --disable-pylibmount \ --disable-static \ --without-python \ --without-systemd \ --without-systemdsystemunitdir real 1m18.990s user 0m39.616s sys 0m43.116s root:/sources/util-linux-2.29.1# time make real 7m9.126s user 5m35.184s sys 1m54.531s root:/sources/util-linux-2.29.1# chown -Rv nobody . root:/sources/util-linux-2.29.1# su nobody -s /bin/bash -c "PATH=$PATH make -k check" #測試是與非root用戶 root:/sources/util-linux-2.29.1# make install root:/sources/util-linux-2.29.1# cd .. root:/sources# rm -rf util-linux-2.29.1/ man 描述:包含查找和顯示man手冊內容的程序 root:/sources# tar xf /downloads/man-db-2.7.6.1.tar.xz root:/sources# cd man-db-2.7.6.1/ root:/sources/man-db-2.7.6.1# time ./configure --prefix=/usr \ --docdir=/usr/share/doc/man-db-2.7.6.1 \ --sysconfdir=/etc \ --disable-setuid \ --enable-cache-owner=bin \ --with-browser=/usr/bin/lynx \ --with-vgrind=/usr/bin/vgrind \ --with-grap=/usr/bin/grap \ --with-systemdtmpfilesdir= real 2m33.172s user 1m17.974s sys 1m18.515s root:/sources/man-db-2.7.6.1# time make real 1m30.525s user 1m5.345s sys 0m30.859s root:/sources/man-db-2.7.6.1# time make check real 0m50.594s user 0m33.950s sys 0m21.535s root:/sources/man-db-2.7.6.1# make install root:/sources/man-db-2.7.6.1# cd .. root:/sources# rm -rf man-db-2.7.6.1/ tar root:/sources# tar xf /downloads/tar-1.29.tar.xz root:/sources# cd tar-1.29/ root:/sources/tar-1.29# time FORCE_UNSAFE_CONFIGURE=1 \ ./configure --prefix=/usr \ --bindir=/bin real 0m47.772s user 0m21.370s sys 0m22.899s root:/sources/tar-1.29# time make real 0m20.196s user 0m15.975s sys 0m4.388s root:/sources/tar-1.29# time make check real 8m21.408s user 0m22.813s sys 1m35.307s root:/sources/tar-1.29# make install root:/sources/tar-1.29# make -C doc install-html docdir=/usr/share/doc/tar-1.29 root:/sources/tar-1.29# cd ../ root:/sources# rm -rf tar-1.29/ texinfo root:/sources# tar xf /downloads/texinfo-6.3.tar.xz root:/sources# cd texinfo-6.3/ root:/sources/texinfo-6.3# ./configure --prefix=/usr --disable-static root:/sources/texinfo-6.3# time make real 0m17.421s user 0m14.642s sys 0m2.591s root:/sources/texinfo-6.3# time make check real 0m35.062s user 0m17.711s sys 0m16.541s root:/sources/texinfo-6.3# time make install root:/sources/texinfo-6.3# time make TEXMF=/usr/share/texmf install-tex real 0m0.083s user 0m0.017s sys 0m0.060s root:/sources/texinfo-6.3# info系統使用一個純文本的用來保存一些菜單的條目,可能與系統安裝的信息不一致,因此做爲可選的 pushd /usr/share/info rm -v dir for f in * do install-info $f dir 2>/dev/null done popd root:/sources/texinfo-6.3# cd .. root:/sources# rm -rf texinfo-6.3/ vim root:/sources# tar xf /downloads/vim-8.0.069.tar.bz2 root:/sources# cd vim80/ root:/sources/vim80# echo '#define SYS_VIMRC_FILE "/etc/vimrc"' >> src/feature.h root:/sources/vim80# time ./configure --prefix=/usr real 0m13.434s user 0m6.640s sys 0m6.964s root:/sources/vim80# time make real 1m8.373s user 1m4.687s sys 0m3.551s root:/sources/vim80# time make -j1 test real 0m12.829s user 0m9.619s sys 0m1.009s root:/sources/vim80# make install ln -sv vim /usr/bin/vi for L in /usr/share/man/{,*/}man1/vim.1; do ln -sv vim.1 $(dirname $L)/vi.1 done root:/sources/vim80# ln -sv ../vim/vim80/doc /usr/share/doc/vim-8.0.069 cat > /etc/vimrc << "EOF" " Begin /etc/vimrc set nocompatible set backspace=2 set mouse=r syntax on if (&term == "xterm") || (&term == "putty") set background=dark endif " End /etc/vimrc EOF root:/sources/vim80# cd .. root:/sources# rm -rf vim80/ clean 清理無用內存 描述: 比較大多是符號文件,主要是編譯時使用調試使用,來獲取一些內存信息,可是對於系統無用 root:/# logout [root@node ~]# chroot $LFS /tools/bin/env -i \ HOME=/root TERM=$TERM PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /tools/bin/bash --login 進行查找和remove操做 root:/# /tools/bin/find /usr/lib -type f -name \*.a \ -exec /tools/bin/strip --strip-debug {} ';' /tools/bin/find /lib /usr/lib -type f -name \*.so* \ -exec /tools/bin/strip --strip-unneeded {} ';' /tools/bin/find /{bin,sbin} /usr/{bin,sbin,libexec} -type f \ -exec /tools/bin/strip --strip-all {} ';' root:/# rm -rf /tmp/* root:/# logout [root@node ~]# chroot "$LFS" /usr/bin/env -i \ HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \ PATH=/bin:/usr/bin:/sbin:/usr/sbin \ /bin/bash --login 刪除些無用文件 rm -f /usr/lib/lib{bfd,opcodes}.a rm -f /usr/lib/libbz2.a rm -f /usr/lib/lib{com_err,e2p,ext2fs,ss}.a rm -f /usr/lib/libltdl.a rm -f /usr/lib/libfl.a rm -f /usr/lib/libfl_pic.a rm -f /usr/lib/libz.a
6.系統配置
6.1. 啓動腳本與設備管理
- mount虛擬和真實文件系統
- 初始化設備
- 激活交換分區(文件)
- 檢查文件系統完整性
- 設置系統的完整性
- 設置系統時鐘
- 啓動網絡
- 啓動系統所需的任何守護程序
- 完成任何用戶須要的其餘自定義任務
LFS-Bootscripts
:/sources# tar xf /downloads/lfs-bootscripts-20150222.tar.bz2 root:/sources# cd lfs-bootscripts-20150222/ root:/sources/lfs-bootscripts-20150222# make install root:/sources/lfs-bootscripts-20150222# ls /etc/rc.d/ init.d rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rcS.d root:/sources/lfs-bootscripts-20150222# cd .. root:/sources# rm -rf lfs-bootscripts-20150222/
設備和模塊管理概述
- udev是Linux2.6內核裏的一個功能,它替代了原來的devfs
- udev以守護進程的形式運行,經過偵聽內核發出來的uevent來管理/dev目錄下的設備文件
- udev在用戶空間(user space)運行
如網卡,磁盤通常不能很好肯定,須要有個東西來管理和識別
優勢:
- 動態管理
- 自定義命名規則爲匹配設備的名稱,能夠實現動態管理,有些設備能夠熱添加時,udev就能夠監聽內核的一個消息,
根據消息來添加或刪除/dev下的設備文件,爲真實存在設備才建立文件
- 可設置的權限和全部者/組
網絡設備命名
- udev根據固件/BIOS數據或總線,插槽或MAC地址等物理特性來命名網絡設備
- 此命名約定的目的是確保網絡設備的名稱一致,而不是基於發現網卡的時間
- 再也不是傳統的eth0,eth1
root:/sources# vim /lib/udev/init-net-rules.sh #VENDORS_IGNORED['00:0c:29:']="vmware" #在虛擬化環境要註釋掉,不然不會生成 #VENDORS_IGNORED['00:50:56:']="vmware" root:/sources# bash /lib/udev/init-net-rules.sh #生成規則環境 root:/sources# ls /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules root:/sources# tail -1 /etc/udev/rules.d/70-persistent-net.rules SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:c2:18:da", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="ens33" SUBSYSTEM=="net" 與網卡有關的設備 ACTION=="add" 添加一個udev的的規則 DRIVERS=="?* 正則是表達不能爲空,udev在檢測一些設備時,如vlan的設備,或者作橋接的子接口,這些是沒有驅動程序的,這裏 是否是vlan,不是橋接子接口的 ATTR{address} 網卡的MAC地址 NAME="ens33" 不會由於位置的變化而變化,如插槽之類的
6.2.網絡配置與bash啓動文件
root:/etc/sysconfig# cat /etc/rc.d/init.d/network for file in /etc/sysconfig/ifconfig.* ip地址: root:/etc/sysconfig# 若是使用dhcp,要使用另外一種配置方法 cat > ifconfig.ens33 << "EOF" ONBOOT=yes IFACE=ens33 SERVICE=ipv4-static IP=192.168.26.147 GATEWAY=192.168.26.2 PREFIX=24 BROADCAST=192.168.26.255 EOF 配置dns: root:/etc/sysconfig# cat > /etc/resolv.conf << "EOF" # Begin /etc/resolv.conf domain centos.reid nameserver 192.168.26.2 # End /etc/resolv.conf EOF root:/etc/sysconfig# ping baidu.com PING baidu.com (220.181.57.216): 56 data bytes 64 bytes from 220.181.57.216: icmp_seq=0 ttl=128 time=10.867 ms 配置hostname root:/etc/sysconfig# echo "node1.centos.reid" > /etc/hostname 配置hosts root:/etc/sysconfig# cat > /etc/hosts << "EOF" # Begin /etc/hosts (network card version) 127.0.0.1 localhost # End /etc/hosts (network card version) EOF 配置systemV bootscript root:/etc/sysconfig# cat > /etc/inittab << "EOF" # Begin /etc/inittab id:3:initdefault: si::sysinit:/etc/rc.d/init.d/rc S 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 --noclear 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 配置系統時間 root:/etc/sysconfig# cat > /etc/sysconfig/clock << "EOF" # Begin /etc/sysconfig/clock UTC=1 # Set this to any options you might need to give to hwclock, # such as machine hardware clock type for Alphas. CLOCKPARAMS= # End /etc/sysconfig/clock EOF bash shell startup 描述:啓動時會讀取一些配置文件 root:/etc/sysconfig# locale -a|grep en_US en_US root:/etc/sysconfig# LC_ALL=en_US locale language LC_ALL=en_US locale charmap LC_ALL=en_US locale int_curr_symbol LC_ALL=en_US locale int_prefix cat > /etc/profile << "EOF" # Begin /etc/profile export LANG=en_US.UTF-8 # End /etc/profile EOF 建立/etc/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 建立/etc/shells文件 描述:與系統shells有關 root:/etc/sysconfig# cat > /etc/shells << "EOF" # Begin /etc/shells /bin/sh /bin/bash # End /etc/shells EOF
7.啓動系統
7.1.fstab與內核編譯安裝
建立fstab 描述:目標系統swap(8GB),ext4(32GB) root:~# ls /etc/fstab ls: cannot access '/etc/fstab': No such file or directory cat > /etc/fstab << "EOF" # Begin /etc/fstab # file system mount-point type options dump fsck # order /dev/sda2 / ext4 defaults 1 1 /dev/sda1 swap swap pri=1 0 0 proc /proc proc nosuid,noexec,nodev 0 0 sysfs /sys sysfs nosuid,noexec,nodev 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 tmpfs /run tmpfs defaults 0 0 devtmpfs /dev devtmpfs mode=0755,nosuid 0 0 # End /etc/fstab EOF 系統內核編譯 root:~# cd /sources/ root:/sources# time tar xf /downloads/linux-4.9.9.tar.xz real 0m35.106s user 0m8.123s sys 0m36.296s root:/sources# cd linux-4.9.9/ root:/sources/linux-4.9.9# make mrproper #清理 root:/sources/linux-4.9.9# make defconfig #生成最基本的配置文件 root:/sources/linux-4.9.9# make menuconfig 注意:把最核心的內核驅動編譯到內核中 - 在vmware workstation中存在已知的問題,主要是內核不能識別vmware workstation中的設備 kernel panic - not syncing: VFS: Unable to mount root fs on unknown 解決: Device Drivers - Generic Driver Options, Maintain a devtmpfs filesystem to mount at /dev - Network device support,Ethernet Driver support,AMD PCnet32 PCI support - Fusion MPT device support(選中SPI,SAS驅動) - SCSI device support,SCSI low-level drivers File Systems - Ext3 Journaling file system support 圖形菜單中操做: 描述:M是爲模塊,*是編譯到內核 Device Drivers ---> Generic Driver Options ---> [*] Maintain a devtmpfs filesystem to mount at /dev ---> Network device support ---> Ethernet driver support ---> <M> AMD PCnet32 PCI support ---> [*] Fusion MPT device support ---> <*> Fusion MPT ScsiHost drivers for SPI SCSI device support ---> [*] SCSI low-level drivers ---> File System File systems ---> <*> The Extended 3 (ext3) filesystem --> exit & save root:/sources/linux-4.9.9# time make real 18m18.654s user 16m4.792s sys 2m33.636s root:/sources/linux-4.9.9# make modules_install #進行模塊的安裝 root:/sources/linux-4.9.9# cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-4.9.9-lfs-8.0 root:/sources/linux-4.9.9# cp -v .config /boot/config-4.9.9 root:/sources/linux-4.9.9# install -d /usr/share/doc/linux-4.9.9 root:/sources/linux-4.9.9# cp -r Documentation/* /usr/share/doc/linux-4.9.9 模塊加載的次序 root:/sources/linux-4.9.9# install -v -m755 -d /etc/modprobe.d #如下是USB編譯爲模塊的事例 cat > /etc/modprobe.d/usb.conf << "EOF" # Begin /etc/modprobe.d/usb.conf install ohci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i ohci_hcd ; true install uhci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i uhci_hcd ; true # End /etc/modprobe.d/usb.conf EOF root:/sources/linux-4.9.9# cd .. root:/sources# rm -rf linux-4.9.9/
7.2.安裝GRUB引導器
描述:LFS做者認爲這是一種比較危險的操做,由於對於grub這種引導加載器,它會寫到硬盤的頭部,有可能把之前的引導加載器作替換, 加載器位置寫不對就沒法引導。 注意:這時使用的磁盤是/dev/sdb,(h0,2),0是硬盤第一個硬盤,2是第二個分區 root:~# grub-install /dev/sdb Installing for i386-pc platform. Installation finished. No error reported. cat > /boot/grub/grub.cfg << "EOF" # Begin /boot/grub/grub.cfg set default=0 set timeout=5 insmod ext2 set root=(hd0,2) menuentry "GNU/Linux, Linux 4.9.9-lfs-8.0" { linux /boot/vmlinuz-4.9.9-lfs-8.0 root=/dev/sda2 ro } EOF
7.3.啓動目標系統
- 關閉虛擬機,把host的硬盤移除,只保留目標系統的硬盤
8.自動構建LFS系統概述描述:ALFS是自動化構建,一個框架,一個可擴展的系統構建器,把手冊代碼抽取出來,造成xml的一個源,根據這個xml來構建執行的腳本。官方版本是jhafs,jh是一我的名,經過分析lfs的官方文來造成一個xml的源http://wiki.linuxfromscratch.org/alfs/wiki/SupportedBooks