本機宿主系統archlinux,lfs SVN-20130711,參考文檔
1.在離開或重新進入當前工作環境 (比如 su 成為 root
或者其他用戶) 時不要忘記檢查 $LFS
是否設置好。
echo $LFS export LFS=/mnt/lfs
2.這個命令:
ln -sv $LFS/tools /
在宿主系統上創建一個 /tools
符號鏈接。它將指向 LFS 分區上的$LFS/tools 目錄,此命令相當於:
ln -sv $LFS/tool /tools
之后可用ls -l 在根目錄看到生成了一個鏈接
lrwxrwxrwx 1 root root 15 Apr 10 19:03 tools -> /mnt/lfs//tools
3.第一遍編譯Binutils,出師不利,開始就出錯了,卡在開頭,耗費一個下午的時間,方才解決(中間在1024放縱了好久……阿彌陀佛)
configure時沒錯,make時出錯,錯誤信息類似下面:
../../../binutils-2.23.2/bfd/doc/bfd.texinfo:325: unknown command `colophon'
../../../binutils-2.23.2/bfd/doc/bfd.texinfo:336: unknown command `cygnus'
make[3]: *** [bfd.info] Error 1
make[3]: Leaving directory `/mnt/lfs/sources/binutils-build/bfd/doc'
Making info in po
make[3]: Entering directory `/mnt/lfs/sources/binutils-build/bfd/po'
make[3]: Nothing to be done for `info'.
make[3]: Leaving directory `/mnt/lfs/sources/binutils-build/bfd/po'
make[3]: Entering directory `/mnt/lfs/sources/binutils-build/bfd'
make[3]: Nothing to be done for `info-am'.
make[3]: Leaving directory `/mnt/lfs/sources/binutils-build/bfd'
make[2]: *** [info-recursive] Error 1
make[2]: Leaving directory `/mnt/lfs/sources/binutils-build/bfd'
make[1]: *** [all-bfd] Error 2
make[1]: Leaving directory `/mnt/lfs/sources/binutils-build'
make: *** [all] Error 2
搜便世界,在這里找到個解決辦法:
sed -i -e 's/@colophon/@@colophon/' \ -e 's/doc@cygnus.com/doc@@cygnus.com/' bfd/doc/bfd.texinfo
當時正在新建的 binutils-build 下,此目錄中的bfd/doc/ 中沒有bfd.texinfo 文件,而在 binutils-2.23.2/bfd/doc/中,所以命令改為(注意,sed不可執行多次):
sed -i -e 's/@colophon/@@colophon/' \ -e 's/doc@cygnus.com/doc@@cygnus.com/' ../binutils-2.23.2/bfd/doc/bfd.texinfo
成功編譯! 此前還稀里糊塗的運行過make clean, make distclean等命令,刪除過目錄,重新下載binutils包,但都沒奏效,如果上面的方法不行,可以試試這些。此外,如果懷疑是gcc版本的問題,在宿主系統要求中gcc的部分,有這個note:
On some distributions, there have been reports that some libraries used by gcc can be in an inconsistent state and that this interferes with building some LFS packages. To check this, look in /usr/lib and possibly /usr/lib64 for libgmp.la, libmpfr.la, and libmpc.la. Either all three should be present or absent, but not only one or two. If the problem exists on your system, either rename or delete the .la files or install the appropriate missing package.
我運行version-check.sh后發現沒有 libgmp.la, libmpfr.la, libmpc.la這三個貨,可以從這下手解決。
4.第一遍編譯gcc,這條命令沒有解釋清楚
sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure
-i 選項表示將改變直接寫入文件
/k prot/ 會搜索到這行
# Test for stack protector support in target C library
將/k prot/寫成/stack protector/或許更容易理解。
接下來不是將"k prot" 替換成后邊那句,而是在這行后邊插入
agcc_cv_libc_provides_ssp=yes
就成了
# Test for stack protector support in target C library
agcc_cv_libc_provides_ssp=yes
5.第一遍gcc,出錯:
configure: error: in `/mnt/lfs/sources/gcc-build/i686-lfs-linux-gnu/libatomic': configure: error: C compiler cannot create executables See `config.log' for more details. Makefile:11514: recipe for target 'configure-target-libatomic' failed make[1]: *** [configure-target-libatomic] Error 1 make[1]: Leaving directory '/mnt/lfs/sources/gcc-build' Makefile:837: recipe for target 'all' failed make: *** [all] Error 2
原因:libatomic未禁用。
解決:在前一步的configure選項中,加入 --disable-libatomic 選項 (另一個方案,自己沒試,供參考)
6.安裝 Linux API 頭文件, 解壓內核。之前在程序包說明的部分提到內核要用最新的
Linux 內核相對經常更新,經常是因為發現了新的安全弱點。只要勘誤表沒有聲明,總應該使用最新的 3.10.x 內核版本。
對於速度受限或者帶寬昂貴的用戶,想要升級 Linux 內核,可以分別下載程序包的基線版本和補丁。這可能會節省一些時間或開銷。
在這下載patch文件,解壓到內核目錄,用這個命令將補丁打上
patch -p1 < patch-3.10.36
其中,patch-3.10.36 為解壓后的補丁文件
7.編譯glibc, configure錯誤:
checking for autoconf... autoconf
checking whether autoconf works... no
configure: error:
*** These critical programs are missing or too old: make
*** Check the INSTALL file for required versions.
fuck,這個問題如此困難,是make版本的問題。而我用的lfs因為要看中文的,所以不是最新的,也就會有版本相關的bug。踏破鐵鞋,搜到一個解決辦法,給glibc-2.17里的configure打個補丁,點擊此處下載該補丁,即configure-make4.patch ,放到glibc-2.17的目錄,然后在該目錄執行:
patch <configure-make4.patch
下載這個文件可能需要fuck the gfw,在下面貼出此patch的內容:
--- configure 2012-12-19 18:06:09.792647617 +0200 +++ configure.fix 2013-10-31 01:14:26.479246078 +0200 @@ -4936,7 +4936,7 @@ ac_prog_version=`$MAKE --version 2>&1 | sed -n 's/^.*GNU Make[^0-9]*\([0-9][0 -9.]*\).*$/\1/p'` case $ac_prog_version in '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; - 3.79* | 3.[89]*) + 3.79* | 3.[89]* | 4.[01]*) ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
之后make出錯:
/mnt/lfs/sources/glibc-build/resolv/libresolv_pic.a(gethnamaddr.os):/mnt/lfs/sources/glibc-2.17/resolv/gethnamaddr.c:636: more undefined references to `__stack_chk_guard' follow collect2: error: ld returned 1 exit status ../Makerules:446: recipe for target '/mnt/lfs/sources/glibc-build/resolv/libresolv.so' failed make[2]: *** [/mnt/lfs/sources/glibc-build/resolv/libresolv.so] Error 1 make[2]: Leaving directory '/mnt/lfs/sources/glibc-2.17/resolv' Makefile:233: recipe for target 'resolv/others' failed make[1]: *** [resolv/others] Error 2 make[1]: Leaving directory '/mnt/lfs/sources/glibc-2.17' Makefile:9: recipe for target 'all' failed make: *** [all] Error 2
問題居然出在第一遍gcc時那句:
sed -i '/k prot/agcc_cv_libc_provides_ssp=yes' gcc/configure
忘了執行……fuck!! stupid!!,之前光查它什么意思了,忘了運行之,只好再搞一遍……
8.第二遍binutils, 如果是重新解壓的,不要忘了到binutils-2.23.2目錄里執行那條sed命令。
9.第二遍gcc,configure出錯:
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+. Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify their locations.
前面沒理解對,這一步
tar -Jxf ../mpfr-3.1.2.tar.xz mv -v mpfr-3.1.2 mpfr tar -Jxf ../gmp-5.1.2.tar.xz mv -v gmp-5.1.2 gmp tar -zxf ../mpc-1.0.1.tar.gz mv -v mpc-1.0.1 mpc
mpfr,gmp,mpc三個文件夾的正確位置應為gcc-4.8.1目錄,我誤以為直接在$LFS/source目錄解壓然后重命名了……
10.沒有第10條。接下來的包順利地一塌糊塗,直接闖到了第三部分,編制LFS!
to be continued...