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: Die Jun 26 00:08:30 CEST 2007 [mika]
8 ################################################################################
10 export PATH=/sbin:/bin:/usr/bin:/usr/sbin
13 . /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 # Assume that we don't want the eject+prompt stuff when running in one
24 # of the special modes:
25 grep -qe ' toram' -qe ' usb' -qe 'serial' -qe 'fromhd' /proc/cmdline && INSTALLED=yes
30 message="grml system will be halted..."
35 message="Preparing for reboot..."
39 echo "Usage: call this script as \"halt\" or \"reboot\" please.">&2
45 for i in `seq 1 40` ; do
47 echo -n "$1.${NORMAL}"
52 # Disable kernel messages
53 echo "0" > /proc/sys/kernel/printk
55 # We may kill our network connection here before unmounting NFS. Bad luck.
56 # poweroff pcmcia devices
57 if [ -d /sys/bus/pcmcia -a -x /sbin/pccardctl ] ; then
58 # make sure we don't lose any data, see issue219 for details
59 log_begin_msg "Syncing devices..."
61 log_begin_msg "Shutting down PCMCIA devices..."
62 pccardctl eject >/dev/null 2>&1
66 if [ -n "$INSTALLED" ] ; then
68 log_begin_msg_nn "Running /etc/init.d/rc ${level}: "
69 /etc/init.d/rc $level 1>/dev/null 2>&1 &
74 # Remove all truecrypt mappings...
75 if [ -x /usr/sbin/truecrypt ] ; then
76 if grep -q truecrypt /proc/modules ; then
77 log_begin_msg "Unmapping truecrypt volumes."
78 MSG=$(truecrypt -d 2>1)
79 echo $MSG | grep "No volumes mapped" && eend 0
80 [ -z "$MSG" ] && eend 0 || eend 1
87 log_begin_msg_nn "Sending all processes the TERM signal: "
88 mysleep "$BLUE" ; log_end_msg $?
92 log_begin_msg_nn "Sending all processes the KILL signal: "
93 mysleep "$RED" ; log_end_msg $?
96 if grep -q nfsdir /proc/cmdline ; then
97 log_begin_msg "Bootoption nfsdir detected, syncing filesystems."
98 sync && sleep 1 ; log_end_msg $?
100 # Unmount network filesystems first before shutting down network
101 NETMOUNTS="$(awk '{if($1~/:/){print $2}}' /proc/mounts 2>/dev/null)"
102 if [ -n "$NETMOUNTS" ]; then
103 log_begin_msg "Unmounting network filesystems."
104 umount -t nfs,nfs4,smbfs -alvf 2>/dev/null
107 NETDEVICES="$(/sbin/ifconfig | awk '/^[^ ]+/ {print $1}' | grep -v '^lo$')"
108 if [ -n "$NETDEVICES" ]; then
109 pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; }
110 killall dhclient dhclient3 2>/dev/null
111 log_begin_msg "Shutting down network device..."
112 for n in $NETDEVICES; do
113 echo "${SUBMSG} ${WHITE}$n${NORMAL}"
114 ifdown $n 1>/dev/null 2>&1
116 done ; log_end_msg $?
118 log_begin_msg "Syncing local filesystems..."
119 sync && sleep 1 ; log_end_msg $?
122 # Turn off swap, then unmount file systems.
123 log_begin_msg "Turning off swap."
124 swapoff -a >/dev/null 2>&1 ; log_end_msg $?
127 log_begin_msg "Deactivating udev:"
128 echo -n " ${GREEN}-${NORMAL} "
129 /etc/init.d/udev stop ; log_end_msg $?
130 [ -n $INSTALLED ] || mkdir -p /dev/pts
131 [ -n $INSTALLED ] || cp -a /GRML/dev/console /GRML/dev/tty[0-9]* /GRML/dev/loop* /GRML/dev/initctl /GRML/dev/null /dev/
132 [ -n $INSTALLED ] || ln -s /GRML/dev/* /dev/ 2>/dev/null
134 # Read in boot parameters
135 CMDLINE="`cat /proc/cmdline 2>/dev/null`"
136 # noprompt or noeject option given?
137 NOPROMPT=${NOPROMPT:-''}
138 case "$CMDLINE" in *noprompt*) NOPROMPT="yes"; ;; esac
139 NOEJECT=${NOEJECT:-''}
140 case "$CMDLINE" in *noeject*) NOEJECT="yes"; ;; esac
141 [ -r /etc/noprompt ] && NOPROMPT='yes'
142 [ -r /etc/noeject ] && NOPROMPT='yes' && NOEJECT='yes'
144 # Turn on autoeject of CD-ROMs
145 if [ -z "$NOEJECT" ]; then
146 for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done
147 for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done
150 # Detected cdrom device
151 if [ -z "$INSTALLED" ]; then
152 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
155 # Umount everything but root
156 log_begin_msg "Unmounting file systems."
158 # Be safe in case someone messed with /etc/mtab
159 if [ -z "$INSTALLED" ] ; then
161 ln -snf /proc/mounts /etc/mtab
164 # Free loopback devices if necessary, so we can unmount the host media
165 for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
167 # Remove remaining unused modules (Kernel 2.4)
168 # rmmod -a >/dev/null 2>&1
170 umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 1>/dev/null 2>&1
174 # For a harddisk installation: mount / ro
175 [ -n "$INSTALLED" ] && mount -n -o remount,ro / 2>/dev/null
177 if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
178 # do not prompt for removal when running in grml2ram mode:
179 if ! mount | grep -q 'on /cdrom ' ; then
180 echo "CD not mounted, nothing to eject therefore."
183 [ -n "$CDROM" -a -z "$NOEJECT" ] && eject -p "$CDROM" 2>/dev/null
185 read -s -p "${GREEN}Please remove CD, close cdrom drive and hit return [auto 2 minutes].${NORMAL}" -t 120 a
190 echo "$message" >/dev/console
192 # Finally halt or reboot
193 /etc/init.d/$command stop
195 ## END OF FILE #################################################################