萬盛學電腦網

 萬盛學電腦網 >> Linux教程 >> 創建BSD啟動腳本/etc/rc.d/rc.sysinit

創建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-------------------------

copyright © 萬盛學電腦網 all rights reserved