新闻  |   论坛  |   博客  |   在线研讨会
建立自己的linux系统(二)
wxy_88kl | 2008-07-03 23:20:22    阅读:80265   发布文章

    从现在开始一直到第五章结束,也就是完成Stripping中间的步骤中如果重新启动的恢复步骤:
  1.重新启动计算机,并从LiveCD启动
  相关知识点:在VMWare中因为磁盘已经有了信息了,所以会从磁盘启动,需要在启动虚拟机中的机器时按F2进入虚拟机的虚拟BIOS,然后在BOOT中设置第一启动为CD-ROM,保存退出即可。


        2.LiveCD启动过程同第一次启动选择一样。
  3.加载分区
  export LFS=/mnt/lfs
  mkdir -pv $LFS
  mount /dev/hda2 $LFS
  4.加载交换分区(如果不想用交换分区或者没有交换分区可跳过此步骤)
  swapon /dev/hda1
  5.建立工具链的链接
  ln -sv $LFS/tools /
  6.创建lfs用户
  groupadd lfs
  useradd -s /bin/bash -g lfs -m -k /dev/null lfs
  passwd lfs
  chown -v lfs $LFS/tools
  chown -v lfs $LFS/sources
  su - lfs
  7.建立lfs用户的环境
  cat > ~/.bash_profile << "EOF"
  exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
  EOF
  cat > ~/.bashrc << "EOF"
  set +h
  umask 022
  LFS=/mnt/lfs
  LC_ALL=POSIX
  PATH=/tools/bin:/bin:/usr/bin
  export LFS LC_ALL PATH
  EOF
  source ~/.bash_profile
  8.检查一下
  export命令查看输出,应该是
  declare -x HOME="/home/lfs"
  declare -x LC_ALL="POSIX"
  declare -x LFS="/mnt/lfs"
  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="linux"
  9.进入编译目录
  cd $LFS/sources
  基本上就恢复工作状态了。

开始工具链的制作
进入LFS包编译目录
cd $LFS/sources

tar xvf /lfs-sources/binutils-2.17.tar.bz2 cd binutils-2.17
相关知识点:
  大家可以注意到后面所有的解包命令均使用tar xvf来完成,而不管文件的压缩方式是bz2还是gz,这是因为较新的tar程序都具有自动识别后缀名并自动调用相应的解压缩工具的能力,所以可以不需要指定压缩方式,但对于早期的tar命令则可能不具备这个功能因此需要你根据包的压缩方式来指定,如bz2使用j,gz使用z,对应上面的binutils 则是tar xvjf /lfs-sources/binutils-2.17.tar.bz2
  因LFS的LiveCD中提供的tar版本比较新,后面制作的tar版本也比较新,因此支持自动识别的能力,同时为了使文章的解压命令看起来比较统一方便维护(同样对于想制作成脚本的朋友也会比较方便)因此后面统一使用tar xvf来解压。

  接着我们需要建立一个目录,因为binutils建议使用一个空目录来编译
mkdir -v ../binutils-build cd ../binutils-build CC="gcc -B/usr/bin/" ../binutils-2.17/configure --prefix=/tools --disable-nls --disable-werror make make install make -C ld clean make -C ld LIB_PATH=/tools/lib cp -v ld/ld-new /tools/bin cd .. rm -rf binutils-build rm -rf binutils-2.17
tar xvf /lfs-sources/gcc-4.1.2.tar.bz2 mkdir -v gcc-build cd gcc-build CC="gcc -B/usr/bin/" ../gcc-4.1.2/configure --prefix=/tools \ --with-local-prefix=/tools --disable-nls \ --enable-shared --enable-languages=c make bootstrap make install ln -vs gcc /tools/bin/cc cd .. rm -rf gcc-build rm -rf gcc-4.1.2

Linux-2.6.22.5 API Headers
tar xvf /lfs-sources/linux-2.6.22.5.tar.bz2 cd linux-2.6.22.5 make mrproper make headers_check make INSTALL_HDR_PATH=dest headers_install cp -rv dest/include/* /tools/include cd .. rm -rf linux-2.6.22.5

Glibc-2.5.1
tar xvf /lfs-sources/glibc-2.5.1.tar.bz2 cd glibc-2.5.1 mkdir -v ../glibc-build cd ../glibc-build ../glibc-2.5.1/configure --prefix=/tools \ --disable-profile --enable-add-ons \ --enable-kernel=2.6.0 --with-binutils=/tools/bin \ --without-gd --with-headers=/tools/include \ --without-selinux make mkdir -v /tools/etc touch /tools/etc/ld.so.conf make install cd .. rm -rf glibc-build rm -rf glibc-2.5.1

相关知识点:
  这里的参数--enable-kernel=2.6.0,只是为了说明kernel的大版本,所以不需要根据实际的kernel版本来改,即使是用linux-2.6.15也一样只写2.6.0就可以了。

调整工具链
mv -v /tools/bin/{ld,ld-old} mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old} mv -v /tools/bin/{ld-new,ld} ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld gcc -dumpspecs | sed 's@^/lib/ld-linux.so.2@/tools&@g' > `dirname $(gcc -print-libgcc-file-name)`/specs GCC_INCLUDEDIR=`dirname $(gcc -print-libgcc-file-name)`/include && find ${GCC_INCLUDEDIR}/* -maxdepth 0 -xtype d -exec rm -rvf '{}' \; && rm -vf `grep -l "DO NOT EDIT THIS FILE" ${GCC_INCLUDEDIR}/*` && unset GCC_INCLUDEDIR

相关知识点:
  工具链的调整方法有好几种,而且不同版本GCC的specs可能会有不同,但实际上都是把specs文件中的/lib/ld-linux.so.2替换成了/tools/lib/ld-linux.so.2,所以即使有些文章在调整工具链上的命令和LFS手册上的不一样也不用太奇怪,当然也可以直接用gcc -dumpspecs导出后手工直接编辑specs文件。

测试工具链的调整
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep 'tools'
如果输出大致如下
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
则表示调整成功,因为所有的库已经连接到了/tools/lib下。
rm -rf a.out dummy.c

测试工具安装
说明:这部分将安装3个用于第六章各种源码包编译后的测试的工具,所以如果你不打算做make check之类的事情,那么这3个包可以不装。
Tcl-8.4.15 Expect-5.43.0 DejaGNU-1.4.4
tar xvf /lfs-sources/tcl8.4.15-src.tar.gz cd tcl8.4.15/unix ./configure --prefix=/tools make make install make install-private-headers ln -sv tclsh8.4 /tools/bin/tclsh cd $LFS/sources tar xvf /lfs-sources/expect-5.43.0.tar.gz cd expect-5.43 patch -Np1 -i /lfs-sources/expect-5.43.0-spawn-1.patch cp configure{,.bak} sed 's:/usr/local/bin:/bin:' configure.bak > configure ./configure --prefix=/tools --with-tcl=/tools/lib --with-tclinclude=/tools/include --with-x=no make make SCRIPTS="" install cd $LFS/sources tar xvf /lfs-sources/dejagnu-1.4.4.tar.gz cd dejagnu-1.4.4 ./configure --prefix=/tools make install cd .. rm -rf tcl8.4.15 rm -rf expect-5.43 rm -rf dejagnu-1.4.4

tar xvf /lfs-sources/gcc-4.1.2.tar.bz2 cd gcc-4.1.2 cp -v gcc/Makefile.in{,.orig} sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in cp -v gcc/Makefile.in{,.tmp} sed 's/^XCFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp \ > gcc/Makefile.in patch -Np1 -i /lfs-sources/gcc-4.1.2-specs-1.patch mkdir -v ../gcc-build cd ../gcc-build ../gcc-4.1.2/configure --prefix=/tools \ --with-local-prefix=/tools \ --enable-clocale=gnu --enable-shared \ --enable-threads=posix --enable-__cxa_atexit \ --enable-languages=c,c++ --disable-libstdcxx-pch make make install cd .. rm -rf gcc-build rm -rf gcc-4.1.2

再次测试工具链的调整,以确保刚刚编译的gcc正确工作
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep 'tools'
如果输出大致如下
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
则表示调整成功,因为所有的库已经连接到了/tools/lib下。
rm -rf a.out dummy.c

tar xvf /lfs-sources/binutils-2.17.tar.bz2 mkdir -v binutils-build cd binutils-build ../binutils-2.17/configure --prefix=/tools --disable-nls \ --with-lib-path=/tools/lib make make install make -C ld clean make -C ld LIB_PATH=/usr/lib:/lib cp -v ld/ld-new /tools/bin cd .. rm -rf binutils-build rm -rf binutils-2.17

Ncurses-5.6
tar xvf /lfs-sources/ncurses-5.6.tar.gz cd ncurses-5.6 ./configure --prefix=/tools --with-shared --without-debug --without-ada --enable-overwrite make make install cd .. rm -rf ncurses-5.6

Bash-3.2
tar xvf /lfs-sources/bash-3.2.tar.gz cd bash-3.2 patch -Np1 -i /lfs-sources/bash-3.2-fixes-5.patch ./configure --prefix=/tools --without-bash-malloc make make install ln -vs bash /tools/bin/sh cd .. rm -rf bash-3.2

Bzip2-1.0.4
tar xvf /lfs-sources/bzip2-1.0.4.tar.gz cd bzip2-1.0.4 make make PREFIX=/tools install cd .. rm -rf bzip2-1.0.4

Coreutils-6.9
tar xvf /lfs-sources/coreutils-6.9.tar.bz2 cd coreutils-6.9 ./configure --prefix=/tools make make install cp -v src/su /tools/bin/su-tools cd .. rm -rf coreutils-6.9

Diffutils-2.8.1
tar xvf /lfs-sources/diffutils-2.8.1.tar.gz cd diffutils-2.8.1 ./configure --prefix=/tools make make install cd .. rm -rf diffutils-2.8.1

Findutils-4.2.31
tar xvf /lfs-sources/findutils-4.2.31.tar.bz2 cd findutils-4.2.31 ./configure --prefix=/tools make make install cd .. rm -rf findutils-4.2.31

Gawk-3.1.5
tar xvf /lfs-sources/gawk-3.1.5.tar.bz2 cd gawk-3.1.5 ./configure --prefix=/tools cat >> config.h << "EOF" #define HAVE_LANGINFO_CODESET 1 #define HAVE_LC_MESSAGES 1 EOF make make install cd .. rm -rf gawk-3.1.5

Gettext-0.16.1
tar xvf /lfs-sources/gettext-0.16.1.tar.gz cd gettext-0.16.1 cd gettext-tools ./configure --prefix=/tools --disable-shared make -C gnulib-lib make -C src msgfmt cp -v src/msgfmt /tools/bin cd $LFS/sources rm -rf gettext-0.16.1

Grep-2.5.1a
tar xvf /lfs-sources/grep-2.5.1a.tar.bz2 cd grep-2.5.1a ./configure --prefix=/tools --disable-perl-regexp make make install cd .. rm -rf grep-2.5.1a

Gzip-1.3.12
tar xvf /lfs-sources/gzip-1.3.12.tar.gz cd gzip-1.3.12 ./configure --prefix=/tools make make install cd .. rm -rf gzip-1.3.12

Make-3.81
tar xvf /lfs-sources/make-3.81.tar.bz2 cd make-3.81 ./configure --prefix=/tools make make install cd .. rm -rf make-3.81

Patch-2.5.4
tar xvf /lfs-sources/patch-2.5.4.tar.gz cd patch-2.5.4 ./configure --prefix=/tools make make install cd .. rm -rf patch-2.5.4

Perl-5.8.8
tar xvf /lfs-sources/perl-5.8.8.tar.bz2 cd perl-5.8.8 patch -Np1 -i /lfs-sources/perl-5.8.8-libc-2.patch ./configure.gnu --prefix=/tools -Dstatic_ext='Data/Dumper Fcntl IO POSIX' make perl utilities cp -v perl pod/pod2man /tools/bin mkdir -pv /tools/lib/perl5/5.8.8 cp -Rv lib/* /tools/lib/perl5/5.8.8 cd .. rm -rf perl-5.8.8

Sed-4.1.5
tar xvf /lfs-sources/sed-4.1.5.tar.gz cd sed-4.1.5 ./configure --prefix=/tools make make install cd .. rm -rf sed-4.1.5

Tar-1.18
tar xvf /lfs-sources/tar-1.18.tar.bz2 cd tar-1.18 ./configure --prefix=/tools make make install cd .. rm -rf tar-1.18

Texinfo-4.9
tar xvf /lfs-sources/texinfo-4.9.tar.bz2 cd texinfo-4.9 ./configure --prefix=/tools make make install cd .. rm -rf texinfo-4.9

Util-linux-2.12r
tar xvf /lfs-sources/util-linux-2.12r.tar.bz2 cd util-linux-2.12r sed -i 's@/usr/include@/tools/include@g' configure ./configure make -C lib make -C mount mount umount make -C text-utils more cp -v mount/{,u}mount text-utils/more /tools/bin cd .. rm -rf util-linux-2.12r

Stripping
这步是可有可无的,如果你打算今后还要用/tools里面的东西,那么可以strip一下来减少占用的磁盘空间,但如果做完目标系统后就删除了,不Strip也可以,反正最后也是要删掉的。
strip --strip-debug /tools/lib/* strip --strip-unneeded /tools/{,s}bin/*

info和man里面的内容在制作过程中没什么用处,所以删掉
rm -rf /tools/{info,man}

退出lfs用户
exit

到目前为止,工具链已经制作完成了,接着就要开始制作真正的目标系统了,如果你到目前为止没出什么问题,那么恭喜你成功的通过了一关,不过接着还有相当长的路。

从现在开始不在需要lfs用户来制作系统了
chown -R root:root $LFS/tools



*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
Deandre [ 匿名]  2008-11-26 05:40:13 

It

Noel [ 匿名]  2008-11-26 02:56:34 

Don

Pete [ 匿名]  2008-11-25 19:56:03 

Don

Scottie [ 匿名]  2008-11-25 17:41:08 

Don

Franklin [ 匿名]  2008-11-25 15:12:45 

All aren

Stacy [ 匿名]  2008-11-25 13:28:42 

If you can

Jess [ 匿名]  2008-11-25 12:28:45 

Don

Maxwell [ 匿名]  2008-11-25 12:09:14 

Can

Jan [ 匿名]  2008-11-25 09:01:40 

A fly won

Elvin [ 匿名]  2008-11-25 08:43:41 

All aren

Jerrell [ 匿名]  2008-11-25 06:19:58 

A single thread from everyone

Ty [ 匿名]  2008-11-24 23:47:22 

Don

Quinton [ 匿名]  2008-11-24 23:03:00 

Don

Adolfo [ 匿名]  2008-11-24 09:35:20 

feather one

Michelle [ 匿名]  2008-11-24 05:36:52 

A single thread from everyone

Donny [ 匿名]  2008-11-24 03:07:25 

God doesn

Kenton [ 匿名]  2008-11-24 01:07:08 

eat one

Jack [ 匿名]  2008-11-23 21:51:05 

a bird

Raphael [ 匿名]  2008-11-23 21:21:10 

Good thongs don

Samir [ 匿名]  2008-11-23 20:05:32 

Don

Gerry [ 匿名]  2008-11-23 18:35:38 

God doesn

Brent [ 匿名]  2008-11-23 17:51:14 

A sp

Hassan [ 匿名]  2008-11-23 17:35:03 

have an ace up one

Kristofer [ 匿名]  2008-11-23 15:35:54 

from under one

Rufus [ 匿名]  2008-11-23 14:36:50 

Don

Jamaal [ 匿名]  2008-11-23 12:21:00 

If you can

Francesco [ 匿名]  2008-11-23 09:51:58 

Don

Cristian [ 匿名]  2008-11-23 07:52:43 

All aren

Timothy [ 匿名]  2008-11-23 00:38:00 

Good thongs don

Charles [ 匿名]  2008-11-22 22:52:35 

Don

Timmy [ 匿名]  2008-11-22 20:35:42 

Don

Joey [ 匿名]  2008-11-22 16:50:43 

A sp

Jayson [ 匿名]  2008-11-22 16:06:14 

Don

Jed [ 匿名]  2008-11-22 15:36:51 

A man can

Reinaldo [ 匿名]  2008-11-22 08:28:24 

from under one

Donnie [ 匿名]  2008-11-22 07:28:24 

Don

Brandon [ 匿名]  2008-11-22 01:56:34 

Don

Carson [ 匿名]  2008-11-22 00:55:45 

A single thread from everyone

Justen [ 匿名]  2008-11-21 23:09:51 

Jonathan [ 匿名]  2008-11-21 22:55:10 

God doesn

Leonard [ 匿名]  2008-11-21 18:51:41 

Don

Quentin [ 匿名]  2008-11-21 13:36:10 

get one

Beau [ 匿名]  2008-11-21 11:06:49 

If you don

Horace [ 匿名]  2008-11-21 06:08:57 

If you don

Ramiro [ 匿名]  2008-11-21 04:52:36 

All aren

Ulysses [ 匿名]  2008-11-21 04:06:10 

If you can

Van [ 匿名]  2008-11-21 01:32:09 

If you don

Leif [ 匿名]  2008-11-21 01:16:42 

Benjamin

Dwight [ 匿名]  2008-11-21 00:29:07 

All aren

Pierre [ 匿名]  2008-11-20 20:56:23 

If you don

漫天皆白, 雪里行军情更迫。 头上高山, 风卷红旗过大关。 此行何去?
推荐文章
最近访客