LFS-6.1.1实践笔记

来源:互联网 发布:剑三捏脸数据图片成男 编辑:程序博客网 时间:2024/06/06 13:56
+-----------------------------------------------------------------------------+
|                         第一部分 文档说明                                   |
+-----------------------------------------------------------------------------+
1 作用
##########
   LFS-6.1.1实践笔记
   (与LFS-6.1.1手册一起查阅)

2 版权
######
  版权: 聂大鹏

3 组织与作者
############
3.1 作者
========
3.1.1 作者1
-----------
   姓名: 聂大鹏
   email: dozec@mail.csdn.net

4 产生时间
##########
  时间: 2007-2-6

5 版本
######
  版本: 0.1 版

6 修订过程
##########

7 目录
######
  0 实验环境说明
  1 介绍(其下每章节均与LFS6.1.1对应)
  2 准备分区
  3 软件包和补丁
  4 最后的准备工作
  5 构建临时编译环境
  6 安装系统基础软件
  7 配置系统启动脚本
  8 参考文档



+-----------------------------------------------------------------------------+
|                         第二部分 文档正文                                   |
+-----------------------------------------------------------------------------+
0 实验环境说明
##############
0.1 实验环境
============
工作站: RHEL4
        Linux version 2.6.14.7
        gcc version 3.4.6 20060404 (Red Hat 3.4.6-3))
        CPU: Pentium 1.7G
        Memory: 256MB
        装LFS根分区: /dev/hdd1 (hdd是一块4.3G硬盘)
           swap分区: /dev/hdd2
        /dev/hdd1               1         427     3429846   83  Linux
        /dev/hdd2             428         524      779152+  82  Linux swap


0.2 相关文档
============
  a). 做一个功能单一,体积小巧的LFS
      http://www.linuxsir.org/bbs/showthread.php?t=233228
  b). "我们可以做的更小!《功能单一,体积小巧的LFS》续篇"
      http://www.linuxsir.org/bbs/showthread.php?t=236599
  c). 从按下电源开关到bash提示符
      Ch: http://users.rsise.anu.edu.au/%7Eokeefe/p2b/chinese/power2bash.html
      En: http://axiom.anu.edu.au/%7Eokeefe/p2b/
  d). Software-Building-HOWTO
      http://www.tldp.org/HOWTO/Software-Building-HOWTO.html
      (这是一份详尽的关于在 Linux 下编译安装"一般的" Unix 软件的指南)
  e). The Linux Users' Guide
      http://www.linuxhq.com/guides/LUG/guide.html
      (这份指南涵盖了各类 Linux 软件的用法)
  f). The Essential Pre-Reading Hint
      http://www.linuxfromscratch.org/hints/downloads/files/essential_prereading.txt
      一份专为 Linux 新手而写的 LFS 提示,包括一份链接列表,这接的信息源包含的主题非常广泛而且内容很棒
  g). LFS 初学者注意事项
      http://www.linuxsir.org/bbs/showthread.php?t=231446
      这是 LinuxSir.Org 上 LFS 版主"终极幻想"专为 LFS 新手而写的注意事项,中文.
  h). lfs-6.1.1勘误表
      http://www.linuxfromscratch.org/lfs/errata/6.1.1/
  i). 制作 LFS 过程中各个阶段恢复工作状态的详细方法.
      http://www.linuxsir.org/bbs/showthread.php?t=242880
  k). LFS FAQ
      http://www.linuxfromscratch.org/faq/
  l). LFS Maillist
      http://www.linuxfromscratch.org/search.html 搜索邮件
  m). 软件包附加信息
      http://www.linuxfromscratch.org/~matthew/LFS-references.html
  n). LFS-6.1-2 安装实录[附带全过程的详细命令]把路径写全了.
      http://www.linuxsir.org/bbs/showthread.php?t=223177
  o). 手把手教你如何建立自己的Linux系统(LFS速成手册)---> 肯定成功
      http://www.linuxsir.org/bbs/showthread.php?t=244052
  p). 如何使LFS安装在一个系统已存分区上
      http://www.linuxfromscratch.org/hints/downloads/files/lfs_next_to_existing_systems.txt
  q). 编译器优化(第6章P144)
      http://www.linuxfromscratch.org/hints/downloads/files/optimization.txt
      GCC 编译选项及优化提示
      http://www.linuxsir.org/bbs/showthread.php?t=222670
  r). 可以使用一个包管理工具来跟踪每个包安装和修改了那些程序。(第6章P145)
      参考下列页面看看各种不同风格的包管理工具:
      http://www.linuxfromscratch.org/blfs/view/svn/introduction/important.html
      推荐的特别适合于LFS的管理包的方法请参见:
      http://www.linuxfromscratch.org/hints/downloads/files/more_control_and_pkg_man.txt
  s). FHS(Filesystem Hierarchy Standard) 标准
      http://www.pathname.com/fhs/
  t). BSD风格启动初始化(RedHat上为System-V的风格)
      http://www.linuxfromscratch.org/hints/downloads/files/bsd-init.txt


0.3 待查阅
==========
  a).Udev与Sysfs
    使用 Udev 需要 2.6.2 或者更新版本的内核,Udev 通过读取 sysfs 文件系统动态的创建设备.
    另起文档.


1 介绍(其下每章节均与LFS6.1.1对应)
##################################
1.1 备注
========
  a).安装LFS的2种途径. -> 已安装好的Linux发行版上去构建LFS
                       -> 通过LFS的LiveCD,包含有构建LFS的一切工具及软件包
                          下载地址: http://www.linuxfromscratch.org/livecd/

  b). configure脚本的错误记得检查config.log


2 准备分区
##########
2.1 备注
========
  a). 建立LFS需要一个新分区, 当建立一个小的LFS时,分区需要1.3G.
      若想让该系统成为你工作的主系统,需要2~3G. 实验当中的/dev/hdd1为4G.够了.
      /dev/hdd1的文件系统为ext3.

  b). 创建LFS需要有一个swap分区.实验工作站上已经有swap分区了.实验当中LFS使用
      工作站的swap分区.
      #mkswap用于创建一个swap分区.
      #swapon /dev/xxx  激活swap分区. <----> #swapoff

  c). 创建LFS环境变量并挂载分区.
      [root@hellokitty ~]# export LFS=/mnt/lfs
      [root@hellokitty ~]# mkdir -p /mnt/lfs
      [root@hellokitty ~]# mount /dev/hdd1 $LFS
      [root@hellokitty ~]# ls /$LFS
      lost+found


3 软件包和补丁
##############
3.1 操作笔记
============
  a). 实验之前,我先下载了LiveCD(lfslivecd-x86-6.1-1-4.iso),其中包含了构建LFS
      需要用的软件包及补丁包. LiveCD中的软件包及补丁包存放在工作站当中的
      $LFS/source目录中.
      [root@hellokitty ~]# mkdir -p $LFS/sources
      [root@hellokitty ~]# chmod 1777 $LFS/sources

      看了眼LFS-6.1.1中的软件链接列表....n多全是GNU的(http://ftp.gnu.org/gnu/automake)
      还有一些是从Kernel.org中的(http://www.kernel.org/pub/linux/devel/binutils/)

  b). 我是通过NFS将LiveCD当中的软件包及补丁包拷贝到本机的.
      大体步骤如下:
      NFS Server(真实机器:EL4):
      修改/etc/exports文件: 加入/var/ftp/pub/lfs_source *(rw,sync)
                            共享出/var/ftp/pub/lfs_source目录
                            并且lfs_source目录其权限要给777,否则无写权限.
      # service portmap restart
      # service nfs restart
      该目录暂存放一下从LiveCD的/lfs-sources目录当中拷过来的软件包及补丁.
      然后复制到$LFS/sources目录当中.


      NFS Client(EL4上跑的虚拟机,里面运行的是LiveCD):
      # /etc/rc.d/init.d/portmap start
      # /etc/rc.d/init.d/nfs-client start
      # mount 172.16.109.1:/var/ftp/pub/lfs_source /mnt  
        (109.1是vmnet1的地址, vmware网络为Host-only)
      # cp -rf /lfs-sources/* /mnt

  c). 在LiveCD直接构建LFS也比较easy, 但感觉如果中途重启机器.就需要重新配置LFS用户环境
      等其它重复工作了.  在工作站上直接构建LFS, 如果重启机器, 起来之后只要
      1. export LFS=/mnt/lfs   (加到/etc/profile也是很可行)
      2. mount /dev/hdd1 $LFS
      3. alias ls='/bin/ls --color'
      就可以了.
      另外实验机器就256MB Memory, 实在耗不起vmware.  多留点内存加快编译速度也好呀.


4 最后的准备工作
################
4.1 操作笔记
============
  a). 创建$LFS/tools目录,里面存放临时编译工具链.以避免与最后安装的系统基础软件冲突.
      [root@hellokitty ~]# mkdir -p $LFS/tools
      [root@hellokitty ~]# ln -sv $LFS/tools /
      [root@hellokitty ~]# ll -d /tools       (创建一个符号链接/tools)
      lrwxrwxrwx  1 root root 14  2月  5 21:55 /tools -> /mnt/lfs/tools
      [root@hellokitty ~]# chmod 777 $LFS/tools

  b). 创建lfs用户,设置密码
      # groupadd lfs
      # useradd -s /bin/bash -g lfs -m -k /dev/null lfs
      # passwd -d lfs

      将$LFS/tools and sources目录的属主设置为lfs用户.
      [root@hellokitty lfs]# chown lfs $LFS/tools
      [root@hellokitty lfs]# chown lfs $LFS/sources

  c). 设置~/.bash_profile, 此文件会在登陆shell/su命令加-执行调用.(例如#su - dozec)
      [root@hellokitty lfs]# su - lfs
      -bash-3.00$   cat > ~/.bash_profile << EOF  (将屏幕上的输入重定向到.bash_profile)
      > exec env -i  HOME=$HOME TERM=$TERM PS1="[/u@/h /W]//$ " /bin/bash
      > Ctrl+D  
      (env -i参数start with an empty environment, 除了HOME/TERM/PS1环境变量无其它.
       其目的是避免其后操作被潜在的环境变量所影响.)
      -bash-3.00$
      -bash-3.00$ exit
      logout
      [root@hellokitty lfs]# su - lfs
      [lfs@hellokitty ~]$    会看到这里的刚才设置的PS1已经生效了.
      

      再设置~/.bashrc, 此文件会在进行subshell/执行su命令时/进入x-windows启动终端
      3种情况均会调用该文件.
      [lfs@hellokitty ~]$ cat > ~/.bashrc << EOF
      > set +h
      > PATH=/tools/bin:/bin:/usr/bin
      > umask 022
      > LFS=/mnt/lfs
      > LC_ALL=POSIX
      > export PATH LFS LC_ALL
      > Ctrl+D
      说明:1. set +h用于关闭hash与$PATH当中/tools/bin/放在最前的目的是新工具一旦安装完成,
              就直接使用/tools/bin下的新工具链,而避免使用旧的工具链.
           2. LC_ALL 环境变量控制着某些程序的本地化,使其显示的信息遵循指定国家的惯例。
              请把 LC_ALL 设置为"POSIX"或"C"(这两者是等价的)以确保在 chroot 环境中的
              所有东西都像预期的那样正常工作。

      [lfs@hellokitty ~]$ ls .
      ./             ../            .bash_history  .bash_profile  .bashrc
      
      注意: 切换到lfs用户时最好用#su - lfs.  因为存在有~/.bash_profile文件.

  d). 其实如果不使用lfs用root也是能完成工具链的,不过需要对root的环境变量进行修改,
      还要防止因为输入错误而导致覆盖主系统下的文件,所以LFS手册中制作工具链部分就是
      为了解决这种意外的发生而用lfs用户来建立工具链. (ID: youbest on linuxsir.org)

  e). 有的软件包包含测试程序(例如:GCC, Binutils, Glibc), 运行这些测试程序可以检验软件包
      是否按照开发者的意愿来工作.


5 构建临时编译环境
##################
5.1 笔记
========
  a). 构建这个小系统分两步进行:
      第一步是构建一个新的不依赖于宿主系统的GNU工具链. (第5章)
      (本章就干这个,  工具链安装到/tools --> $LFS/tools当中.)
      第二个步骤是利用这个工具链去构建其它基本的工具.(第6章)

      第5章干的就是构建一个不依赖于宿主系统的GNU工具链(当然还包括一些基础工具,
      例如sed/gawk/diff/patch等),
      当这个独立的GNU tool chain构建好后,我们就可以chroot到$LFS当中,用这条工具链
      来编译生成最终LFS系统当中存在的软件包.为什么不用宿主系统的GNU tool chain,就是因为我们要
      chroot $LFS后, 宿主系统当中的头文件/库文件我们就不能用了.
      而我们现在构建的这个不依赖于宿主系统的GNU工具链又恰恰是基于已经存在于宿主系统的工具链
      完成的. 这个关系要理解好.

  b). 先装Binutils(Binutils是kernel.org发布的.提供了汇编器as/链接器ld等二进制工具.)
      再装GCC.
      再装Glibc.

  c). Binutils需要注意处:
      target triplet(工作站EL4的工作平台)
      [lfs@hellokitty binutils-2.15.94.0.2.2]$ ./config.guess
      i686-pc-linux-gnu
      
      工作站EL4的动态链接器.
      [lfs@hellokitty binutils-2.15.94.0.2.2]$ readelf -l /bin/ls | grep interpreter
      [Requesting program interpreter: /lib/ld-linux.so.2]
      动态链接器就是一动态库,程序运行时由ld-linux.so.2来加载程序运行所需的其它动态库.

      链接器是.o文件连接时生成可执行文件时使用.
      工作站上用的链接器的库搜索顺序.
      [lfs@hellokitty binutils-2.15.94.0.2.2]$ ld --verbose | grep SEARCH
      SEARCH_DIR("/usr/i386-redhat-linux/lib");
      SEARCH_DIR("/usr/local/lib");
      SEARCH_DIR("/lib");
      SEARCH_DIR("/usr/lib");
      
  d). GCC需要注意处:
      通过./configure脚本的输出/tools/i686-pc-linux-gnu/bin/as
      -->判定是使用我们工作链的as,而非工作站上的.

      工作站EL4上GCC所用的链接器
      [lfs@hellokitty binutils-2.15.94.0.2.2]$ gcc -print-prog-name=ld
      ld

      # gcc -v a.c  通过-v显示预处理/编译/汇编各阶段信息.
       -v  Print (on standard error output) the commands executed to run
           the stages of compilation. Also print the version number of the
           compiler driver program and of the preprocessor and the compiler proper.


5.2 操作步骤
============
  0)  要强调的就是:
      装完软件包后就删除源码目录和编译目录.除非LFS-6.1.1明确表示不用删除.!!!

  1). 安装binutils(as/ld).
      [lfs@hellokitty sources]$ pwd
      /mnt/lfs/sources
      [lfs@hellokitty sources]$  tar -jxvf binutils-2.15.94.0.2.2.tar.bz2
      [lfs@hellokitty sources]$ cd binutils-2.15.94.0.2.2
      [lfs@hellokitty binutils-2.15.94.0.2.2]$ patch -Np1 -i ../binutils-2.15.94.0.2.2-gcc4-1.patch
      -N参数是ignore 逆向补丁,就是diff时旧文件与新文件写反了产生出的补丁文件
      -i参数是读取patch.  以前不一直是用输入重定向嘛 <

      [lfs@hellokitty binutils-2.15.94.0.2.2]$ mkdir -v ../binutils-build
      [lfs@hellokitty binutils-2.15.94.0.2.2]$ cd ../binutils-build/
      [lfs@hellokitty binutils-build]$ time { ../binutils-2.15.94.0.2.2/configure
       --prefix=/tools --disable-nls && make && make install; } 回车
       --prefix指明软件包中的程序装到哪个目录当中.
       --disable-nls禁止国际化(i18n),静态程序不需要国际化特性.
      结束后输入:
      real    6m7.964s  <-- ( SBU. )
      user    3m0.407s
      sys     0m56.336s

      [lfs@hellokitty binutils-build]$ make -C ld clean
      进入ld子目录,执行clean动作, 也就是清除ld目录下的可执行文件.

      [lfs@hellokitty binutils-build]$ make -C ld LIB_PATH=/tools/lib
      重新编译ld目录当中的文件.主要是指明LIB_PATH变量->指明了连接器的默认库搜索路径.

      最后,没有删除binutils的源码目录及编译目录.


  2). GCC-3.4.3(c/c++ compiler) 第1遍
     [lfs@hellokitty sources]$ tar -jxvf gcc-3.4.3.tar.bz2
     [lfs@hellokitty sources]$ mkdir gcc-build
     [lfs@hellokitty sources]$ cd gcc-build/
     [lfs@hellokitty gcc-build]$ ../gcc-3.4.3/configure --prefix=/tools --libexecdir=/tools/lib
     --with-local-prefix=/tools --disable-nls --enable-shared --enable-language=c && make bootstrap

     --with-local-prefix=/tools    把/usr/local/include从GCC的包含文件搜索路径中删除.
                                   (不一定必要)

     --enable-shared            只有加上此参数,才能编译出libgcc_s.so.1 and libgcc_eh.a.
                                 Glibc的配置脚本只有找到libgcc_eh.a才能确保成功.
     --enable-language=c        只编译GCC软件包中的C compiler.  

     make bootstrap             使用bootstrap参数的是指示GCC反复编译几次.它用第一次生成的compiler
                                来编译自己,然后用第二次生成的compiler来第三次编译自己,最后比较第二
                                次和第三次编译的结果,以确保compiler正确.
    
     [lfs@hellokitty gcc-build]$ make install

     创建cc这个符号链接,使其指向GCC(EL这个平台上是/usr/bin/cc->gcc)
     [lfs@hellokitty gcc-build]$ ln -s gcc /tools/bin/cc
     [lfs@hellokitty gcc-build]$ ll -d /tools/bin/cc /tools/bin/gcc
     lrwxrwxrwx  1 lfs lfs      3 Feb  7 19:36 /tools/bin/cc -> gcc
     -rwxr-xr-x  3 lfs lfs 175273 Feb  7 19:26 /tools/bin/gcc

     @@最后,删除gcc-build and gcc-3.4.3
     [lfs@hellokitty sources]$ rm -rf gcc-build/
     [lfs@hellokitty sources]$ rm -rf gcc-3.4.3

 
  3). Linux-Libc-Headers-2.6.11.2
      以前/usr/include存放的都是内核当中的头文件(直接来源于内核的tar包中的include),
      但由于内核开发者建议不要这么做,所以就产生了Linux-Libc-Headers API 头文件.
      确实是这样,内核头文件与Userspace态开发程序的头文件是不一致的.

     [lfs@hellokitty sources]$ tar -jxvf linux-libc-headers-2.6.11.2.tar.bz2
     [lfs@hellokitty sources]$ cd linux-libc-headers-2.6.11.2
     [lfs@hellokitty linux-libc-headers-2.6.11.2]$ cp -rf include/asm-i386 /tools/include/asm
     [lfs@hellokitty linux-libc-headers-2.6.11.2]$ cp -rf include/linux/ /tools/include/
     [lfs@hellokitty linux-libc-headers-2.6.11.2]$ cd ..
     [lfs@hellokitty sources]$ rm -rf linux-libc-headers-2.6.11.2


  4). Glibc 2.3.4
     [lfs@hellokitty sources]$ tar -jxvf glibc-2.3.4.tar.bz2
     [lfs@hellokitty sources]$ cd glibc-2.3.4
     [lfs@hellokitty glibc-2.3.4]$ patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch
     该补丁的作用是解决在2.6.11 kernel下, Glibc会有2个测试项目不能通过(属于测试程序的原因)     

     [lfs@hellokitty glibc-2.3.4]$ mkdir ../glibc-build
     [lfs@hellokitty glibc-2.3.4]$ cd ../glibc-build/

     [lfs@hellokitty glibc-build]$ ../glibc-2.3.4/configure --prefix=/tools /
     > --disable-profile --enable-add-ons /
     > --enable-kernel=2.6.0 --with-binutils=/tools/bin /
     > --without-gd --with-headers=/tools/include /
     > --without-selinux && make
     
     --enable-add-ons   指定Glibc使用附加的NPTL包作为线程序库
     --enable-kernel=2.6.0  通知Glibc编译支持2.6.x内核的库.
                            此处只是为了说明kernel的大版本,所以不需要根据实际的
                            kernel版本来改,即使是用linux-2.6.15也一样只写2.6.0就可以了。
                            (ID : youbest on linuxsir.org)
     --with-binutils=/tools/bin  非必须,但其会保证在编译Glibc时不会用错Binutils程序.
     --with-headers=/tools/include  前面的头文件是安装到/tools/include当中.现在就指定
                                    Glibc使用这里的头文件来编译自己.
     --without-selinux   当从一个含有selinux特性的系统中编译时,Glibc会将selinux支持包含进来.
                         这里是禁止这么做,因为LFS并不包含selinux的支持.

    在这里执行如下语句进行测试没有什么用处,而且很费时间(跑了半个点).
    [lfs@hellokitty glibc-build]$ make check

    提前touch一个ld.so.conf文件,这样在其后安装Glibc过程当中就不会出现警告说少了这个文件.
    [lfs@hellokitty glibc-build]$ mkdir -p /tools/etc/
    [lfs@hellokitty glibc-build]$ touch /tools/etc/ld.so.conf
    
    安装glibc
    [lfs@hellokitty glibc-build]$ make install

    [lfs@hellokitty glibc-build]$ make localedata/install-locales
    
    [lfs@hellokitty sources]$ rm -rf glibc-2.3.4
    [lfs@hellokitty sources]$ rm -rf glibc-build/


  5).调用工具链: 现在临时的C库已经装好了.接下来是要把以后编译的所有软件包全部
                 链接到刚刚装好的Glibc上. 为达到这个目标,需要做2件事.
     5.1).调整ld, 使其库搜索路径为/tools/lib,这个在5.3节如下2条语句已经完成,
          # make -C ld clean
          # make -C ld LIB_PATH=/tools/lib
          此处只需要安装生成好的ld就可以了.
          [lfs@hellokitty sources]$ cd binutils-build/
          [lfs@hellokitty binutils-build]$ make -C ld install

          [lfs@hellokitty binutils-build]$ cd ..
          [lfs@hellokitty sources]$ rm -rf binutils-2.15.94.0.2.2
          [lfs@hellokitty sources]$ rm -rf binutils-build/

 
     5.2).调整GCC的specs文件,目的是把/lib/ld-linux.so.2 替换成 /tools/lib/ld-linux.so.2
          指向新的动态库加载器.
          [lfs@hellokitty sources]$ SPECFILE=`gcc --print-file specs` && sed 's@ /lib/ld-linux.so.2@ /tools/lib/ld-linux.so.2@g' $SPECFILE > tempspecfile && mv -f tempspecfile $SPECFILE && unset SPECFILE

         将自己工具链当中的可能存在的宿主系统当中潜入的头文件删除.(GCC的fixincludes脚本导致的.)
         [lfs@hellokitty sources]$ rm -vf /tools/lib/gcc/*/*/include/{pthread.h,bits/sigthread.h}

     5.3).检查工具链是否正常工作.
         [lfs@hellokitty sources]$ echo 'main() {}' > dummy.c
         [lfs@hellokitty sources]$ cc dummy.c
         [lfs@hellokitty sources]$ readelf -l a.out | grep ': /tools'
         [Requesting program interpreter: /tools/lib/ld-linux.so.2]
                                          这里是/tools/lib/就正确.库已经连接到/tools/lib下了.
         [lfs@hellokitty sources]$ rm -rf dummy.c a.out


  6). Tcl-8.4.9 以及Expect and DejaGNU都是为了运行GCC/binutils的测试程序(make check)提供支持的.
     [lfs@hellokitty sources]$ tar -jxvf tcl8.4.9-src.tar.bz2
     [lfs@hellokitty sources]$ cd tcl8.4.9/unix/
     [lfs@hellokitty unix]$ ./configure --prefix=/tools
     [lfs@hellokitty unix]$ make && make install
     然后不删除tcl8.4.9这个源码目录,因为其后的安装需要这里的头文件.

     设置一个环境变量来指向TCL头文件目录的完整路径.(Expect要使用)
     [lfs@hellokitty unix]$ cd ..
     [lfs@hellokitty tcl8.4.9]$ export TCLPATH=$(pwd)
     [lfs@hellokitty tcl8.4.9]$ echo $TCLPATH
     /mnt/lfs/sources/tcl8.4.9
     [lfs@hellokitty tcl8.4.9]$ ln -s tclsh8.4 /tools/bin/tclsh
     [lfs@hellokitty tcl8.4.9]$ ll -d /tools/bin/tclsh
     lrwxrwxrwx  1 lfs lfs 8 Feb  7 22:18 /tools/bin/tclsh -> tclsh8.4

  7). Expect-5.43.0
     [lfs@hellokitty sources]$ tar -jxvf expect-5.43.0.tar.bz2
     [lfs@hellokitty sources]$ cd expect-5.43
     [lfs@hellokitty expect-5.43]$ patch -Np1 -i ../expect-5.43.0-spawn-1.patch  
     [lfs@hellokitty expect-5.43]$ ./configure --prefix=/tools --with-tcl=/tools/lib --with-tclinclude=$TCLPATH --with-x=no

     --with-tcl=/tools/lib  指定找到我们安装的tcl.而非宿主系统当中的tcl.
     --with-tclinclude=$TCLPATH  告知expect去哪里寻找tcl的源码/头文件
     --with-x=no  告知configure脚本不要去搜索tk(tcl的图形界面组件)以及x-windows的库,会从宿主系统上找到的.


     [lfs@hellokitty expect-5.43]$ make
     [lfs@hellokitty expect-5.43]$ make SCRIPTS="" install
     SCRIPTS=""  这个选项防止安装 Expect 所补充的一些并不需要的脚本。

     [lfs@hellokitty expect-5.43]$ unset TCLPATH
     [lfs@hellokitty sources]$ rm -rf tcl8.4.9
     [lfs@hellokitty sources]$ rm -rf expect-5.43


  8). DejaGNU-1.4.4
      [lfs@hellokitty sources]$ tar -jxvf dejagnu-1.4.4.tar.bz2
      [lfs@hellokitty dejagnu-1.4.4]$ ./configure --prefix=/tools && make install
      [lfs@hellokitty dejagnu-1.4.4]$ cd ..
      [lfs@hellokitty sources]$ rm -rf dejagnu-1.4.4


  9). GCC-3.4.3 pass 2
     [lfs@hellokitty sources]$ tar -jxvf gcc-3.4.3.tar.bz2
     [lfs@hellokitty sources]$ cd gcc-3.4.3
     [lfs@hellokitty gcc-3.4.3]$ patch -Np1 -i ../gcc-3.4.3-no_fixincludes-1.patch
                                 该补丁作用禁止Gcc中的fixincludes脚本运行,防止宿主机
                                 中的头文件混到我们自己编译工具链的头文件当中.
     [lfs@hellokitty gcc-3.4.3]$ patch -Np1 -i ../gcc-3.4.3-specs-2.patch
                                 事先修改specs文件->保证新动态库加载器在编译Gcc的时候
                                 就用上了.这样随后编译的所有程序都会连接到新的Glibc上.
                                 并且把/usr/include从Gcc的头文件搜索路径中删除.

    由于我所使用的内核是2.6.14,所以下载该补丁并且打上.
    [lfs@hellokitty sources]$ wget http://www.linuxfromscratch.org/patches/downloads/gcc/gcc-3.4.3-pch-1.patch     [lfs@hellokitty sources]$ cd gcc-3.4.3
    [lfs@hellokitty gcc-3.4.3]$ patch -Np1 -i ../gcc-3.4.3-pch-1.patch


    [lfs@hellokitty gcc-3.4.3]$ mkdir ../gcc-build
    [lfs@hellokitty gcc-3.4.3]$ cd ../gcc-build/
    [lfs@hellokitty gcc-build]$ ../gcc-3.4.3/configure --prefix=/tools /
    > --libexecdir=/tools/lib --with-local-prefix=/tools /
    > --enable-clocale=gnu --enable-shared /
    > --enable-threads=posix --enable-__cxa_atexit /
    > --enable-languages=c,c++ --disable-libstdcxx-pch

    --enable-clocale=gnu 本参数确保C++库在任何情况下都使用正确的locale模块
    --enable-threads=posix  使c++异常能够处理线程代码
    --enable-__cxa_atexit 用 __cxa_atexit 代替atexit来登记C++对象的本地静态和全局析构函数,
                          这是为了完全符合标准对析构函数的处理规定。
    --enable-languages=c,c++  本参数编译 C 和 C++ 语言的编译器。
    --disable-libstdcxx-pch 不为 libstdc++ 编译预编译头(PCH)


    [lfs@hellokitty gcc-build]$ make && make install
    [lfs@hellokitty gcc-build]$ cd ..
    [lfs@hellokitty sources]$ rm -rf gcc-build/
    [lfs@hellokitty sources]$ rm -rf gcc-3.4.3



    做测试.
    [lfs@hellokitty sources]$ echo 'main(){}' > dummy.c
    [lfs@hellokitty sources]$ cc dummy.c
    [lfs@hellokitty sources]$ readelf -l a.out | grep SEARCH
    [lfs@hellokitty sources]$ readelf -l a.out | grep ': tools'
    [lfs@hellokitty sources]$ readelf -l a.out | grep ': /tools'
         [Requesting program interpreter: /tools/lib/ld-linux.so.2]
         编译过程没有问题,而且动态连接器是/toosl/lib/就OK了
    [lfs@hellokitty sources]$ rm -rf dummy.c a.out


 
  10). Binutils pass 2
    [lfs@hellokitty sources]$ tar -jxvf binutils-2.15.94.0.2.2.tar.bz2
    [lfs@hellokitty sources]$ mkdir binutils-build
    [lfs@hellokitty sources]$ cd binutils-build/
    [lfs@hellokitty binutils-build]$ ../binutils-2.15.94.0.2.2/configure --prefix=/tools /
    > --disable-nls --enable-shared --with-lib-path=/tools/lib
    --with-lib-path=/tools/lib 指定库搜索路径为/tools/lib, 以避免去搜索宿主系统的库目录.    

    [lfs@hellokitty binutils-build]$ make && make install

    [lfs@hellokitty binutils-build]$ make -C ld clean
    [lfs@hellokitty binutils-build]$ make -C ld LIB_PATH=/usr/lib:/lib

    *注意:这里不要删除binutils-build,因为到制作目标系统的时候需要用到它!


  11). Gawk-3.1.4
    [lfs@hellokitty sources]$ tar -jxvf gawk-3.1.4.tar.bz2
    [lfs@hellokitty sources]$ cd gawk-3.1.4
    [lfs@hellokitty gawk-3.1.4]$ ./configure --prefix=/tools && make && make install   
    [lfs@hellokitty gawk-3.1.4]$ cd ..
    [lfs@hellokitty sources]$ rm -rf gawk-3.1.4


  12). Coreutils-5.2.1(包含有tail/head/sort命令)
    [lfs@hellokitty sources]$ tar -jxvf coreutils-5.2.1.tar.bz2
    [lfs@hellokitty sources]$ cd coreutils-5.2.1
    [lfs@hellokitty coreutils-5.2.1]$ DEFAULT_POSIX2_VERSION=199209 ./configure --prefix=/tools && make && make install

    DEFAULT_POSIX2_VERSION=199209  获得向后兼容性,因为coreutils当中的命令有的使用了老式语法.
                                   (高于Glibc2.3.2的时候出现这种情况,临时工具链是glib-2.3.4)

    执行测试
    [lfs@hellokitty coreutils-5.2.1]$ make RUN_EXPENSIVE_TESTS=yes check
    
    [lfs@hellokitty coreutils-5.2.1]$ cd ..
    [lfs@hellokitty sources]$ rm -rf coreutils-5.2.1


  13). Bzip2-1.0.3
    [lfs@hellokitty sources]$ tar -jxvf bzip2-1.0.3.tar.bz2
    [lfs@hellokitty sources]$ cd bzip2-1.0.3
    [lfs@hellokitty bzip2-1.0.3]$ make && make PREFIX=/tools install
    [lfs@hellokitty bzip2-1.0.3]$ cd ..
    [lfs@hellokitty sources]$ rm -rf bzip2-1.0.3


  14). Gzip-1.3.5
    [lfs@hellokitty sources]$ tar -jxvf gzip-1.3.5.tar.bz2
    [lfs@hellokitty sources]$ cd gzip-1.3.5
    [lfs@hellokitty gzip-1.3.5]$ ./configure --prefix=/tools && make && make install
    [lfs@hellokitty gzip-1.3.5]$ cd ..
    [lfs@hellokitty sources]$ rm -rf gzip-1.3.5


  15). Diffutils-2.8.1 (包含diff->来生成补丁的程序)
    [lfs@hellokitty sources]$ tar -jxvf diffutils-2.8.1.tar.bz2
    [lfs@hellokitty sources]$ cd diffutils-2.8.1
    [lfs@hellokitty diffutils-2.8.1]$ ./configure --prefix=/tools && make && make install
    [lfs@hellokitty diffutils-2.8.1]$ cd ..
    [lfs@hellokitty sources]$ rm -rf diffutils-2.8.1

  16). Findutils-4.2.23 (看介绍,包含的应该是find/updatedb/locate命令)
    [lfs@hellokitty sources]$ tar -jxvf findutils-4.2.23.tar.bz2
    [lfs@hellokitty sources]$ cd findutils-4.2.23
    [lfs@hellokitty findutils-4.2.23]$ ./configure --prefix=/tools && make && make install
    [lfs@hellokitty findutils-4.2.23]$ cd ..
    [lfs@hellokitty sources]$ rm -rf findutils-4.2.23


  17). Make-3.80
    [lfs@hellokitty sources]$ tar -jxvf make-3.80.tar.bz2
    [lfs@hellokitty sources]$ cd make-3.80
    [lfs@hellokitty make-3.80]$ ./configure --prefix=/tools && make && make install

    make check测试结果.
    [lfs@hellokitty make-3.80]$ make check

    [lfs@hellokitty make-3.80]$ cd ..
    [lfs@hellokitty sources]$ rm -rf make-3.80

  18). Grep-2.5.1a
    [lfs@hellokitty sources]$ tar -jxvf grep-2.5.1a.tar.bz2
    [lfs@hellokitty sources]$ cd grep-2.5.1a
    [lfs@hellokitty grep-2.5.1a]$ ./configure --prefix=/tools --disable-perl-regexp && make && make install
    --disable-perl-regexp  指明grep不去连接宿主系统当中的perl兼容表达式库,因为在第6章
                           chroot环境后,就不能使用宿主系统当中的anything.
    
    [lfs@hellokitty grep-2.5.1a]$ cd ..
    [lfs@hellokitty sources]$ rm -rf grep-2.5.1a


  19). Sed-4.1.4
    [lfs@hellokitty sources]$ tar -jxvf sed-4.1.4.tar.bz2
    [lfs@hellokitty sources]$ cd sed-4.1.4
    [lfs@hellokitty sed-4.1.4]$ ./configure --prefix=/tools && make && make install
    [lfs@hellokitty sed-4.1.4]$ cd ..
    [lfs@hellokitty sources]$ rm -rf sed-4.1.4


  20). Gettext-0.14.3 (用于系统国际化和本地化的工具,能完成你的程序输出是按照你的本地设置而非英文)
   [lfs@hellokitty sources]$ tar -jxvf gettext-0.14.3.tar.bz2
   [lfs@hellokitty sources]$ cd gettext-0.14.3
   [lfs@hellokitty gettext-0.14.3]$ ./configure --prefix=/tools --disable-libasprintf --without-csharp && make && make install
   --disable-libasprintf 不编译asprintf库,节省时间和空间.
   --without-csharp 不使用c#编译器(不理解了... linux上也有c#这玩意, 这东西不就跑在.net上的嘛.
                                   查了一下,mono提供了c#编译器和运行.)

   [lfs@hellokitty gettext-0.14.3]$ cd ..
   [lfs@hellokitty sources]$ rm -rf gettext-0.14.3


  21). Ncurses-5.4 (提供功能链定义/屏幕绘制/基于文本终端的图形界面的字符终端处理库)
   [lfs@hellokitty sources]$ tar -jxvf ncurses-5.4.tar.bz2
   [lfs@hellokitty sources]$ cd ncurses-5.4
   [lfs@hellokitty ncurses-5.4]$ ./configure --prefix=/tools --with-shared --without-debug --without-ada --enable-overwrite && make && make install
   --without-ada  禁止使用ada编译器
   --enable-overwrite 指明Ncurses安装其头文件至/tools/include 而非/tools/include/ncurses
                      方便其它软件包顺利找到ncurses库的头文件.

   [lfs@hellokitty ncurses-5.4]$ cd ..
   [lfs@hellokitty sources]$ rm -rf ncurses-5.4


  22). Patch-2.5.4
   [lfs@hellokitty sources]$ tar -jxvf patch-2.5.4.tar.bz2
   [lfs@hellokitty sources]$ cd patch-2.5.4
   [lfs@hellokitty patch-2.5.4]$ CPPFLAGS=-D_GNU_SOURCE ./configure --prefix=/tools && make && make install
   [lfs@hellokitty patch-2.5.4]$ cd ..
   [lfs@hellokitty sources]$ rm -rf patch-2.5.4


  23). Tar.1.15.1
   [lfs@hellokitty sources]$ wget http://www.linuxfromscratch.org/patches/downloads/tar/tar-1.15.1-security_fixes-1.patch
   [lfs@hellokitty sources]$ tar -jxvf tar-1.15.1.tar.bz2
   [lfs@hellokitty sources]$ cd tar-1.15.1
   [lfs@hellokitty tar-1.15.1]$ patch -Np1 -i ../tar-1.15.1-security_fixes-1.patch
   [lfs@hellokitty tar-1.15.1]$ ./configure --prefix=/tools && make && make install
   [lfs@hellokitty tar-1.15.1]$ cd ..
   [lfs@hellokitty sources]$ rm -rf tar-1.15.1

 
  24). Texinfo(info命令)
   [lfs@hellokitty sources]$ tar -jxvf texinfo-4.8.tar.bz2
   [lfs@hellokitty sources]$ cd texinfo-4.8
   [lfs@hellokitty texinfo-4.8]$ ./configure --prefix=/tools && make && make install
   [lfs@hellokitty texinfo-4.8]$ cd ..
   [lfs@hellokitty sources]$ rm -rf texinfo-4.8

 
  25). BASH-3.0
   [lfs@hellokitty sources]$ tar -jxvf bash-3.0.tar.bz2
   [lfs@hellokitty sources]$ cd bash-3.0
   [lfs@hellokitty bash-3.0]$ patch -Np1 -i ../bash-3.0-avoid_WCONTINUED-1.patch
   [lfs@hellokitty bash-3.0]$ ./configure --prefix=/tools --without-bash-malloc && make && make install
   --without-bash-malloc  禁用bash的malloc函数,而使用glibc的malloc,因为bash的malloc会有段错误.

   创建sh->bash
   [lfs@hellokitty bash-3.0]$ ln -s bash /tools/bin/sh
   [lfs@hellokitty bash-3.0]$ ls -l /tools/bin/sh /tools/bin/bash
   -rwxr-xr-x  1 lfs lfs 1471494 Feb  8 15:13 /tools/bin/bash
   lrwxrwxrwx  1 lfs lfs       4 Feb  8 15:15 /tools/bin/sh -> bash

   [lfs@hellokitty bash-3.0]$ cd ..
   [lfs@hellokitty sources]$ rm -rf bash-3.0

  26). M4-1.4.3
   [lfs@hellokitty sources]$ tar -jxvf m4-1.4.3.tar.bz2
   [lfs@hellokitty sources]$ cd m4-1.4.3
   [lfs@hellokitty m4-1.4.3]$ ./configure --prefix=/tools && make && make install
   [lfs@hellokitty m4-1.4.3]$ cd ..
   [lfs@hellokitty sources]$ rm -rf m4-1.4.3


  27). Bison-2.0
   [lfs@hellokitty sources]$ tar -jxvf bison-2.0.tar.bz2
   [lfs@hellokitty sources]$ cd bison-2.0
   [lfs@hellokitty bison-2.0]$ ./configure --prefix=/tools && make && make install
   [lfs@hellokitty bison-2.0]$ cd ..
   [lfs@hellokitty sources]$ rm -rf bison-2.0


  28). Flex-2.5.31
   [lfs@hellokitty sources]$ tar -jxvf flex-2.5.31.tar.bz2
   [lfs@hellokitty sources]$ cd flex-2.5.31
   [lfs@hellokitty flex-2.5.31]$ patch -Np1 -i ../flex-2.5.31-debian_fixes-3.patch
   [lfs@hellokitty flex-2.5.31]$ touch doc/flex.1
   [lfs@hellokitty flex-2.5.31]$ ./configure --prefix=/tools && make && make install
   [lfs@hellokitty flex-2.5.31]$ cd ..
   [lfs@hellokitty sources]$ rm -rf flex-2.5.31


  29). Util-linux-2.12q (fdisk/mount/getopt/sys-utils/login-utils)
   [lfs@hellokitty sources]$ tar -jxvf util-linux-2.12q.tar.bz2
   [lfs@hellokitty sources]$ cd util-linux-2.12q
   [lfs@hellokitty util-linux-2.12q]$ sed -i 's@/usr/include@/tools/include@g' configure
   把/usr/include全部替换成/tools/include   s后面紧跟@为替换符.

   [lfs@hellokitty util-linux-2.12q]$ ./configure
   [lfs@hellokitty util-linux-2.12q]$ make -C lib && make -C mount mount umount && make -C text-utils more
   只编译了其中的Lib库以及mount目录当中的mount/umount命令与text-utils目录当中的more命令.
   并用下面的命令将他们copy到/tools/bin
   [lfs@hellokitty util-linux-2.12q]$ cp mount/{,u}mount text-utils/more /tools/bin
   [lfs@hellokitty util-linux-2.12q]$ ls /tools/bin/mount /tools/bin/umount /tools/bin/more
   /tools/bin/more  /tools/bin/mount  /tools/bin/umount

   [lfs@hellokitty util-linux-2.12q]$ cd ..
   [lfs@hellokitty sources]$ rm -rf util-linux-2.12q
  知识点:util-linux-2.12q这个版本如果在GCC4下编译需要打补丁,
           否则虽然能编译通过,但其中的cfdisk程序会有问题,
           目前已经有util-linux-2.12r这个版本已经修正了这个问题,建议使用。
           (ID: youbest on linuxsir.org)
        
 
  30). Perl-5.8.7
   [lfs@hellokitty sources]$ wget http://www.linuxfromscratch.org/patches/downloads/perl/perl-5.8.7-sprintf_vulnerability-1.patch
   [lfs@hellokitty sources]$ tar -jxvf perl-5.8.7.tar.bz2
   [lfs@hellokitty sources]$ cd perl-5.8.7
   [lfs@hellokitty perl-5.8.7]$ patch -Np1 -i ../perl-5.8.7-libc-1.patch
   [lfs@hellokitty perl-5.8.7]$ patch -Np1 -i ../perl-5.8.7-sprintf_vulnerability-1.patch
   [lfs@hellokitty perl-5.8.7]$ ./configure.gnu --prefix=/tools -Dstatic_ext='IO Fcntl POSIX'
   -Dstatic_ext='IO Fcntl POSIX'  使Perl编译静态扩展的最小集,下一张安装Coreutils使用  
   
   [lfs@hellokitty perl-5.8.7]$ make perl utilities
   [lfs@hellokitty perl-5.8.7]$ cp perl pod/pod2man /tools/bin
   [lfs@hellokitty perl-5.8.7]$ mkdir -p /tools/lib/perl5/5.8.7
   [lfs@hellokitty perl-5.8.7]$ cp -rf lib/* /tools/lib/perl5/5.8.7/



  31). 到此为止,我们构建的不依赖于宿主系统的GNU tool china 完成了.
       但是在/tools/下的库以及程序文件包含了大量GDB调试时需要的符号以及其它.
       我们不使用GDB, 所以可以执行如下命令清除这符号.
       [lfs@hellokitty sources]$ strip --strip-debug /tools/lib/*
       [lfs@hellokitty sources]$ strip --strip-unneeded /tools/{,s}bin/*


6 安装系统基础软件
##################
6.1 操作笔记
============
  1). 第6章完成了2件事
      -1: 构建根文件系统布局及相应的一些配置文件.
      -2: 应用第5章构建的(不依赖于宿主系统)GNU tool chain来编译生成最终LFS上的软件包.

      理解Linux系统是如何工作的关键在于了解每个包的用途以及谁用它/什么时候用它.(比较好).
      另外要关注一下软件包的依赖关系(大体上)-->对自己说,对以后编写一个类rpm的包管理器有帮助.
   
  2). 从现在开始以root用户开始进行工作,另外echo $LFS来检查一下环境变量依旧为/mnt/lfs

  3). 构建$LFS/proc 以及 $LFS/sys, 并且挂载相应的proc and sysfs file system.
      [root@hellokitty ~]# mkdir -p $LFS/{proc,sys}
      [root@hellokitty ~]# mount -t proc proc $LFS/proc
      [root@hellokitty ~]# mount -t sysfs sysfs $LFS/sys

      [root@hellokitty ~]# cat /mnt/lfs/proc/version
      Linux version 2.6.14.7 (root@hellokitty.com) (gcc version 3.4.6)..
      /proc and /sys当中均为宿主系统中内核的信息,我们的LFS现在还没内核呢...


      挂载一些其它文件系统.
      [root@hellokitty ~]# mkdir -p $LFS/dev
      [root@hellokitty ~]# mkdir -p $LFS/dev/shm
      [root@hellokitty ~]# mkdir -p $LFS/dev/pts
      [root@hellokitty ~]# chmod 755 $LFS/dev
      [root@hellokitty ~]# chmod 1777 $LFS/dev/shm
      [root@hellokitty ~]# chmod 755 $LFS/dev/pts
      这的权限修改是参考EL4系统工作站的相应目录权限来设置的.

      (以下这3行挂载命令不执行也没事,因为其后还需要再执行一次.)
      [root@hellokitty ~]# mount -vft tmpfs tmpfs $LFS/dev
      [root@hellokitty ~]# mount -vft tmpfs tmpfs $LFS/dev/shm
      [root@hellokitty ~]# mount -vft devpts -o gid=4,mode=620 devpts $LFS/dev/pts


  4). chroot到$LFS下,并且将环境设空(通过-i参数达到,但只保留命令行当中设的几个环境变量).
      其中需要注意的是PATH将/tools/bin设到最后,目的是软件包(Binutils/GCC/Glibc/awk/sed/bash等
      第5章安装的软件包)的最终版本被安装以后,就不再使用/tools下的临时软件包了. +h是禁止BASH
      的HASH功能(该功能主要用于记录首次输入的命令名--命令路径的关系), 因为安装了新的软件包后,
      我们就使用新的软件包,而非/tools/下的临时软件包.

      [root@hellokitty ~]# chroot "$LFS" /tools/bin/env -i /
      > HOME=/root TERM="$TERM" PS1='[/u@lfs /W]//$ ' /
      > PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin /
      > /tools/bin/bash --login +h
      [I have no name!@lfs /]$

      由于没有$LFS/etc/passwd没有被创建,所以这里显示的用户名为"I have no name!"
      另外,由于现在$LFS已经被chroot为根了, 所以LFS变量从此便没有用了.

  5). 如果这个时候中断了过程(重启),需要恢复工作环境的步骤如下:
      # export LFS=/mnt/lfs
      # mount /dev/hdd1 $LFS
      # mount -t proc proc $LFS/proc
      # mount -t sysfs sysfs $LFS/sys
      # mount -vft tmpfs tmpfs $LFS/dev
      # mount -vft tmpfs tmpfs $LFS/dev/shm
      # mount -vft devpts -o gid=4,mode=620 devpts $LFS/dev/pts
      # chroot "$LFS" /tools/bin/env -i /
      HOME=/root TERM="$TERM" PS1='[/u@lfs /W]//$ ' /
      PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin /
      /tools/bin/bash --login +h
      # alias ls='ls --color'    

      创建一脚本文件,把如上语句包含进去,恢复环境执行一下是个good idea.!!!
    

  6). 将/tools目录的所有者由lfs更改为root,由于没有/etc/passwd文件(以后不经强调,均为chroot后的根),
      故写成0:0,  这样也是从安全性上考虑,因为一旦以后LFS系统当中有个用户的UID/GID与/tools目录的
      lfs用户相同,会造成相当危险.
      [I have no name!@lfs /]$ chown -R 0:0 /tools


  7). 构造根文件系统目录布局.
      install -dv /{bin,boot,dev,etc/opt,home,lib,mnt}
      install -dv /{sbin,srv,usr/local,var,opt}
      install -dv /root -m 0750           #root的用户root进好了.
      install -dv /tmp /var/tmp -m 1777   #设置了sticky
      install -dv /media/{floppy,cdrom}
      install -dv /usr/{bin,include,lib,sbin,share,src}
      ln -sv share/{man,doc,info} /usr
      install -dv /usr/share/{doc,info,locale,man}
      install -dv /usr/share/{misc,terminfo,zoneinfo}
      install -dv /usr/share/man/man{1,2,3,4,5,6,7,8}
      install -dv /usr/local/{bin,etc,include,lib,sbin,share,src}
      ln -sv share/{man,doc,info} /usr/local
      install -dv /usr/local/share/{doc,info,locale,man}
      install -dv /usr/local/share/{misc,terminfo,zoneinfo}
      install -dv /usr/local/share/man/man{1,2,3,4,5,6,7,8}
      install -dv /var/{lock,log,mail,run,spool}
      install -dv /var/{opt,cache,lib/{misc,locate},local}
      install -dv /opt/{bin,doc,include,info}
      install -dv /opt/{lib,man/man{1,2,3,4,5,6,7,8}}

  8). 创建几个符号链接,因为其后的安装过程当中,有一些软件包会使用到这些路径.
     [I have no name!@lfs /]$ ln -sv /tools/bin/{bash,cat,pwd,stty} /bin
     [I have no name!@lfs /]$ ln -sv /tools/bin/perl /usr/bin
     [I have no name!@lfs /]$ ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
     [I have no name!@lfs /]$ ln -sv bash /bin/sh


     [I have no name!@lfs /]$ ls -l /bin/*
     lrwxrwxrwx  1 0 0 15 Feb  8 12:13 /bin/bash -> /tools/bin/bash
     lrwxrwxrwx  1 0 0 14 Feb  8 12:13 /bin/cat -> /tools/bin/cat
     lrwxrwxrwx  1 0 0 14 Feb  8 12:13 /bin/pwd -> /tools/bin/pwd
     lrwxrwxrwx  1 0 0  4 Feb  8 12:16 /bin/sh -> bash
     lrwxrwxrwx  1 0 0 15 Feb  8 12:13 /bin/stty -> /tools/bin/stty

  9).创建/etc/passwd文件
     [I have no name!@lfs /]$ cat > /etc/passwd << EOF
     > root:x:0:0:root:/root:/bin/bash
     > EOF

     创建/etc/group文件
     [I have no name!@lfs /]$ cat > /etc/group << "EOF"
     > root:x:0:
     > bin:x:1:
     > sys:x:2:
     > kmem:x:3:
     > tty:x:4:
     > tape:x:5:
     > daemon:x:6:
     > floppy:x:7:
     > disk:x:8:
     > lp:x:9:
     > dialout:x:10:
     > audio:x:11:
     > video:x:12:
     > utmp:x:13:
     > usb:x:14:
     > cdrom:x:15:
     > EOF
     说明:LSB(Linux standard basewww.linuxbase.org)只是推荐root GID=0/bin GID=1,
          其它组名和GID均由管理员指定.   udev的配置过程会使用到其它的组名.

     此时/etc/passwd & group文件均以创建完毕,可以重新启动shell了.
     [I have no name!@lfs /]$ exec /tools/bin/bash --login +h
     [root@lfs /]$  <-- 已经显示出Username了.
 

     最后创建一些日志文件(login/agetty/init/other app会记录信息于此)
     [root@lfs /]$ touch /var/run/utmp /var/log/{btmp,lastlog,wtmp}
     [root@lfs /]$ chgrp -v utmp /var/run/utmp /var/log/lastlog
     [root@lfs /]$ chmod -v 664 /var/run/utmp /var/log/lastlog
     /var/run/utmp: 记录现在登陆的用户(不能直接读取,需要通过系统调用读取)
     /var/log/wtmp: 记录所有的登录与退出.
     /var/log/lastlog: 记录每个用户最后登陆的信息
     /var/log/btmp: 记录错误的尝试登陆


  10). 在最后引导内核时(根文件系统就是当前的根=/dev/hdd1),内核在udev未启动之前需要
       /dev/console and /dev/null 2个设备结点事先存在,当单用户启动时候更是应该.
       (因为需要/dev/console)
      [root@lfs /]$ mknod -m 600 /dev/console c 5 1
      [root@lfs /]$ mknod -m 666 /dev/null c 1 3

      在最后启动LFS系统时,LFS启动脚本开始工作,这些脚本的作用是在/dev挂载一个虚拟文件系统,
      例如:tmpfs, devfs(这个不推荐,不过我常用,devfs已经不开发了,并且正被udev取代).
      并且当设备被检测/访问时动态的创建这些设备结点.  但现在需要我们自己手动的完成
      LFS启动脚本完成的工作.如下:
      [root@lfs /]$ mount -nvt tmpfs none /dev

      [root@lfs /]$ mknod -m 622 /dev/console c 5 1
      [root@lfs /]$ mknod -m 666 /dev/null c 1 3
      [root@lfs /]$ mknod -m 666 /dev/zero c 1 5
      [root@lfs /]$ mknod -m 666 /dev/ptmx c 5 2
      [root@lfs /]$ mknod -m 666 /dev/tty c 5 0
      [root@lfs /]$ mknod -m 444 /dev/random c 1 8
      [root@lfs /]$ mknod -m 444 /dev/urandom c 1 9
      [root@lfs /]$ chown -v root:tty /dev/{console,ptmx,tty}
      这里第二次创建/dev/console and null的原因是因为由于新挂载了tmpfs 到 /dev上,我们原先创建
      的设备结点已经被隐藏了,不过最后LFS系统启动的时候会使用这2个结点文件,到那时才发挥他们的作用.

      LSB启动脚本还会创建如下链接,现在需要我们手动创建.
      [root@lfs /]$ ln -sv /proc/self/fd /dev/fd
      [root@lfs /]$ ln -sv /proc/self/fd/0 /dev/stdin
      [root@lfs /]$ ln -sv /proc/self/fd/1 /dev/stdout
      [root@lfs /]$ ln -sv /proc/self/fd/2 /dev/stderr
      [root@lfs /]$ ln -sv /proc/kcore /dev/core
      [root@lfs /]$ mkdir -v /dev/pts
      [root@lfs /]$ mkdir -v /dev/shm

      [root@lfs dev]$ mount -vt devpts -o gid=4,mode=620 none /dev/pts
      warning: can't open /etc/fstab: No such file or directory(没事)
      [root@lfs dev]$ mount -vt tmpfs none /dev/shm



  11). 如果这个时候中断,恢复工作环境如下:
       export LFS=/mnt/lfs
       mount /dev/hdd1 $LFS

       mount -t proc proc $LFS/proc
       mount -t sysfs sysfs $LFS/sys

       chroot "$LFS" /tools/bin/env -i /
       HOME=/root TERM="$TERM" PS1='[/u@lfs /W]//$ ' /
       PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin /
       /tools/bin/bash --login +h
       # 注意: 当目标LFS的bash安装完成后, 上句就可以改为 /bin/bash --login +h

       alias ls='ls --color'

      mount -nvt tmpfs none /dev

       mknod -m 622 /dev/console c 5 1
       mknod -m 666 /dev/null c 1 3
       mknod -m 666 /dev/zero c 1 5
       mknod -m 666 /dev/ptmx c 5 2  
       mknod -m 666 /dev/tty c 5 0
       mknod -m 444 /dev/random c 1 8
       mknod -m 444 /dev/urandom c 1 9  
       chown -v root:tty /dev/{console,ptmx,tty}

       ln -sv /proc/self/fd /dev/fd
       ln -sv /proc/self/fd/0 /dev/stdin
       ln -sv /proc/self/fd/1 /dev/stdout
       ln -sv /proc/self/fd/2 /dev/stderr
       ln -sv /proc/kcore /dev/core
       mkdir -v /dev/pts
       mkdir -v /dev/shm

       mount -vt devpts -o gid=4,mode=620 none /dev/pts
       mount -vt tmpfs none /dev/shm


  12).安装Linux-Libc-Headers-2.6.11.2
      [root@lfs /]$ cd sources/
      [root@lfs sources]$ tar -jxvf linux-libc-headers-2.6.11.2.tar.bz2
      [root@lfs sources]$ cd linux-libc-headers-2.6.11.2
      [root@lfs linux-libc-headers-2.6.11.2]$ cp -rf include/asm-i386 /usr/include/asm
      [root@lfs linux-libc-headers-2.6.11.2]$ cp -rf include/linux /usr/include
      [root@lfs linux-libc-headers-2.6.11.2]$ chown -R root.root /usr/include/{asm,linux}
      [root@lfs linux-libc-headers-2.6.11.2]$ find /usr/include/{asm,linux} -type d -exec chmod 755 {} /;
      [root@lfs linux-libc-headers-2.6.11.2]$ find /usr/include/{asm,linux} -type f -exec chmod 644 {} /;
      [root@lfs linux-libc-headers-2.6.11.2]$ cd ..
      [root@lfs sources]$ rm -rf linux-libc-headers-2.6.11.2


  13).Man-pages-2.01(include 1200 user manual page)
      [root@lfs sources]$ tar -jxvf man-pages-2.01.tar.bz2
      [root@lfs sources]$ cd man-pages-2.01
      [root@lfs man-pages-2.01]$ make install
      [root@lfs man-pages-2.01]$ cd ..
      [root@lfs sources]$ rm -rf man-pages-2.01

  14).Glibc-2.3.4
      [root@lfs sources]$ tar -jxvf glibc-2.3.4.tar.bz2
      [root@lfs sources]$ cd glibc-2.3.4
      [root@lfs glibc-2.3.4]$ tar -jxvf ../glibc-linuxthreads-2.3.4.tar.bz2
      [root@lfs glibc-2.3.4]$ patch -Np1 -i ../glibc-2.3.4-rtld_search_dirs-1.patch
      [root@lfs glibc-2.3.4]$ patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch
      [root@lfs glibc-2.3.4]$ patch -Np1 -i ../glibc-2.3.4-tls_assert-1.patch

      [root@lfs glibc-2.3.4]$ mkdir ../glibc-build
      [root@lfs glibc-2.3.4]$ cd ../glibc-build/
 
      [root@lfs glibc-build]$ ../glibc-2.3.4/configure --prefix=/usr --disable-profile --enable-add-ons --enable-kernel=2.6.0 --libexecdir=/usr/lib/glibc && make
      --prefix=/usr  装到/usr下了.

      进行Glibc测试(一定要测试,因为这是最后目标LFS系统的Glibc,是整个系统的基础软件)!!
      另外P167 in LFS-6.1.1说明了测试可能出现失败的几种情况.
      [root@lfs glibc-build]$ make -k check >glibc-check-log 2>&1 && grep Error glibc-check-log
      make[2]: [/sources/glibc-build/posix/annexc.out] Error 1 (ignored)


      安装库文件
      [root@lfs glibc-build]$ touch /etc/ld.so.conf
      [root@lfs glibc-build]$ make install

      安装locale
      [root@lfs glibc-build]$ make localedata/install-locales

      安装线程库manual
      [root@lfs glibc-build]$ make -C ../glibc-2.3.4/linuxthreads/man && make -C ../glibc-2.3.4/linuxthreads/man install

      
      Glibc的3个配置文件:     /etc/nsswitch.conf  指明信息存放/搜索顺序.
                                                  例如:指明passwd/group/shadow使用本机的
                                                       指明DNS解析是先用/etc/hosts or BIND.
                                                  在进行网络编程时,socket调用尤其依赖这个文件去寻找
                                                  相应的网络配置信息.
                                                  该文件是Sun开发的.
                              /etc/localtime      时区信息
                              /etc/ld.so.conf     动态库搜索路径.动态库加载程序ld-linux.so.2默认会
                                                  搜索/lib与/usr/lib, 并且加载App需要的动态库(映射
                                                  动态库地址空间到进程空间).如果某些常用的库存放在其它路径,
                                                  当中,就需要在/etc/ld.so.conf当中指定这些目录路径,
                                                  最常用的是/usr/local/lib 与 /opt/lib.

      [root@lfs glibc-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

      [root@lfs glibc-build]$ cp -v --remove-destination /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
      Asia/Shanghai是从tzselect的结果.

      [root@lfs glibc-build]$ cat > /etc/ld.so.conf << "EOF"
      > /usr/local/lib
      > /opt/lib
      > EOF

      Glibc安装完毕.
      [root@lfs glibc-build]$ cd ..
      [root@lfs sources]$ rm -rf glibc-build/
      [root@lfs sources]$ rm -rf glibc-2.3.4



  15).调整工具链:使以后编译的程序全部连接到刚才安的Glibc库.
                 第5章我们创建的GNU工具链是从宿主系统的/lib and /usr/lib转到/tools/lib.
                 (原因是chroot后我们就不能使用宿主系统的库了,所以要构建一个独立的Gnu工具链)
                 现在调整工具链的目的是把/tools/lib转到目标LFS系统当中的/lib and /usr/lib.
                 所以调整工具链总体分为2步:
                 -1: 调整ld, 使其在将.o文件连接生成可执行文件时, 搜索库路径为/lib and /usr/lib.
                 -2: 程序要使用的动态库加载器是/lib/ld-linux.so.2, 而非/tools/lib/ld-linux.so.2
                     这个需要修改GCC的specs文件来达到.

      15.1): 调整ld.
      由于在5.12章节已经执行过以下命令,生成了搜索库路径为/lib and /usr/lib的ld,
      # make -C ld clean
      # make -C ld LIB_PATH=/usr/lib:/lib
      所以此处只要执行以下命令安装ld就好了.
      [root@lfs binutils-build]$ make -C ld INSTALL=/tools/bin/install install
      [root@lfs binutils-build]$ cd ..
      [root@lfs sources]$ rm -rf binutils-build/
      [root@lfs sources]$ rm -rf binutils-2.15.94.0.2.2
      删除要做的,不做可能会影响到其后安装目标LFS的binutils.

     
      
      15.2): 调整Gcc的specs文件以达到将/tools/lib/ld-linux.so.2改为/lib/ld-linux.so.2
      [root@lfs binutils-build]$ perl -pi -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g;' /
      >     -e 's@/*startfile_prefix_spec:/n@$_/usr/lib/ @g;' /
      >         $(gcc --print-file specs)


      15.30: 检查如上调整是否生效.
      [root@lfs binutils-build]$ echo "main() {}" > dummy.c
      [root@lfs binutils-build]$ gcc dummy.c
      [root@lfs binutils-build]$ readelf -l a.out | grep ": /lib"
            [Requesting program interpreter: /lib/ld-linux.so.2] --> 生效了.
      [root@lfs binutils-build]$ rm -rf dummy.c a.out


  16).Binutils-2.15.94.0.22
      16.1) 首先测试一下伪终端(PTY)是否正常工作,如下是工常工作的表现.只要在PTY正常工作的条件下,
      运行Binutils and Gcc的测试程序才有意义.
      [root@lfs sources]$ expect -c "spawn ls"
      spawn ls

      16.2)
      [root@lfs sources]$ tar -jxvf binutils-2.15.94.0.2.2.tar.bz2
      [root@lfs sources]$ mkdir binutils-build
      [root@lfs sources]$ cd binutils-build/
      [root@lfs binutils-build]$ ../binutils-2.15.94.0.2.2/configure --prefix=/usr --enable-shared && make tooldir=/usr
 
      说明:
      tooldir(可执行文件安装目录) = $(exec_prefix)/$(target_alias)
      例如在i686机器上,将是/usr/i686-pc-linux-gnu.因为我们只为自己的LFS系统编译,帮不需要target_alias.
      target_alias只要当Cross tool chian才需要使用.

      [root@lfs binutils-build]$ make tooldir=/usr install
      [root@lfs binutils-build]$ cp ../binutils-2.15.94.0.2.2/include/libiberty.h /usr/include
      libiberty包含了一些常用函数: getopt() strerror() strtol(), 这里是拷贝它的头文件.

      [root@lfs binutils-build]$ cd ..
      [root@lfs sources]$ rm -rf binutils-2.15.94.0.2.2
      [root@lfs sources]$ rm -rf binutils-build/


      16.3) Binutils当中常用程序列表.
      ar: 生成静态库
      as: 汇编器 用来汇编gcc产生的目标文件
      ld: 链接器 将.o与库文件相链接生成可执行文件      
      nm: 列出目标文件中的符号
      size: 列出目标文件当中的下面各个段大小
            text    data     bss
      objcopy: 将一个目标文件当中的内容复制到另一个目标文件
               # objcopy a.out b.out   执行a.out和b.out输出结果相同
      objdump: 显示目标文件当中的信息(头信息,汇编代码,调试信息)
               # objdump -S a.out   显示汇编代码
      readelf: 显示elf文件信息.(elf是二进制文件的一种格式.)
      strip:  删除目标文件当中的符号.(有些符号只是调试时用,删除不影响执行)



  17).Gcc-3.4.3
     17.1).
     [root@lfs sources]$ tar -jxvf gcc-3.4.3.tar.bz2
     [root@lfs sources]$ cd gcc-3.4.3
     [root@lfs gcc-3.4.3]$ patch -Np1 -i ../gcc-3.4.3-no_fixincludes-1.patch
     [root@lfs gcc-3.4.3]$ patch -Np1 -i ../gcc-3.4.3-linkonce-1.patch
     [root@lfs gcc-3.4.3]$ patch -Np1 -i ../gcc-3.4.3-pch-1.patch
     [root@lfs gcc-3.4.3]$ sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
     这条Sed命令的作用是禁止GCC安装它自己的libiberty, 因为我们用的是binutils的.
 
     [root@lfs gcc-3.4.3]$ mkdir ../gcc-build
     [root@lfs gcc-3.4.3]$ cd ../gcc-build/
     [root@lfs gcc-build]$ ../gcc-3.4.3/configure --prefix=/usr /
     >     --libexecdir=/usr/lib --enable-shared /
     >     --enable-threads=posix --enable-__cxa_atexit /
     >     --enable-clocale=gnu --enable-languages=c,c++ && make
     
     进行测试(必要)
     [root@lfs gcc-build]$ make -k check
     -k参数: 即使遇到错误,也继续运行.
     Gcc的测试非常全面,所以基本上均会出现一些错误,不要慌.有一些错误Gcc的开发者是知道的,只是
     还没有解决而已.查看测试摘要用如下命令:
     [root@lfs gcc-build]$ ../gcc-3.4.3/contrib/test_summary | grep -A7 Summ

     安装
     [root@lfs gcc-build]$ make install

     创建必要的符号链接. cpp=c preprocessor(C预处理器)
                         cc在多数平台上都是一个符号链接,指向本平台的真实编译器.
     [root@lfs gcc-build]$ ln -sv ../usr/bin/cpp /lib
     [root@lfs gcc-build]$ ln -sv gcc /usr/bin/cc

     [root@lfs gcc-build]$ cd ..
     [root@lfs sources]$ rm -rf gcc-build gcc-3.4.3

 
     17.2). GCC当中常用程序说明:
     gcc: c compiler
     g++ and c++: c++ compiler
     cpp: c preprocessor
     libgcc: gcc runtime library



  18).至此为止,目标LFS上的GNU工具链已经构建完成.位于/usr目录下剩下本章工作就是用此
      工具链来编译生成最终目标LFS上的基础软件了(Coreutils,bash,grep,sed等).
      编译软件包步骤不再记录,具体参考: LFS-6.1.1手册以及
      http://www.linuxsir.org/bbs/showthread.php?t=244052 (you best on linuxsir.org)
      本章剩余笔记仅记录应该注意的知识点.

  19).Coreutils软件包包含了相当数量的基础程序.(例如:chown,basename,cat等)
      Zlib包含Zlib库,很多程序当中的解缩与解压均会使用该库.分别有静态和动态库2个edition.
                     libz.a为静态库edition.
      Mktemp是一个包含有mktemp程序的软件包,该程序主要以安全的方式创建临时文件,常用于
            脚本文件中.
      Iana-etc软件包主要提供了2个文件:
              /etc/services   : 端口-应用层协议
              /etc/protocols  : TCP/IP子系统可用的各种协议.
      readline库: libhistory & libreadline
                  提供命令行历史的统一用户接口
      vim: 1.注意./configure 时的--enable-multibyte 能使vim支持多字节编码文件.
           2.另外vim有个配置文件/etc/vimrc, 基本配置描述如下:
           set nocompatible  指明vim以比默认的VI兼容模式更强的方式运行.
           set backspace=2   退格键能跨行/自动缩进/插入
           syntax on         开启语法高亮
           set background=dark  设置背影颜色
 
           3. vim -c ":options"可能得到其它选项的说明

      m4是一个宏处理器,用于展开宏.可以用于一个编译器的前端.
      bison: 包含bison and yacc(语法分析器生成器)
             liby.a是一个yacc库,posix需要它.提供yyerror()
      Groff包含处理和格式化文本的程序.它把标准的文本和特殊命令翻译成格式化输出,像man
           手册当中看到的一样.-->可以用Groff来做man page.
      flex包: 包含flex and lex 词法分析器生成器.
              libfl.a是flex库.
      Gettext: 可以在编译程序的时候使用本国语言,可以使程序输出按用户设置的语言而非英文.
      inetutils: 包含ftp ping rcp(远程文件拷贝) telnet等小的网络工具程序.
      iproute2: 包含了相当多的基本IPV4的网络程序.例如:
                ifcfg(ip命令的封装脚本),ifstat,ip,ss(像netstat),nstat
      autoconf & automake : 针对不同系统的配置信息(有头文件嘛?有库嘛?有相应的基础设施嘛?)
                            来生成Makefile
      file软件包包括file命令.
      GNU libtool: 是一个通用库支持脚本,将使用动态库的复杂性隐藏在统一并且可移植的接口.
      Diffutils中包含diff这个工具.
      kbd包含键盘映射表和键盘工具.
      e2fsprogs包含了ext2/ext3文件系统的常用工具及库.
               例如:e2fsck, e2label, fsck, mkfs.ext2, mkfs.ext3,
                    resize2fs(用来增大或者缩小ext2文件系统),
                    tune2fs(调整ext2文件系统参数)
      grep包: grep egrep fgrep
      grub包安装时: # cp /usr/lib/grub/i386-pc/* /boot/grub/
                    把i386-pc目录下的stage1/2和相关文件系统支持全部拷到/boot/grub当中.
      hotplug: 1.系统引导时完成检测现存硬件并向运行的内核加载相应模块.
                 /etc/hotplug/*.rc完成如上功能,LFSbootscript会调用.
               2.内核会在发生某些情况(常见的是热插拔) 调用hotplug程序.
                 /etc/hotplug/*.agent响应内核的热插拔事件并执行.
      man: man手册查看器. groff用来创建man page.
           配置文件为/etc/man.conf.(EL4当中为/etc/man.config)
      Module-Init-Tools: 包含了depmod/insmod/rmmod/modprobe常用模块程序.
      Procps包括进程相关工具:ps  kill skill
                             free(报告物理内存和交换内存的使用情况)
                             pmap(报告指定PID的进程内存映射)
                             vmstat(报告虚拟内存统计)
      psmisc包括killall,pstree.
      shadow包含一组在安全方式下处理密码的程序.例如:
            chsh, login, passwd, su, libshadow(library)
             
            shadow使用2个文件来设置系统的身份认证(能实现禁止某些用户登陆):
            /etc/limits  and  /etc/login.access
            
            shadow使用pwconv开启影子密码.
                  使用grpconv开启组影子密码.
           
            *安装完shadow之后,一定要对root用户重设密码.(不设的结果就是启动LFS系统后无法登陆)!!

      udev配置文件: /etc/udev/rules.d/25-lfs.rules
            包组成: udevstart  在/dev目录创建设备结点以与直接编译进内核的udev模块进行通信.


  20). 当udev装完之后(包括安装完linux-utils),重新开机恢复工作状态的步骤如下:
       export LFS=/mnt/lfs
       mount /dev/hdd1 $LFS

       mount -t proc proc $LFS/proc
       mount -t sysfs sysfs $LFS/sys

       chroot "$LFS" /usr/bin/env -i /
       HOME=/root TERM="$TERM" PS1='[/u@lfs /W]//$ ' /
       PATH=/bin:/usr/bin:/sbin:/usr/sbin /
       /bin/bash --login

       alias ls='ls --color'

      mount -nvt tmpfs none /dev
 
       /sbin/udevstart
      mkdir -v /dev/pts
       mkdir -v /dev/shm
       mount -vt devpts -o gid=4,mode=620 none /dev/pts
       mount -vt tmpfs none /dev/shm

  21). 至此,使用临时我们构建的GNU工具链构建目标LFS系统的软件包已经完成.
       这个GNU工具链已经完成它的使命,可以把备份一下工具链(把/tools打个包),
       以备后用.然后删除/tools目录就好了. 注意,这个工具链是一个依赖于
       目标LFS系统的工具链,因为Binutils中的ld以及GCC中的specs均被调整到
       /lib下, 而非/tools下.如果想用这个工具链来构建一个目标LFS系统的话,
       需要调整工具链.


7 配置系统启动脚本
##################
7.1 笔记
========
  a). 非常令我失望,还以为第7章能从头到尾讲述一下启动脚本,没想到只是简单描述了
      lfs-bootscripts-3.2.1这个包安装过程以及其几个配置文件.关于lfs-bootscripts
      的分析将在另行分析.

  b). SysVinit规定的7种运行级别, 而非发行版自己定义的.
      0: 关机
      1: 单用户
      2: 无网络的多用户模式
      3: 带网络的多用户模式
      4: 保留或者同3
      5: GUI
      6: 重启

  c). /etc/rc.d/rcX.d当中的软链接均链接到/etc/rc.d/init.d当中的实际脚本.
      开头为S为start, K为stop.  S/K后的数字从00-99, 越小执行得越早.
      [root@lfs /]$ ls -l /etc/rc.d/rc3.d/*
      /etc/rc.d/rc3.d/S10sysklogd -> ../init.d/sysklogd
      /etc/rc.d/rc3.d/S20network -> ../init.d/network
     
      常用脚本参数: start/stop/restart/status/reload(重新加载配置文件而不重启服务

  d). 时间设置
      cat > /etc/sysconfig/clock << "EOF"
      # Begin /etc/sysconfig/clock
      UTC=1
      # End /etc/sysconfig/clock
      EOF

  e). 完成键盘热键映射
      cat > /etc/inputrc << "EOF"
      set horizontal-scroll-mode Off
      set meta-flag On
      set input-meta On
      set convert-meta Off
      set output-meta On
      set bell-style none
      "/eOd": backward-word
      "/eOc": forward-word
      "/e[1~": beginning-of-line
      "/e[4~": end-of-line
      "/e[5~": beginning-of-history
      "/e[6~": end-of-history
      "/e[3~": delete-char
      "/e[2~": quoted-insert
      "/eOH": beginning-of-line
      "/eOF": end-of-line
      "/e[H": beginning-of-line
      "/e[F": end-of-line
      EOF

  f). 设置BASH启动文件
      cat > /etc/profile << "EOF"
      # Begin /etc/profile
 
      export LANG=zh_CN.GB18030
      export INPUTRC=/etc/inputrc

      # End /etc/profile
      EOF

  g). 配置主机名
      echo "HOSTNAME=mylinux" > /etc/sysconfig/network

  h). 设置主机名-ip映射
      cat > /etc/hosts << "EOF"
      # Begin /etc/hosts (no network card version)
      127.0.0.1 mylinux localhost
      # End /etc/hosts (no network card version)
      EOF

  i). 设置NIC(ip/geteway/broadcast根据情况修改)
      cd /etc/sysconfig/network-devices &&
      mkdir -v ifconfig.eth0 &&
      cat > ifconfig.eth0/ipv4 << "EOF"
      ONBOOT=yes
      SERVICE=ipv4-static
      IP=192.168.1.1
      GATEWAY=192.168.1.2
      PREFIX=24
      BROADCAST=192.168.1.255
      EOF

  j). 修改/etc/fstab,指明系统启动时要挂载的分区
      # Begin /etc/fstab
      # file system  mount-point  type   options         dump  fsck
      #                                                        order
      
      /dev/hdd1      /            ext3   defaults        1     1
      /dev/hda9     swap    swap   pri=1           0     0
      proc           /proc        proc   defaults        0     0
      sysfs          /sys         sysfs  defaults        0     0
      devpts         /dev/pts     devpts gid=4,mode=620  0     0
      shm            /dev/shm     tmpfs  defaults        0     0
      # End /etc/fstab

      注意点:将tmpfs 挂载到 /dev/shm 以便启用 POSIX 共享内存的功能,
             内核必须编入了配套的支持才能使用这个功能.

   k). 关于内核的注意点:
       -1: 以VMWare5.0为基础虚拟的硬件来配置内核如果你想支持loop设备,
           那么应在Device Drivers->Block devices加入Loopback device support
           和Cryptoloop Support的支持.
       -2: 如果在建立虚拟机的时候是选择的SCSI的磁盘,那么应该在Device Drivers->
           SCSI device support->SCSI low-level drivers下加入BusLogic SCSI support的支持,
           可以采用编译到内核来避免未用initrd脚本来加载模块而导致启动失败
       -3: 支持网络则应该在Device Drivers->Networking support->Ethernet (10 or 100Mbit)
           加入AMD PCnet32 PCI support的支持
       -4: 文件系统的支持,需要根据之前将目标系统分区格式化的情况而定,使用了什么文件系统就
           需要加入该文件系统的支持
       -5: # cp -v arch/i386/boot/bzImage /boot/lfskernel-2.6.11.12
           # cp -v System.map /boot/System.map-2.6.11.12
           # cp -v .config /boot/config-2.6.11.12

  l). grub见LFS文档

  m). -1 编译内核要注意的一点就是ext3文件系统一定编译到内核内,而非module,这样就
         可以省去initrd(ramfs)这道手续了.initrd专门用来解决鸡生蛋/蛋生鸡的问题.例如:
         你的根文件系统位于SCSI硬盘上,而你又把SCSI驱动编译成module,内核要想支持上
         你的SCSI硬盘,就得先去加载SCSI驱动模块,而模块又在SCSI硬盘上.解决方法就是先利用
         GRUB加载kernel and initrd到memory中(GRUB具有SCSI设备的驱动程序,而内核现在没有),
         然后kernel先挂载上initrd为临时根文件系统,再把事先我们存放到initrd当中的SCSI
         模块加载,从而解决对SCSI设备的支持. 最后kernel会重新挂载SCSI硬盘为根文件系统.

      -2 另外一点是我在启动LFS系统时遇到的问题,归档一下.
         /dev/hda是宿主系统所安装的硬盘.grub安装到其上的MBR.
         /dev/hdd1是LFS系统的根文件系统. 由于我硬盘是拿来的时候就有一个分区, 为fat32的.
         所以我就直接格式化为ext3文件系统了, fdisk -l /dev/hdd1 看它的时候显示的fat32.
         其实这没事, 作为从盘来讲也不看/dev/hdd1的MBR当中446后64字节的分区表. 不过从
         grub引导的时候出现错误了, 说unknow partiton. 解决方法是用fdisk把/dev/hdd1的
         partition system id 改为83(linux partition), GRUB就正常加载根文件系统了.
         从这能看出, grub是按照硬盘MBR当中446字节后的64字节的分区表中的partition system id
         来判断你分区的文件系统类型, 然后再加载相应的文件系统驱动.
      

8 参考文档
##########
LFS-6.1.1文档

原创粉丝点击