2 # Filename: grml-reboot
3 # Purpose: reboot grml system
4 # Authors: grml-team (grml.org), (c) Klaus Knopper, (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 # Latest change: Sam Sep 30 13:48:17 CEST 2006 [mika]
8 ################################################################################
10 PATH=/sbin:/bin:/usr/bin:/usr/sbin
13 [ -r /etc/grml_colors ] && . /etc/grml_colors
14 . /etc/grml/lsb-functions
18 exec >/dev/console 2>&1 </dev/console
20 # Check if we are running from a GRML-CD or HD
22 [ -e /GRML/etc/grml_cd ] || INSTALLED=yes
23 grep -q 'toram ' /proc/cmdline && INSTALLED=yes
29 ${YELLOW}GRML halted.${NORMAL}"
35 message="${GREEN}Preparing for reboot...${NORMAL}"
37 if [[ `readlink /sbin/reboot` == 'halt' ]] ; then
38 options="-d -i -f" # this is sysvinit of debian
40 options="-r -d -i -f" # this is sysvinit of grml
44 echo "$0: call this script as \"halt\" or \"reboot\" please!"
49 # No sync and no wtmp entry if running from CD
50 [ -n "$INSTALLED" ] || options="$options -n"
53 for i in `seq 1 40` ; do
55 echo -n "$1.${NORMAL}"
60 # Disable kernel messages
61 echo "0" > /proc/sys/kernel/printk
63 # We may kill our network connection here before unmounting NFS. Bad luck.
64 # poweroff pcmcia devices
65 if pidof cardmgr >/dev/null 2>&1; then
66 log_begin_msg "Shutting down PCMCIA devices..."
67 cardctl eject >/dev/null 2>&1 && sleep 3
68 killall cardmgr && sleep 3 ; log_end_msg $?
71 if [ -n "$INSTALLED" ] ; then
73 log_begin_msg_nn "Running /etc/init.d/rc ${level}: "
74 /etc/init.d/rc $level 1>/dev/null 2>&1 &
79 # Remove all truecrypt mappings...
80 if [ -x /usr/sbin/truecrypt ] ; then
81 if grep -q truecrypt /proc/modules ; then
82 log_begin_msg "Unmapping truecrypt volumes."
83 MSG=$(truecrypt -d 2>1)
84 echo $MSG | grep "No volumes mapped" && eend 0
85 [ -z "$MSG" ] && eend 0 || eend 1
92 log_begin_msg_nn "Sending all processes the TERM signal: "
93 mysleep "$BLUE" ; log_end_msg $?
97 log_begin_msg_nn "Sending all processes the KILL signal: "
98 mysleep "$RED" ; log_end_msg $?
101 if grep -q nfsdir /proc/cmdline ; then
102 log_begin_msg "Bootoption nfsdir detected, syncing filesystems"
103 sync && sleep 1 ; log_end_msg $?
105 # Unmount network filesystems first before shutting down network
106 NETMOUNTS="$(awk '{if($1~/:/){print $2}}' /proc/mounts 2>/dev/null)"
107 if [ -n "$NETMOUNTS" ]; then
108 log_begin_msg "Unmounting network filesystems."
109 umount -t nfs -arvf 2>/dev/null ; log_end_msg $?
112 NETDEVICES="$(awk -F: '/eth.:/{print $1}' /proc/net/dev 2>/dev/null)"
113 if [ -n "$NETDEVICES" ]; then
114 pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; }
115 log_begin_msg "Shutting down network device..."
116 for n in $NETDEVICES; do
117 echo "${SUBMSG} ${WHITE}$n${NORMAL}"
119 done ; log_end_msg $?
121 log_begin_msg "Syncing local filesystems..."
122 sync && sleep 1 ; log_end_msg $?
125 # Turn off swap, then unmount file systems.
126 log_begin_msg "Turning off swap."
127 swapoff -a >/dev/null 2>&1 ; log_end_msg $?
129 log_begin_msg "Deactivating udev:"
130 echo -n " ${GREEN}-${NORMAL} "
131 /etc/init.d/udev stop ; log_end_msg $?
132 [ -n $INSTALLED ] || mkdir -p /dev/pts
133 [ -n $INSTALLED ] || cp -a /GRML/dev/console /GRML/dev/tty[0-9]* /GRML/dev/loop* /GRML/dev/initctl /GRML/dev/null /dev/
134 [ -n $INSTALLED ] || ln -s /GRML/dev/* /dev/ 2>/dev/null
136 # Read in boot parameters
137 CMDLINE="`cat /proc/cmdline 2>/dev/null`"
138 # noprompt or noeject option given?
139 NOPROMPT=${NOPROMPT:-''}
140 case "$CMDLINE" in *noprompt*) NOPROMPT="yes"; ;; esac
142 NOEJECT=${NOEJECT:-''}
143 case "$CMDLINE" in *noeject*) NOEJECT="yes"; ;; esac
144 [ -r /etc/noprompt ] && NOPROMPT='yes'
145 [ -r /etc/noeject ] && NOPROMPT='yes' && NOEJECT='yes'
147 # No sync and no wtmp entry if running from CD
148 [ -n "$INSTALLED" ] || options="$options -n"
150 if [ -z "$NOEJECT" ]; then
151 # Turn on autoeject of CD-ROMs
152 for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done
153 for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done
156 # Turn on auto-eject feature of cdrom (2.2 kernel)
157 if [ -z "$INSTALLED" ]; then
158 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
159 # [ -n "$CDROM" ] && eject -s -a on "$CDROM" 2>/dev/null
162 # Note: This needs the static version of "init" which contains
163 # the "halt" command plus rmmod/umount calls
164 FINALCMD="/sbin/$command"
165 if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
166 [ -L /etc/init ] && rm -f /etc/init
167 [ -x /etc/init ] || cp -p /sbin/init /etc/
168 [ -x /etc/init ] && FINALCMD="/etc/init"
171 # Now umount everything but root
172 log_begin_msg "Unmounting file systems."
174 # Be safe in case someone messed with /etc/mtab
175 if [ -z "$INSTALLED" ] ; then
177 ln -snf /proc/mounts /etc/mtab
180 # Free loopback devices if necessary, so we can unmount the host media
181 for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
183 # Remove remaining unused modules (Kernel 2.4)
184 rmmod -a >/dev/null 2>&1
188 # For a harddisk installation: mount / ro
189 [ -n "$INSTALLED" ] && mount -n -o remount,ro / 2>/dev/null
191 if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
193 [ -n "$CDROM" -a -z "$NOEJECT" ] && eject -p "$CDROM" 2>/dev/null
195 echo "${CYAN}Please remove CD, close cdrom drive and hit return.${NORMAL}"
199 echo "$message" >/dev/console
201 # Now halt or reboot.
202 exec $FINALCMD $options >/dev/console 2>&1 </dev/console
204 ## END OF FILE #################################################################