mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

221 lines
7.3 KiB

  1. #!/bin/sh
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/package/base/sysfiles/system.init
  11. # ROCK Linux is Copyright (C) 1998 - 2004 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. #
  25. # Desc: System bootup and shutdown
  26. # Runlevel: 01 rcX rc1 rc2 rc3 rc4 rc5
  27. #
  28. main_begin
  29. block_begin(start, `Mounting /dev, /proc, /sys and /dev/shm.')
  30. check(`[ -e /dev/.devfsd ] || mount -n /dev')
  31. check(`mount -n /proc')
  32. mount -n /sys 2> /dev/null
  33. check(`mount -n /dev/shm')
  34. mount -n /dev/pts 2> /dev/null
  35. dnl
  36. if [ -f /etc/conf/hardware ] ; then
  37. . /etc/conf/hardware
  38. fi
  39. dmesg -n 3
  40. dnl
  41. block_split(`Configuring the /dev filesystem ...')
  42. check(`sh /etc/conf/devfs')
  43. dnl
  44. block_split(`Activating swap devices.')
  45. check(`swapon -a')
  46. dnl
  47. if [ -s /etc/lvmtab ]; then
  48. block_split(`Activating Volume Groups...')
  49. check(`/sbin/vgchange -ay')
  50. fi
  51. dnl
  52. block_split(`Checking file systems.')
  53. fsck -A -C -a ; fsckrc=$?
  54. if [ $(( $fsckrc & ~3 )) != 0 ] ; then
  55. echo " **"
  56. echo " ** Filesystem check failed (returncode=$fsckrc)."
  57. echo " ** Please repair the broken disk(s) manually."
  58. echo " **"
  59. sulogin -t 600 /dev/console
  60. umount -adrv ; /sbin/reboot -d -f
  61. while true ; do sleep 1 ; done
  62. elif [ $(( $fsckrc & 2 )) != 0 ] ; then
  63. for x in 10 9 8 7 6 5 4 3 2 ; do
  64. echo -en "\rSystem reboot in $x seconds ... "
  65. sleep 1
  66. done ; echo -e "\rSystem reboot now! "
  67. umount -adrv ; /sbin/reboot -d -f
  68. while true ; do sleep 1 ; done
  69. fi
  70. dnl
  71. block_split(`Mounting local file systems.')
  72. check(`mount -n -o remount,rw /')
  73. rootdev="/dev/$(ls -l /dev/root | sed 's,.* -> ,,')"
  74. check(`grep -v "^rootfs " /proc/mounts | \
  75. sed "s,^/dev/root ,$rootdev ," > /etc/mtab')
  76. check(`mount -a -t nocoda,nfs,devfs,proc,sysfs')
  77. dnl
  78. if [ "$HARDWARE_SETUP" = rockplug ]; then
  79. block_split(`Configuring hardware by activating rockplug.')
  80. echo "/sbin/rockplug" > /proc/sys/kernel/hotplug
  81. for file in /etc/rockplug/*.init ; do
  82. [ -f $file ] && $file start
  83. done
  84. else
  85. block_split(`Loading kernel modules and configuring the kernel.')
  86. check(`sh /etc/conf/kernel')
  87. fi
  88. dnl
  89. [ -f /etc/conf/clock ] && . /etc/conf/clock
  90. if [ "$clock_tz" = localtime ] ; then
  91. block_split(`Setting kernel clock to local time.')
  92. check(`hwclock --hctosys --localtime')
  93. fi
  94. if [ "$clock_rtc" ] ; then
  95. block_split(`Setting enhanced real time clock precision to $clock_rtc.')
  96. if [ -w /proc/sys/dev/rtc/max-user-freq ] ; then
  97. check(`echo $clock_rtc > /proc/sys/dev/rtc/max-user-freq')
  98. else
  99. echo "No /proc/sys/dev/rtc/max-user-freq found."
  100. fi
  101. fi
  102. dnl
  103. block_split(`Setting hostname to $(cat /etc/HOSTNAME).')
  104. check(`hostname "$(cat /etc/HOSTNAME)"')
  105. dnl
  106. block_split(`Refresh utmp, delete lock and tmp files and other stuff.')
  107. find /var/lock /var/run /tmp -mindepth 1 -print0 2> /dev/null | xargs --null rm -rf
  108. rm -f /etc/nologin /nologin /fastboot ; touch /var/run/utmp
  109. chmod 664 /var/run/utmp ; chown root:tty /var/run/utmp
  110. mkdir /tmp/.ICE-unix
  111. chmod 1777 /tmp/.ICE-unix
  112. dnl
  113. block_split(`Writing /var/log/boot.msg.')
  114. check(`dmesg > /var/log/boot.msg')
  115. dnl
  116. block_split(`Setting keyboard keymappings.')
  117. if [ -L /etc/default.keymap ] ; then
  118. mapfile=$(ls -l /etc/default.keymap | sed 's,.* -> ,,')
  119. check(`loadkeys $mapfile')
  120. elif [ -f /etc/default.keymap ] ; then
  121. check(`loadkeys /etc/default.keymap')
  122. else
  123. echo "No /etc/default.keymap found."
  124. fi
  125. dnl
  126. block_split(`Setting keyboard repeat rate and delay time.')
  127. kbd_rate=30; kbd_delay=250
  128. [ -f /etc/conf/kbd ] && . /etc/conf/kbd
  129. check(`D_prefix/bin/kbdrate -r $kbd_rate -d $kbd_delay < /dev/console')
  130. dnl
  131. block_split(`Setting console screen font.')
  132. if [ -L /etc/default.vcfont ] ; then
  133. fontfile=$(ls -l /etc/default.vcfont | sed 's,.* -> ,,')
  134. check(`setfont $fontfile')
  135. elif [ -f /etc/default.vcfont ] ; then
  136. check(`setfont /etc/default.vcfont')
  137. else
  138. echo "No /etc/default.vcfont found."
  139. fi
  140. dnl
  141. block_split(`Setting console terminal type and blank interval.')
  142. con_term=linux; con_blank=0
  143. [ -f /etc/conf/console ] && . /etc/conf/console
  144. check(`D_prefix/bin/setterm -term $con_term -blank $con_blank > /dev/console')
  145. dnl
  146. block_split(`Setting up loopback networking.')
  147. check(`ip link set lo up')
  148. check(`ip addr add 127.0.0.1/8 dev lo')
  149. check(`ip route add 127/8 dev lo')
  150. dnl
  151. block_split(`Setting overflow UID and GID kernel parameters.')
  152. check(`sysctl -w kernel.overflowuid=$(id -u nobody) > /dev/null')
  153. check(`sysctl -w kernel.overflowgid=$(id -g nobody) > /dev/null')
  154. dnl
  155. block_split(`Reading /etc/sysctl.conf file.')
  156. check(`sysctl -p')
  157. dnl
  158. block_split(`Initializing kernel random number generator.')
  159. if [ -e /var/state/random-seed ] ; then
  160. check(`cat /var/state/random-seed >/dev/urandom')
  161. fi
  162. block_end
  163. block_begin(stop, `Saving /var/log/init.msg and /var/log/boot.msg.')
  164. check(`touch /var/log/init.msg /var/log/boot.msg')
  165. check(`mv /var/log/init.msg /var/log/init.old')
  166. check(`mv /var/log/boot.msg /var/log/boot.old')
  167. block_split(`Writing a wtmp record.')
  168. if [ "$RUNLEVEL" = 0 ] ; then check(`halt -w')
  169. else check(`reboot -w') ; fi
  170. block_split(`Saving kernel random seed.')
  171. dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null
  172. dnl
  173. block_split(`Sending all processes a SIGTERM (15).')
  174. check(`killall5 -15') ; sleep 5
  175. block_split(`Sending all processes a 2nd SIGTERM (15).')
  176. check(`killall5 -15') ; sleep 5
  177. block_split(`Sending all processes a SIGKILL (9).')
  178. check(`killall5 -9') ; sleep 5
  179. dnl
  180. block_split(`Turning off swap devices.')
  181. check(`swapoff -a')
  182. sync ; sleep 1
  183. dnl
  184. block_split(`Remounting sync/ro and umount filesystems.')
  185. cut -d' ' -f-3 /etc/mtab /proc/mounts | sort -k2 -u -r | \
  186. while read dev dir fs ; do
  187. [ "$dir" = "/" ] && continue
  188. [ "$dir" = "/dev" ] && continue
  189. [ "$dir" = "/dev/shm" ] && continue
  190. [ "$dir" = "/proc" ] && continue
  191. [ "$dir" = "/sys" ] && continue
  192. [ "$dir" = "/tmp" ] && continue
  193. echo "Umounting $dev on $dir ($fs)."
  194. mount -o remount,sync $dir
  195. mount -o remount,ro $dir
  196. umount -d $dir
  197. done
  198. dnl
  199. block_split(`Unmounting remaining file systems.')
  200. grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab
  201. sync ; sleep 1 ; sync
  202. umount -vdnra -t nodevfs,proc,sysfs,shm
  203. mount -vn -o remount,sync /
  204. mount -vn -o remount,ro /
  205. sleep 1 ; sync ; sleep 1
  206. dnl
  207. block_split()
  208. command=""
  209. [ "$RUNLEVEL" = 0 ] && command=halt
  210. [ "$RUNLEVEL" = 6 ] && command=reboot
  211. if [ -n "$command" ] ; then
  212. echo "Going to $command the system ..."
  213. $command -d -f -i -p
  214. while true ; do sleep 1 ; done
  215. fi
  216. block_end
  217. main_end