星期一, 十月 16, 2006

ALFS: jhalfs-1.0 CLFS

要在非 x86 平台上编译 LFS,需要使用 CLFS。

jhalfs 已经被用了替代 nALFS,它直接从 LFS BOOK 的 xml 文档中提取命令。目前 livecd 中使用的是 jhalfs-1.0,因为 jhalfs-2.0 似乎还只支持 x86 平台。

首先从 livecd 中拷贝 jhalfs-1.0 和源代码包:
# useradd lfs
# mount -t iso9660 /mnt/file/iso/lfslivecd-x86-6.2-3.iso -o loop /mnt/cdrom
# mount -t ext2 /mnt/cdrom/root.ext2 -o loop /mnt/lfslivecd
# su - lfs
$ cp /mnt/lfslivecd/jhalfs-1.0 .
$ cp /mnt/lfslivecd/lfs-sources .
$ exit

调整:
# cd jhalfs-1.0
# vi common/config
# declare -r SVN="svn://svn.linuxfromscratch.org"
declare -r SVN="http://svn.cross-lfs.org/svn/repos"

这是因为 CLFS 的站点已经变化,所以需要修改相应的 SVN 指向,否则无法得到需要的 CLFS BOOK。参见:
http://linux-phreak.biz/pipermail/clfs-dev/2006-September/000332.html

查看 Books Supported by jhalfs
可以看到当前 stable 版本是 1.0.0,于是可以运行如下命令开始安装:
# export SRC_ARCHIVE=~lfs/lfs-sources
# export CLFS=/mnt/lfs
// 一定要有这个环境变量
# vi CLFS/config
TIMEZONE=Asia/Shanghai
# ./clfs -B 1.0.0 -D /mnt/lfs -K ~lfs/skeleton/linux-kernel-config -F ~lfs/skeleton/etc/fstab -G -T 0 -M
-B: 指定 CLFS BOOK version
-D: 目标目录,mount /dev/sda7 /mnt/lfs
-K: 内核 .config 文件
-F: /etc/fstab
-G: 设定如果包不在 ~lfs/lfs-sources,则下载之
-T:
-M: Make,即前面所有步骤会生成 Makefiles,执行之。否则可以在 /mnt/lfs/jhalfs 下运行 make

最后,为方便和简单起见,将主系统中的 kernel, initrd, /etc/modprobe.conf, /lib/modules/`uname -r` 全部拷贝到 $CLFS,并使用主系统的 grub 启动。

troubleshooting:
使用 jhalfs-1.0 安装 CLFS 于 x86_64 pure64,从 $CLFS/jhalfs/logs 来看,没有报什么错误,于是我将原来系统的 kernel, initrd, /etc/modprobe.conf, /lib/modules/$version 拷贝到 $CLFS 相应目录(我以前也这么干过,是可以的),在 grub.conf 中增加相应的记录:
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda8 39G 20G 17G 54% /
tmpfs 217M 0 217M 0% /dev/shm
/dev/sda7 40G 2.3G 36G 7% /mnt/lfs
/dev 217M 112K 217M 1% /mnt/lfs/dev
tmpfs 217M 112K 217M 1% /mnt/lfs/dev/shm
devpts 217M 112K 217M 1% /mnt/lfs/dev/pts
/dev/sda9 40G 16G 22G 42% /mnt/file

# vi $CLFS/etc/fstab
# filesystem    mount-point     fs-type options         dump fsck-order
/dev/hda7 / ext3 defaults 1 1
# /dev/hda6 swap swap pri=1 0 0
/dev/hda6 swap swap defaults 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
# usbfs /proc/bus/usb usbfs devgid=14,devmode=0660 0 0


重启后启动 LFS,报错如下:
Checking file system ...
/dev/hda7
The superblock could not be read or does not describe a correct ext2 filesystem. If the device is valid and it really contains an ext2 filesystem(and not swap or ufs or something else), then the superblock is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193

FAILURE:
File system error were encountered that could not be fixed automatically...

Press Enter and the system wlll halt

重启到主系统,运行如下命令:
# vi CHROOT.sh
#!/bin/sh
# mount /dev/sda7 /mnt/lfs -o remount
export CLFS=/mnt/lfs
mount -vt proc proc ${CLFS}/proc
mount -vt sysfs sysfs ${CLFS}/sys
mount -v -o bind /dev ${CLFS}/dev
mount -f -vt tmpfs tmpfs ${CLFS}/dev/shm
mount -f -vt devpts -o gid=4,mode=620 devpts ${CLFS}/dev/pts
chroot "${CLFS}"

# vi LOGOUT.sh
#!/bin/sh
logout
export CLFS=/mnt/lfs
umount ${CLFS}/dev/pts
umount ${CLFS}/dev/shm
umount ${CLFS}/dev
umount ${CLFS}/proc
umount ${CLFS}/sys
umount ${CLFS}


# mount /dev/sda7 /mnt/lfs
# export CLFS=/mnt/lfs
# sh CHROOT.sh
// 上面三个命令每次从主系统进入 CLFS 都必须执行,在重启主系统时则需要执行
// sh LOGOUT.sh
# dumpe2fs /dev/sda7 | less
// 找到所有 superblocks 所在的块,选择一个,比如第二个
# fsck.ext3 -b 32768 /dev/sda7 -y
这样并无效果。

再次启动到 LFS,仔细观察输出,可以发现远在报错之前,就已经出现:
Loading jbd.ko module
Loading ext3.ko module
Trying to resume from /dev/sda6
No suspend signature on swap, not resuming.
Creating root device.
Mounting root filesystem.
kjournald starting. Commit internal 5 seconds
EXT3-fs: mounted filesystem with ordered data mode
setting up other filesystems
setting up new root fs
no fstab.sys, mounting internal defaults
Swithing to new root and running init

回到主系统,chroot 到 CLFS,将 fstab 拷贝为 fstab.sys,再次重启 LFS。

这次明确提示没有找到 /dev/hda7,无法 mount。再仔细看 fstab,原来是将 sda7 写成了 hda7!

DON'T PANIC!
DON'T PANIC!!
DON'T PANIC!!!

没有评论: