ITEEDU

创建BSD启动脚本/etc/rc.d/rc.sysinit

/etc/HOSTNAME一定要创建,下面脚本中要用,要不然下面会出错。

-----------------------------/etc/rc.d/rc.sysinit----------------------------
#!/bin/sh
#以只读方式mount根系统
echo "Mounting root device read-only..."
/bin/mount -n -o remount,ro /
# 挂载swap交换区
echo "Initializing swap partitions..."
/sbin/swapon -a

# $?为命令返回值,1为错误。fsck检查文件系统错误则重启。
/sbin/fsck -A -a -C
if [ $? -gt 1 ]; then
   echo
   echo "ERROR:"
   echo "Your filesystem has been severely damaged. You can probably correct this"
   echo "problem by running e2fsck manually (eg. with the -v and -y options). After"
   echo "you logout, the system will reboot."
   echo
   PS1="(Repair filesystem)# "
   export PS1
   /sbin/sulogin
   /bin/umount -a -r
   /sbin/reboot -f
fi

# 以可读写方式重新mount文件系统。
echo "Remounting root device read-write..."
/bin/mount -n -v -o remount,rw /

echo "" >/etc/mtab
/bin/mount -f -o remount,rw /

# 挂载其它本地文件系统。
echo "Mounting other local filesystems..."
/bin/mount -a -v -tnonfs

# 设置主机名和域名。
echo "Setting up hostname..."
/bin/hostname `cat /etc/HOSTNAME |cut -d . -f1`
/bin/domainname `cat /etc/HOSTNAME |cut -d . -f2-`

# 随机数设备
if [ -f "/etc/random-seed" ]; then
  echo "Initializing random number generator..."
  /bin/cat /etc/random-seed >/dev/urandom
  rm -f /etc/random-seed
fi

echo "Loading keymap..."
/usr/bin/loadkeys -d

#设置系统时间
echo "Setting system time from hardware clock..."
/sbin/hwclock --hctosys --utc

#开启系统和内核日志服务
echo "Starting system and kernel log daemons...."
/usr/sbin/syslogd
/usr/sbin/klogd -c3

### Use modules? If yes, uncomment this:
# echo "Updating module dependencies..."
# /sbin/depmod -a
-------------------------end of /etc/rc.d/rc.sysinit-------------------------