当前位置:Linux教程 - 安装启动 - 安装启动 - edHat 7.3 Live in CDROM HowTo

安装启动 - edHat 7.3 Live in CDROM HowTo

edHat 7.3 Live in CDROM HowTo
2004-04-23 15:18 pm
来自:Linux文档
现载:Www.8s8s.coM
地址:无名

思路:
使用cdrom引导并运行linux,关键要解决如下问题:
一:如何把系统运行时候使用的文件系统/dev,/var,/tmp变成可写。
二:如何改变系统引导顺序
基本步骤:
(0) 环境准备
。准备一个PC
大硬盘
光盘刻录机
128M内存
分区如下
/dev/hda1 linux boot ext2
/dev/hda2 linux root ext2
/dev/hda3 linux swap
/dev/hda4 extendend
/dev/hda5 linux root ext2 至少650M以上

。main install安装。
boot分区在/dev/hda1,
root分区在/dev/hda2,
swap分区在/dev/hda3。
必要的工具,例如mkisofs、cdrecord等。

。test install安装
一个分区在/dev/hda5,
swap使用/dev/hda3,
只安装需要放置到CDROM的软件.
注意:不能破坏主引导扇区,它是通过main inst的lilo引导的

。双引导配置
重新启动计算机,此时会进入main install,执行如下步骤:
#mkdir /mnt/lfs
#mount –t ext2 /dev/hda5 /mnt/lfs
# vi /etc/lilo
# /sbin/lilo
——————————————————————
/etc/lilo.conf文件内容如下:
prompt
timeout=50
default=linux
boot=/dev/had
map=/boot/map
install=/boot/boot.b
message=/boot/message
linear

image=/boot/vmlinuz-2.4.18-3
label=main_inst
initrd=/boot/initrd-2.4.18-3.img
read-only
append="ramdisk=20480"
root=/dev/hda2 <——main install 的root分区

image =/mnt/lfs/boot/vmlinuz-2.4.18-3
label=test_inst
read-only
append="ramdisk=32768"
root=/dev/hda5 &——test install的root分区
————————————————————————————

。test install环境调整
重新引导,选择test install ;
确认test install 能够自引导并且一切都正常;
然后根据需要,可以做:
删除不必要的软件包,
安装用户应用软件,
重新编译内核。等等

(一)配置test install环境

。重新引导,选择main install ,并执行
#mount –t ext2 /dev/hda5 /mnt/lfs
。配置/var,/dev到ramdisk系统
#vi /mnt/lfs/etc/rc.d/rc.iso
_______________________________
创建/mnt/lfs/etc/rc.d/rc.iso
# /var
mke2fs -q -i 1024 /dev/ram1 16384
mount /dev/ram1 /var -o defaults,rw
cp -a /lib/var /

# /dev
mke2fs -q -i 1024 /dev/ram2 16384
mount /dev/ram2 /dev -o rw
cp -a /lib/dev /
(建立这么大的/dev是因为inode数目的限制,dev下文件特别多)
____________________________________________________
。编辑/mnt/lfs/etc/rc.sysnit
a) 禁止重新mount 根文件系统位rw
# Remount the root filesystem read-write.
# state=`awk '/(^/dev/root| / / { print $4 }' /proc/mounts`
#[ "$state" != "rw" ] &&
# action $"Remounting root filesystem in read-write mode: " mount -n -o remount,rw /
b) 调用rc.iso脚步

# Set the path
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
HOSTNAME=`/bin/hostname`
一节之后,增加如下内容
# To boot from cdrom
. /etc/rc.d/rc.iso
c)禁止激活交换分区
# Now turn on swap in case we swap to files.
#swapon -a
#action $"Enabling swap space: " /bin/true

d)禁止执行fsck
在这个位置
if [ -f /fsckoptions ]; then
fsckoptions=`cat /fsckoptions`
else
fsckoptions=
fi
增加语句,用来控制是否执行fsck
fastboot=yes
fsckoptions=

e)禁止mount 其他文件系统
# Mount all other filesystems (except for NFS and /proc, which is already
# mounted). Contrary to standard usage,
# filesystems are NOT unmounted in single user mode.
#action $"Mounting local filesystems: " mount -a -t nonfs,smbfs,ncpfs -O no_netdev
f) 禁止自动执行文件系统检查
# create the crash indicator flag to warn on crashes, offer fsck with timeout
# touch /.autofsck
。编辑/etc/rc.d/init.d/random
修改如下语句
random_seed=/var/lib/random-seed

random_seed=/var/run/random-see

。创建并执行如下脚步,它建立了/var 、/tmp、/dev的模板, 创建/etc/mtab的链接
#cd /mnt/lfs
# vi create_iso.sh
# sh create_iso.sh

————————————————————————
#!/bin/sh
echo tmp
rm -fR /mnt/lfs/tmp
ln -s var/tmp /mnt/lfs/tmp

###
echo mtab
touch /mnt/lfs/proc/mounts
rm /mnt/lfs/etc/mtab
ln -s /proc/mounts /mnt/lfs/etc/mtab
###
echo dev
mkdir /mnt/lfs/lib/dev
cp –a /mnt/lfs/dev /mnt/lfs/lib
###
echo var
mv /mnt/lfs/var/lib /mnt/lfs/lib/var-lib
mv /mnt/lfs/var /mnt/lfs/lib
mkdir /mnt/lfs/var
ln -s /lib/var-lib /mnt/lfs/lib/var/lib
for i in `find /mnt/lfs/lib/var/log -type f`; do cat /dev/null > $i; done
rm `find /mnt/lfs/lib/var/lock -type f`
rm `find /mnt/lfs/lib/var/run -type f`
______________________________________________

。 确认test install环境的正确
重新引导,选择test install
这时这个install应该象一个cdrom似的。
如果有什么工作不正常,或者重新引导,选择main install后进行修复;
或者在test install中执行如下命令后可以进行修复:
mount -o remount,rw /


(二) 创建boot image
。重新引导,选择main install

。产生一个可以启动的软盘
# mkbootdisk --mkinitrdargs --with=ide-cd `uname -r`

。按照如下步骤抽取boot.img中的文件
# dd if=/dev/fd0 of=/tmp/cdrom.img bs=1440k count=1
# mkdir /mnt/bootfd
# mount -o loop -t msdos /tmp/cdrom.img /mnt/bootfd
# zcat /mnt/bootfd/initrd.img > /tmp/initrd-cdrom
# mkdir /mnt/initrd
# mount -o loop /tmp/initrd-cdrom /mnt/initrd
。拷贝test install的内核到boot.img文件中
cp /mnt/lfs/boot/zImage /mnt/bootfd
注意:根据实际情况,有可能需要修改zImage的名字
。拷贝cdrom驱动模块到cdrom.img中
#cd /mnt/initrd/lib
#cp /lib/modules/2.4.18-3/kernel/drivers/cdrom/cdrom.o .
#cp /lib/modules/2.4.18-3/kernel/drivers/ide/ide-cd.o .
#cp /lib/modules/2.4.18-3/kernel/fs/nls/nls_iso8859-1.o .
。 编辑linuxrc文件
# vi /mnt/initrd/linuxrc
----------------------------------
#!/bin/nash

echo "Loading cdrom module"
insmod /lib/cdrom.o
echo "Loading ide-cd module"
insmod /lib/ide-cd.o
echo "Loading nls_iso8859-1 module"
insmod /lib/nls_iso8859-1.o
echo Mounting /proc filesystem
mount -t proc /proc /proc
echo Creating root device
mkrootdev /dev/root
echo 0x0100 > /proc/sys/kernel/real-root-dev
echo Mounting root filesystem
mount --ro -t iso9660 /dev/root /sysroot
umount /proc
pivot_root /sysroot /sysroot/initrd
---------------------------------------------
。编辑boot.img文件中的syslinux.cfg
# cd /mnt/bootfd
# vi syslinux.cfg
_____________________________________
default linux
label linux
kernel zImage
append initrd=initrd.img root=/dev/hdc rmdisk=32768

———————————————————————
注意:root= 后面是光驱设备名称

。压缩initrd,并拷贝到boot.img
# umount /mnt/initrd
# gzip -9 < /tmp/initrd-cdrom > /mnt/bootfd/initrd.img

。拷贝boot image文件
# umount /mnt/bootfd
# mv /tmp/cdrom.img /mnt/lfs/boot.img

(三) 创建并校验iso image
。继续在main install中工作
。创建iso image

# cd /root/lfs & 确保其空间足够存储iso image
#mkisofs -R -b boot.img -c boot.catalog -o boot.iso /mnt/lfs

。校验iso image的正确性

a) 通过loop 设备 mount 光盘映象文件
# mkdir /mnt/iso
# mount boot.iso /mnt/iso -o loop -t iso9660
b) 校验boot.iso 内容正确
c) umount boot.iso
umount /mnt/iso
(四) 刻录光盘
1) 使用linux来刻录
刻录设备的安装请参考CD-Writing HOWTO。
命令行:
cdrecord -v speed=<desired writing speed> dev=<path to your writers generic scsi device> boot.iso

2)如果使用windows来刻录
可以把iso image ftp到windos平台上,然后使用相应的程序进行刻录



其他问题
1: dev文件系统
我是通过建立ramdisk的办法来完成的。这需要配置内核支持足够大的ramdik。
另外的一种做法是使用DEVFS文件系统来完成对dev目录的出来,我没有尝试。。
2:其他文件系统
系统在启动的时候会提示“mount other filesystem fail“这个问题可以通过注释/etc/rc.d/init.d/netfs文件:
Action $”Mounting other filesystem:” mount –a –t nonfs,smbfs,ncpfs来解决。
但是如果注释掉的话会telnet连接不了

3: 继续‘瘦身’
我目前只是没有安装x window,应该还可以继续减少其他软件包。
4: 换碟
使用目前的引导办法,cdrom启动之后,就不能更换。在那篇日文的资料里,介绍了使用tmpfs系统的办法,把整个root系统放到内存了。这是通过在boot的时候,使用init选项把这个文件展开。
5:通用性问题
不同硬盘、光驱、主板、网卡



参考资料:
http://www.linuxaid.com.cn/articles/7/1/710687494.shtml
介绍制作自己的linux发行版,里面关于boot.img文件的分析比较好
http://tldp.org/HOWTO/Diskless-root-NFS-HOWTO.html
有一章是关于制作live in cdrom的。特别是讲解了原理
http://tldp.org/HOWTO/Bootdisk-HOWTO/index.html
关于lilo,boot 过程的权威
http://www15.big.or.jp/~yamamori/sun/cdlinux/
关于用cdrom直接运行游戏的介绍,日文的。Initrd.Img的配置比较详细