# $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
} ;/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