- 论坛徽章:
- 0
|
2005-3-31更新
OpenBSD LiveCD制作过程
刚开始接触OpenBSD时,我就很想使用OpenBSD LiveCD,但没找到。今年1月那时起就想自己做一个LiveCD,一个新年一过, 就将它放下了,现在又重新开始制作,今天写这篇文章只是我思路的一个开始,制作的LiveCD,还不完善,我会后续为其改进。
制作过程:
一、 准备工作:
1、 一个能运行OpenBSD系统的所需要的必备文件,这里我就没像一些mini LiveCD那样对系统进行剔牛肉进行精减了,只是将一个能运行的系统的所有文件进行备份。而且如果备份的文件不大, 那制作出的LiveCD就很小, 我们就可以将这个备份的系统文件也一起放进CD中, 到时就可以用这个LiveCD安装系统,方法就是我今年1月3日写的《OpenBSD 另类安装法》。
2、 OpenBSD系统的源程序,我们在制作过程中需要编译光盘镜像。
二、 将备份的系统文件解开到一个目录下,我将以这个目录作为LiveCD的根目录制作CD,如/usr/live/。
三、 将OpenBSD源程序解开到/usr/src下,然后:
1、 安装必须的程序:
# cd /usr/src/distrib/crunch/crunchgen
#make; make install
#cd /usr/src/distrib/crunch/crunchide
#make; make install
2、 定制内核
内核文件是/usr/src/sys/arch/i386/conf/RAMDISK_CD,我们需要对这个文件进行修改,其中有三行最重要,一定不能少:
option MFS
option UNION
config bsd root on cd0a
LiveCD运行于MFS上,而且它的根目录在CD上。
还有其它一些选项如:
option SMALL_KERNEL
option NO_PROPLICE
option TIMEZONE=0
option DST=0
option RAMDISK_HOOKS
option MINIROOTSIZE=3560
需要将一些多余的东西删除,因此这个内核大小控制在2.88M以内, 太大时会编译失败。我的RAMDISK_CD是将/usr/src/sys/arch/i386/conf/GENERIC 和/usr/src/sys/conf/GENERIC这两个文章合并然后去掉一些内容整理出来的。
3、 编译内核
# cd /usr/src/distrib/i386/ramdisk_cd
#make
成功后会在目录下生成cdrom36.fs这个文件,我们将这个文件复制到制作LiveCD的目录下/usr/live/。
四、 修改/usr/live/etc中的各类文件
1、fstab
- /dev/cd0a / cd9660 ro,noatime 0 0
- swap /dev mfs rw,noatime,union,-s=16384 0 0
- swap /tmp mfs rw,nodev,noexec,nosuid,noatime,-s=32768 0 0
- swap /etc mfs rw,noatime,-s=16384 0 0
- swap /var mfs rw,noatime,-s=16384 0 0
- swap /home mfs rw,noatime,-s=16384 0 0
复制代码
以前我没发现fstab的功能居然如此强大, 以为它只能mount已分好的挂载点, 原来它在光盘系统中还可以在启动时自动挂载写入fstab中的mfs.
2、rc
OpenBSD启动时首先读取这个文件, 如果找不到它就会读取根目录下的/.profile文件进行初始配置。
修改/etc/rc文件, 三个地方修改
-
- # $OpenBSD: rc,v 1.251 2004/08/21 08:17:28 hshoexer Exp $
- # System startup script run by init on autoboot
- # or after single-user.
- # Output and error are redirected to console by init,
- # and the console is the controlling terminal.
- # Subroutines (have to come first).
- # Strip comments (and leading/trailing whitespace if IFS is set)
- # from a file and spew to stdout
- stripcom() {
- local _file="$1"
- local _line
- {
- while read _line ; do
- _line=${_line%%#*} # strip comments
- test -z "$_line" && continue
- echo $_line
- done
- } < $_file
- }
- # End subroutines
- stty status '^T'
- # Set shell to ignore SIGINT (2), but not children;
- # shell catches SIGQUIT (3) and returns to single user after fsck.
- trap : 2
- trap : 3 # shouldn't be needed
- HOME=/; export HOME
- PATH=/sbin:/bin:/usr/sbin:/usr/bin
- export PATH
- if [ $1x = shutdownx ]; then
- dd if=/dev/urandom of=/var/db/host.random bs=1024 count=64 >;/dev/null 2>;&1
- chmod 600 /var/db/host.random >;/dev/null 2>;&1
- if [ $? -eq 0 -a -f /etc/rc.shutdown ]; then
- echo /etc/rc.shutdown in progress...
- . /etc/rc.shutdown
- echo /etc/rc.shutdown complete.
- # bring carp interfaces down gracefully
- for hn in /etc/hostname.carp[0-9]*; do
- # Strip off /etc/hostname. prefix
- if=${hn#/etc/hostname.}
- test "$if" = "carp[0-9]*" && continue
- ifconfig $if >; /dev/null 2>;&1
- if [ "$?" != "0" ]; then
- ifconfig $if down
- fi
- done
- if [ "X${powerdown}" = X"YES" ]; then
- exit 2
- fi
- else
- echo single user: not running /etc/rc.shutdown
- fi
- exit 0
- fi
- # Configure ccd devices.
- if [ -f /etc/ccd.conf ]; then
- ccdconfig -C
- fi
- # Configure raid devices.
- for dev in 0 1 2 3; do
- if [ -f /etc/raid$dev.conf ]; then
- raidctl -c /etc/raid$dev.conf raid$dev
- fi
- done
- # Check parity on raid devices.
- raidctl -P all
- swapctl -A -t blk
- if [ -e /fastboot ]; then
- echo "Fast boot: skipping disk checks."
- elif [ $1x = autobootx ]; then
- echo "Automatic boot in progress: starting file system checks."
- # fsck –p 这一行要注释掉
- case $? in
- 0)
- ;;
- 2)
- exit 1
- ;;
- 4)
- echo "Rebooting..."
- reboot
- echo "Reboot failed; help!"
- exit 1
- ;;
- 8)
- echo "Automatic file system check failed; help!"
- exit 1
- ;;
- 12)
- echo "Boot interrupted."
- exit 1
- ;;
- 130)
- # interrupt before catcher installed
- exit 1
- ;;
- *)
- echo "Unknown error; help!"
- exit 1
- ;;
- esac
- fi
- trap "echo 'Boot interrupted.'; exit 1" 3
- umount -a >;/dev/null 2>;&1
- mount -a -t nonfs
- mount -uw / # root on nfs requires this, others aren't hurt
- rm -f /fastboot # XXX (root now writeable)
- 这里需要在/dev下建立三个设备点, 不然后一步tar出错, 系统启动时会问题多多
- mknod /dev/stdout c 22 1
- mknod /dev/stdin c 22 0
- mknod /dev/stderr c 22 2
- if [ -f /mfs/mfs.tgz ]; then
- tar zxpf /mfs/mfs.tgz -C /
- echo 'Fixed up mfs from /mfs/mfs.tgz'
- fi
- chmod 755 /dev /etc /var
- chmod a+rwx,a+t /tmp
- # set flags on ttys. (do early, in case they use tty for SLIP in netstart)
- echo 'setting tty flags'
- ttyflags -a
- if [ "X${pf}" != X"NO" ]; then
- RULES="block all"
- RULES="$RULES\npass on lo0"
- RULES="$RULES\npass in proto tcp from any to any port 22 keep state"
- RULES="$RULES\npass out proto { tcp, udp } from any to any port 53 keep state"
- RULES="$RULES\npass out inet proto icmp all icmp-type echoreq keep state"
- RULES="$RULES\npass out inet6 proto icmp6 all icmp6-type routersol"
- RULES="$RULES\npass in inet6 proto icmp6 all icmp6-type routeradv"
- RULES="$RULES\npass proto { pfsync, carp }"
- case `sysctl vfs.mounts.nfs 2>;/dev/null` in
- *[1-9]*)
- # don't kill NFS
- RULES="scrub in all no-df\n$RULES"
- RULES="$RULES\npass in proto udp from any port { 111, 2049 } to any"
- RULES="$RULES\npass out proto udp from any to any port { 111, 2049 }"
- ;;
- esac
- echo $RULES | pfctl -f - -e
- fi
- if [ -f /etc/sysctl.conf ]; then
- (
- # delete comments and blank lines
- set -- `stripcom /etc/sysctl.conf`
- while [ $# -ge 1 ] ; do
- sysctl $1
- shift
- done
- )
- fi
- # set hostname, turn on network
- echo "Setting Network......" 修改这里, 加入我写的setnetwork脚本,
- . /etc/setnetwork 这样网络设置在每台机上都可以重新设置而不是更改文件.
复制代码
3、上一步最后有一个setnetwork脚本,这一步写出。我的脚本编写不会, 只好从其它地方抄过来,有一些错误,需要请高手改写。这个文件有点大, 贴在最后吧!
4、将一些网络配置的文件删除如:hosts, mygate等。上一步的network在启动时会生成这些配置文件。
五、 备份几个目录,在4.3 rc脚本中的MFS部分那个文件。
在/usr/live/ LiveCD根目录下建立文件夹:mfs 然后:
# tar cvzfp mfs/mfs.tgz dev etc home var
六、 制作ISO镜像:
# cd /usr/live
# mkhybrid –b cdrom36.fs –c boot.catalog –R –v –o /usr/OpenBSD-LiveCD.iso /usr/live
现在制作完成, 你可以用虚拟机测试这个生成的ISO镜像。
参考了网上许多文章, 这里就不一一列出来了, 感谢那些大哥写出那么好的教程.
我现在还有几个问题需要解决,主要是MFS这方面的,另外shell脚本的错误也需要大家来解决。
设置网络用的setnetwork脚本:
setnetwork:
我将制作的一个livecd放在:
ftp://ftp.linuxeden.com/rianren/
各位可以下载来试试! |
|