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.

255 lines
8.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 - 2005 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 /proc, /sys, /dev/shm and /dev/pts.')
  30. mount -n /proc 2> /dev/null
  31. mount -n /sys 2> /dev/null
  32. check(`mount -n /dev/shm')
  33. mount -n /dev/pts 2> /dev/null
  34. dnl
  35. if [ -f /etc/conf/hardware ] ; then
  36. . /etc/conf/hardware
  37. fi
  38. dmesg -n 3
  39. dnl
  40. block_split(`Configuring the /dev filesystem ...')
  41. check(`sh /etc/conf/devfs')
  42. dnl
  43. block_split(`Activating swap devices.')
  44. check(`swapon -a')
  45. dnl
  46. if [ -s /etc/lvmtab ]; then
  47. block_split(`Activating Volume Groups...')
  48. check(`/sbin/vgchange -ay')
  49. fi
  50. dnl
  51. block_split(`Checking file systems.')
  52. fsck -A -C -a ; fsckrc=$?
  53. if [ $(( $fsckrc & ~3 )) != 0 ] ; then
  54. echo " **"
  55. echo " ** Filesystem check failed (returncode=$fsckrc)."
  56. echo " ** Please repair the broken disk(s) manually."
  57. echo " **"
  58. sulogin -t 600 /dev/console
  59. umount -adrv ; /sbin/reboot -d -f
  60. while true ; do sleep 1 ; done
  61. elif [ $(( $fsckrc & 2 )) != 0 ] ; then
  62. for x in 10 9 8 7 6 5 4 3 2 ; do
  63. echo -en "\rSystem reboot in $x seconds ... "
  64. sleep 1
  65. done ; echo -e "\rSystem reboot now! "
  66. umount -adrv ; /sbin/reboot -d -f
  67. while true ; do sleep 1 ; done
  68. fi
  69. dnl
  70. block_split(`Mounting local file systems.')
  71. check(`mount -n -o remount,rw /')
  72. rootdev="/dev/$(ls -l /dev/root 2> /dev/null | sed 's,.* -> ,,')"
  73. if [ "$rootdev" = "/dev/" ]; then
  74. rootdev="$( sed 's, ,\n,g' < /proc/cmdline | \
  75. grep ^root= | cut -f2- -d= )"
  76. [ -z "$rootdev" ] && rootdev="/dev/root"
  77. fi
  78. check(`grep -v "^rootfs " /proc/mounts | \
  79. sed "s,^/dev/root ,$rootdev ," > /etc/mtab')
  80. check(`mount -a -t nocoda,nfs,devfs,proc,sysfs')
  81. dnl
  82. block_split(`Refresh utmp, delete lock and tmp files and other stuff.')
  83. find /var/lock /var/run /tmp -mindepth 1 -print0 2> /dev/null | xargs --null rm -rf
  84. rm -f /etc/nologin /nologin /fastboot ; touch /var/run/utmp
  85. chmod 664 /var/run/utmp ; chown root:tty /var/run/utmp
  86. mkdir /tmp/.ICE-unix /var/lock/subsys
  87. chmod 1777 /tmp/.ICE-unix
  88. dnl
  89. case "$HARDWARE_SETUP" in
  90. rockplug)
  91. block_split(`Configuring hardware by activating rockplug.')
  92. echo "/sbin/rockplug" > /proc/sys/kernel/hotplug
  93. for file in /etc/rockplug/*.init; do
  94. [ -f $file ] && $file start
  95. done
  96. ;;
  97. hotplug)
  98. block_split(`Configuring hardware by activating hotplug.')
  99. echo "/sbin/hotplug" > /proc/sys/kernel/hotplug
  100. for RC in /etc/hotplug/*.rc; do
  101. echo -n "[$( basename ${RC%.rc} )] "
  102. check(`$RC start');
  103. done; echo
  104. touch /var/lock/subsys/hotplug
  105. ;;
  106. *)
  107. block_split(`Auto-load all modules at boot-time using hwscan.')
  108. check(`hwscan -- -V | sh')
  109. esac
  110. block_split(`Loading kernel modules and configuring the kernel.')
  111. check(`sh /etc/conf/kernel')
  112. dnl
  113. [ -f /etc/conf/clock ] && . /etc/conf/clock
  114. if [ "$clock_tz" = localtime ] ; then
  115. block_split(`Setting kernel clock to local time.')
  116. check(`hwclock --hctosys --localtime')
  117. fi
  118. if [ "$clock_rtc" ] ; then
  119. block_split(`Setting enhanced real time clock precision to $clock_rtc.')
  120. if [ -w /proc/sys/dev/rtc/max-user-freq ] ; then
  121. check(`echo $clock_rtc > /proc/sys/dev/rtc/max-user-freq')
  122. else
  123. echo "No /proc/sys/dev/rtc/max-user-freq found."
  124. fi
  125. fi
  126. dnl
  127. block_split(`Setting hostname to $(cat /etc/HOSTNAME).')
  128. check(`hostname "$(cat /etc/HOSTNAME)"')
  129. dnl
  130. block_split(`Writing /var/log/boot.msg.')
  131. check(`dmesg > /var/log/boot.msg')
  132. dnl
  133. block_split(`Setting keyboard keymappings.')
  134. if [ -L /etc/default.keymap ] ; then
  135. mapfile=$(ls -l /etc/default.keymap | sed 's,.* -> ,,')
  136. check(`loadkeys $mapfile')
  137. elif [ -f /etc/default.keymap ] ; then
  138. check(`loadkeys /etc/default.keymap')
  139. else
  140. echo "No /etc/default.keymap found."
  141. fi
  142. dnl
  143. block_split(`Setting keyboard repeat rate and delay time.')
  144. kbd_rate=30; kbd_delay=250
  145. [ -f /etc/conf/kbd ] && . /etc/conf/kbd
  146. check(`D_prefix/bin/kbdrate -r $kbd_rate -d $kbd_delay < /dev/console')
  147. dnl
  148. block_split(`Setting console screen font.')
  149. if [ -L /etc/default.vcfont ] ; then
  150. fontfile=$(ls -l /etc/default.vcfont | sed 's,.* -> ,,')
  151. check(`setfont $fontfile')
  152. elif [ -f /etc/default.vcfont ] ; then
  153. check(`setfont /etc/default.vcfont')
  154. else
  155. echo "No /etc/default.vcfont found."
  156. fi
  157. dnl
  158. block_split(`Setting console terminal type and blank interval.')
  159. con_term=linux; con_blank=0
  160. [ -f /etc/conf/console ] && . /etc/conf/console
  161. check(`D_prefix/bin/setterm -term $con_term -blank $con_blank > /dev/console')
  162. dnl
  163. block_split(`Setting up loopback networking.')
  164. check(`ip link set lo up')
  165. check(`ip addr add 127.0.0.1/8 dev lo')
  166. check(`ip route add 127/8 dev lo')
  167. dnl
  168. block_split(`Setting overflow UID and GID kernel parameters.')
  169. check(`sysctl -w kernel.overflowuid=$(id -u nobody) > /dev/null')
  170. check(`sysctl -w kernel.overflowgid=$(id -g nobody) > /dev/null')
  171. dnl
  172. block_split(`Reading /etc/sysctl.conf file.')
  173. check(`sysctl -p')
  174. dnl
  175. block_split(`Initializing kernel random number generator.')
  176. if [ -e /var/state/random-seed ] ; then
  177. check(`cat /var/state/random-seed >/dev/urandom')
  178. fi
  179. block_end
  180. block_begin(stop, `Saving /var/log/init.msg and /var/log/boot.msg.')
  181. check(`touch /var/log/init.msg /var/log/boot.msg')
  182. check(`mv /var/log/init.msg /var/log/init.old')
  183. check(`mv /var/log/boot.msg /var/log/boot.old')
  184. block_split(`Writing a wtmp record.')
  185. if [ "$RUNLEVEL" = 0 ] ; then check(`halt -w')
  186. else check(`reboot -w') ; fi
  187. block_split(`Saving kernel random seed.')
  188. dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null
  189. dnl
  190. case "$HARDWARE_SETUP" in
  191. rockplug)
  192. block_split(`Unconfiguring hardware by de-activating rockplug.')
  193. for file in /etc/rockplug/*.init; do
  194. [ -f $file ] && $file stop
  195. done
  196. ;;
  197. hotplug)
  198. block_split(`Unconfiguring hardware by de-activating hotplug.')
  199. for RC in /etc/hotplug/*.rc; do
  200. echo -n "[$( basename ${RC%.rc} )] "
  201. check(`$RC stop');
  202. done; echo
  203. rm -f /var/lock/subsys/hotplug
  204. ;;
  205. esac
  206. dnl
  207. block_split(`Sending all processes a SIGTERM (15).')
  208. check(`killall5 -15') ; sleep 5
  209. block_split(`Sending all processes a 2nd SIGTERM (15).')
  210. check(`killall5 -15') ; sleep 5
  211. block_split(`Sending all processes a SIGKILL (9).')
  212. check(`killall5 -9') ; sleep 5
  213. dnl
  214. block_split(`Turning off swap devices.')
  215. check(`swapoff -a')
  216. sync ; sleep 1
  217. dnl
  218. block_split(`Remounting sync/ro and umount filesystems.')
  219. cut -d' ' -f-3 /etc/mtab /proc/mounts | sort -k2 -u -r | \
  220. while read dev dir fs ; do
  221. [ "$dir" = "/" ] && continue
  222. [ "$dir" = "/dev" ] && continue
  223. [ "$dir" = "/dev/shm" ] && continue
  224. [ "$dir" = "/proc" ] && continue
  225. [ "$dir" = "/sys" ] && continue
  226. [ "$dir" = "/tmp" ] && continue
  227. echo "Umounting $dev on $dir ($fs)."
  228. mount -o remount,sync $dir
  229. mount -o remount,ro $dir
  230. umount -d $dir
  231. done
  232. dnl
  233. block_split(`Unmounting remaining file systems.')
  234. grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab
  235. sync ; sleep 1 ; sync
  236. umount -vdnra -t nodevfs,proc,sysfs,shm
  237. mount -vn -o remount,sync /
  238. mount -vn -o remount,ro /
  239. sleep 1 ; sync ; sleep 1
  240. dnl
  241. block_split()
  242. command=""
  243. [ "$RUNLEVEL" = 0 ] && command=halt
  244. [ "$RUNLEVEL" = 6 ] && command=reboot
  245. if [ -n "$command" ] ; then
  246. echo "Going to $command the system ..."
  247. $command -d -f -i -p
  248. while true ; do sleep 1 ; done
  249. fi
  250. block_end
  251. main_end