本节有很多输入工作要做,因为需要创建大量的启动脚本。使用鼠标从本指南复制文本并粘贴到文本编辑器中是一个非常节省时间的工具。
插入并挂载标记为“启动盘”的软盘。
bash# mount /dev/fd0 /mnt bash# cd /mnt/boot/grub |
使用您最喜欢的文本编辑器创建以下文件,并将其保存为 /mnt/boot/grub/menu.lst
default 0 timeout 3 title Pocket Linux Boot Disk kernel (fd0)/boot/vmlinuz root=/dev/fd0 load_ramdisk=1 prompt_ramdisk=1 |
从 ftp://ftp.cistron.nl/pub/people/miquels/software/ 下载最新的 sysvinit 源代码
bash# cd /usr/src/sysvinit-2.85/src bash# make CC="gcc -mcpu=i386" bash# cp halt init shutdown ~/staging/sbin bash# ln -s halt ~/staging/sbin/reboot bash# ln -s init ~/staging/sbin/telinit bash# mknod ~/staging/dev/initctl p |
![]() | 为了提高速度,我们跳过了检查库和剥离二进制文件的步骤。sysvinit 的库要求非常基本,并且 Makefile 被配置为自动剥离二进制文件。 |
使用文本编辑器创建以下文件并将其保存为~/staging/etc/inittab
# /etc/inittab - init daemon configuration file # # Default runlevel id:1:initdefault: # # System initialization si:S:sysinit:/etc/init.d/rc S # # Runlevel scripts r0:0:wait:/etc/init.d/rc 0 r1:1:respawn:/bin/sh r2:2:wait:/etc/init.d/rc 2 r3:3:wait:/etc/init.d/rc 3 r4:4:wait:/etc/init.d/rc 4 r5:5:wait:/etc/init.d/rc 5 r6:6:wait:/etc/init.d/rc 6 # # end of /etc/inittab |
使用文本编辑器创建以下文件并将其保存为~/staging/etc/init.d/rc
#!/bin/sh
#
# /etc/init.d/rc - runlevel change script
#
PATH=/sbin:/bin
SCRIPT_DIR="/etc/rc$1.d"
#
# Check that the rcN.d directory really exists.
if [ -d $SCRIPT_DIR ]; then
#
# Execute the kill scripts first.
for SCRIPT in $SCRIPT_DIR/K*; do
if [ -x $SCRIPT ]; then
$SCRIPT stop;
fi;
done;
#
# Do the Start scripts last.
for SCRIPT in $SCRIPT_DIR/S*; do
if [ -x $SCRIPT ]; then
$SCRIPT start;
fi;
done;
fi
#
# end of /etc/init.d/rc |
使文件可执行。
bash# chmod +x ~/staging/etc/init.d/rc |
添加了一个 case 语句,以允许脚本根据给定的命令行参数挂载或卸载本地文件系统。原始脚本包含在 case 语句的“start”部分中。“stop”部分是新的。
#!/bin/sh
#
# local_fs - check and mount local filesystems
#
PATH=/sbin:/bin ; export PATH
case $1 in
start)
echo "Checking local filesystem integrity."
fsck -ATCp
if [ $? -gt 1 ]; then
echo "Filesystem errors still exist! Manual intervention required."
/bin/sh
else
echo "Remounting / as read-write."
mount -n -o remount,rw /
echo -n > /etc/mtab
mount -f -o remount,rw /
echo "Mounting local filesystems."
mount -a -t nonfs,smbfs
fi
;;
stop)
echo "Unmounting local filesystems."
umount -a -r
;;
*)
echo "usage: $0 start|stop";
;;
esac
#
# end of local_fs |
使用文本编辑器创建以下脚本并将其保存为~/staging/etc/init.d/hostname
#!/bin/sh # # hostname - set the system name to the name stored in /etc/hostname # PATH=/sbin:/bin ; export PATH echo "Setting hostname." if [ -f /etc/hostname ]; then hostname $(cat /etc/hostname) else hostname gnu-linux fi # # end of hostname |
使用文本编辑器创建~/staging/etc/init.d/halt如下所示。
#!/bin/sh # # halt - halt the system # PATH=/sbin:/bin ; export PATH echo "Initiating system halt." halt # # end of /etc/init.d/halt |
创建以下脚本并将其保存为~/staging/etc/init.d/reboot
#!/bin/sh # # reboot - reboot the system # PATH=/sbin:/bin ; export PATH echo "Initiating system reboot." reboot # # end of /etc/init.d/reboot |
将所有脚本文件标记为可执行。
bash# chmod +x ~/staging/etc/init.d/* |
bash# cd ~/staging/etc bash# mkdir rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rcS.d bash# cd ~/staging/etc/rcS.d bash# ln -s ../init.d/local_fs S20local_fs bash# ln -s ../init.d/hostname S30hostname bash# cd ~/staging/etc/rc0.d bash# ln -s ../init.d/local_fs K10local_fs bash# ln -s ../init.d/halt K90halt bash# cd ~/staging/etc/rc6.d bash# ln -s ../init.d/local_fs K10local_fs bash# ln -s ../init.d/reboot K90reboot |