学习啦 > 学习电脑 > 操作系统 > Linux教程 > 创建BSD启动脚本/etc/rc.d/rc.sysinit

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

时间: 若木635 分享

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

学习啦在线学习网   创建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-------------------------

75548