LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 2135|回复: 13

chroot + livecd = 硬盘安装LFS

[复制链接]
发表于 2007-3-17 00:13:45 | 显示全部楼层 |阅读模式
用livecd安装LFS的一大好处就是成功率比较高,这点对于新手尤其重要。
硬盘安装的好处有很多,这里就不多说了。

论坛精华区有一篇帖子介绍了“把livecd安装在硬盘上”的方法[http://www.linuxsir.cn/bbs/showthread.php?t=274629],可惜我多番尝试都不成功,更改init.c再重新编译重新打包对我来说太难了。

不过我由此得到了提示,再参考livecd的/root目录里的那篇lfscd-remastering-howto.txt,
摸索出了一个比较容易操作的方法。现在不使用光驱,不重启电脑,就可以利用LiveCD的环境来编译安装LFS了。

我下载了lfslivecd-x86-6.2-5.iso,然后

mkdir /mnt/isolfs
mount -o loop lfslivecd-x86-6.2-5.iso /mnt/isolfs
mkdir /mnt/lfslivecd
export WORK=/mnt/lfslivecd
cp /mnt/isolfs/root.ext2 $WORK/root.ext2

这时请查看 $WORK/root.ext2 是不是1.5G,如果不是,请参考lfscd-remastering-howto.txt[http://wiki.linuxfromscratch.org ... -howto.txt?rev=1744]里的办法,得到这个1.5G的文件,然后继续。

mkdir $WORK/root
mount -o loop $WORK/root.ext2 $WORK/root

mount -t proc proc $WORK/root/proc
mount -t sysfs sysfs $WORK/root/sys
mount -t devpts devpts $WORK/root/dev/pts
mount -t tmpfs tmpfs $WORK/root/dev/shm

mount --bind /dev $WORK/root/dev        #这句是安装gentoo时学到的。

一切准备就绪,可以chroot了。

chroot /mnt/lfslivecd/root

现在测试一下这个工作环境是否理想,运行以下命令:
  1. cat > version-check.sh << "EOF"
  2. #!/bin/bash
  3. # Simple script to list version numbers of critical development tools
  4. bash --version | head -n1 | cut -d" " -f2-4
  5. echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-4
  6. bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-
  7. echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
  8. diff --version | head -n1
  9. find --version | head -n1
  10. gawk --version | head -n1
  11. gcc --version | head -n1
  12. /lib/libc.so.6 | head -n1 | cut -d" " -f1-7
  13. grep --version | head -n1
  14. gzip --version | head -n1
  15. cat /proc/version | head -n1 | cut -d" " -f1-3,5-7
  16. make --version | head -n1
  17. patch --version | head -n1
  18. sed --version | head -n1
  19. tar --version | head -n1
  20. EOF
  21. bash version-check.sh
复制代码

如果你也使用livecd-x86-6.2-5.iso,将会得到以下结果:
  1. bash, version 3.1.17(1)-release
  2. Binutils: version 2.16.1
  3. bzip2,  Version 1.0.3, 15-Feb-2005.
  4. Coreutils:  5.96
  5. diff (GNU diffutils) 2.8.1
  6. GNU find version 4.2.27
  7. GNU Awk 3.1.5
  8. gcc (GCC) 4.0.3
  9. GNU C Library stable release version 2.3.6,
  10. grep (GNU grep) 2.5.1
  11. gzip 1.3.5
  12. Linux version 2.6.18-3-686 2.6.18-7) (waldi@debian.org) (gcc
  13. GNU Make 3.80
  14. patch 2.5.4
  15. GNU sed version 4.1.5
  16. tar (GNU tar) 1.15.1
复制代码

可见,得到了一个很适合安装LFS的宿主环境。Have fun!

*********************

补充一点,我在这个环境里根据/root/README的说明来设置,可以用startx进xfce里上网。但我还没有正式在里面安装LFS,所以虽然现在一切看起来很好,但并不完全确定安装过程中会有什么情况发生。

另外,我有一个疑问,

mount -t sysfs sysfs $WORK/root/sys
mount -t devpts devpts $WORK/root/dev/pts
mount -t tmpfs tmpfs $WORK/root/dev/shm

这几句我是按照lfscd-remastering-howto.txt来写的,不知道具体有什么用处。高手可以讲解一下吗?谢谢!
发表于 2007-3-17 10:29:50 | 显示全部楼层
太好了!
支持!
这样就真的可以边工作边做LFS了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-3-17 16:45:39 | 显示全部楼层
多谢支持。我现在就是一边使用debian一边在livecd环境里编译LFS。

刚刚出现了问题。

进行到 5.10. DejaGNU-1.4.4,在make check时说 no more pts。
在非chroot的终端执行
mount -o bind /dev/pts /mnt/lfslivecd/root/dev/pts
后解决问题。

不知道刚开始时不要
mount -t devpts devpts $WORK/root/dev/pts
mount -t tmpfs tmpfs $WORK/root/dev/shm
只用
mount -o bind /dev $WORK/root/dev
会不会更好。

另外,装好第二遍的GCC后,make check出现了错误,不知道怕不怕。
回复 支持 反对

使用道具 举报

发表于 2007-3-18 11:10:56 | 显示全部楼层
gcc 第二遍 make check 会有错,手册也有说明
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-3-18 18:26:26 | 显示全部楼层
是呀,我后来也在手册上看到了,另外手册里对 pts shm 等也有解释,真是详尽得可怕的手册。
回复 支持 反对

使用道具 举报

发表于 2007-5-16 14:46:25 | 显示全部楼层
在这个环境下
#uname -a
显示的仍是原系统的信息而不是Livecd的信息...
没问题吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-5-17 22:55:51 | 显示全部楼层
后来我已经安装通过了,完全没有问题。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-5-19 21:33:53 | 显示全部楼层
发现一个问题,如果要在这个chroot里上网先要 *在非chroot状态下* 运行这个命令
cp /etc/resolv.conf /mnt/lfslivecd/root/etc/
回复 支持 反对

使用道具 举报

发表于 2007-6-21 17:16:42 | 显示全部楼层
Post by kikiwarm
多谢支持。我现在就是一边使用debian一边在livecd环境里编译LFS。

刚刚出现了问题。

进行到 5.10. DejaGNU-1.4.4,在make check时说 no more pts。
在非chroot的终端执行
mount -o bind /dev/pts /mnt/lfslivecd/root/dev/pts
后解决问题。

不知道刚开始时不要
mount -t devpts devpts $WORK/root/dev/pts
mount -t tmpfs tmpfs $WORK/root/dev/shm
只用
mount -o bind /dev $WORK/root/dev
会不会更好。

另外,装好第二遍的GCC后,make check出现了错误,不知道怕不怕。



如果不要前面两句,我出现一下错误:
lfs:/mnt/lfs/sources/dejagnu-1.4.4$ make check
Making check in doc
make[1]: Entering directory `/mnt/lfs/sources/dejagnu-1.4.4/doc'
make[1]: Nothing to be done for `check'.
make[1]: Leaving directory `/mnt/lfs/sources/dejagnu-1.4.4/doc'
make[1]: Entering directory `/mnt/lfs/sources/dejagnu-1.4.4'
make  check-DEJAGNU
make[2]: Entering directory `/mnt/lfs/sources/dejagnu-1.4.4'
cd testsuite ; make check
make[3]: Entering directory `/mnt/lfs/sources/dejagnu-1.4.4/testsuite'
Making check in libdejagnu
make[4]: Entering directory `/mnt/lfs/sources/dejagnu-1.4.4/testsuite/libdejagnu'
if g++ -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"dejagnu\" -DVERSION=\"1.4.4\"  -I. -I.    -I../.. -g -g -O2 -MT unit.o -MD -MP -MF ".deps/unit.Tpo" \
  -c -o unit.o `test -f 'unit.cc' || echo './'`unit.cc; \
then mv -f ".deps/unit.Tpo" ".deps/unit.Po"; \
else rm -f ".deps/unit.Tpo"; exit 1; \
fi
g++ -I../.. -g -g -O2   -o unit  unit.o
make[4]: Leaving directory `/mnt/lfs/sources/dejagnu-1.4.4/testsuite/libdejagnu'make[4]: Entering directory `/mnt/lfs/sources/dejagnu-1.4.4/testsuite'
Nothing to be done for all
make  check-DEJAGNU
make[5]: Entering directory `/mnt/lfs/sources/dejagnu-1.4.4/testsuite'
Making a new site.exp file...
srcdir=`CDPATH="${ZSH_VERSION+.}:" && cd . && pwd`; export srcdir; \
EXPECT=expect; export EXPECT; \
runtest=` if [ -f ../runtest ] ; then echo ../runtest; else echo "ERROR: runtest not found" ; exit 1; fi`; \
if /bin/sh -c "$runtest --version" > /dev/null 2>&1; then \
  l='dejagnu'; for tool in $l; do \
    $runtest  --srcdir $srcdir ; \
  done; \
else echo "WARNING: could not find \`runtest'" 1>&2; :;\
fi
WARNING: Couldn't find the global config file.
WARNING: No tool specified
Test Run By lfs on Thu Jun 21 08:23:52 2007
Native configuration is i686-pc-linux-gnu

                ===  tests ===

Schedule of variations:
    unix

Running target unix
Using /mnt/lfs/sources/dejagnu-1.4.4/testsuite/../config/base-config.exp as tool-and-target-specific interface file.
Using /mnt/lfs/sources/dejagnu-1.4.4/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /mnt/lfs/sources/dejagnu-1.4.4/testsuite/libdejagnu/tunit.exp ...
ERROR: tcl error sourcing /mnt/lfs/sources/dejagnu-1.4.4/testsuite/libdejagnu/tunit.exp.
ERROR: The system has no more ptys.  Ask your system administrator to create more.
    while executing
"spawn -noecho "./${executable}" ${params}"
    (procedure "host_execute" line 29)
    invoked from within
"host_execute "unit""
    (file "/mnt/lfs/sources/dejagnu-1.4.4/testsuite/libdejagnu/tunit.exp" line 1)
    ("uplevel" body line 1)
    invoked from within
"catch "uplevel #0 source $test_file_name""
Running /mnt/lfs/sources/dejagnu-1.4.4/testsuite/runtest.all/libs.exp ...
Running /mnt/lfs/sources/dejagnu-1.4.4/testsuite/runtest.all/options.exp ...
ERROR: Couldn't find library file util-defs.exp.
make[5]: *** [check-DEJAGNU] Error 1
make[5]: Leaving directory `/mnt/lfs/sources/dejagnu-1.4.4/testsuite'
make[4]: *** [check-am] Error 2
make[4]: Leaving directory `/mnt/lfs/sources/dejagnu-1.4.4/testsuite'
make[3]: *** [check-recursive] Error 1
make[3]: Leaving directory `/mnt/lfs/sources/dejagnu-1.4.4/testsuite'
make[2]: *** [check-DEJAGNU] Error 2
make[2]: Leaving directory `/mnt/lfs/sources/dejagnu-1.4.4'
make[1]: *** [check-am] Error 2
make[1]: Leaving directory `/mnt/lfs/sources/dejagnu-1.4.4'
make: *** [check-recursive] Error 1
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-6-21 22:50:13 | 显示全部楼层
多谢反馈!
看来那两句还是有用的
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表