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
67 log_begin_msg_nn "Running /etc/init.d/rc ${level}: "
68 /etc/init.d/rc $level 1>/dev/null 2>&1 &
73 # Remove all truecrypt mappings...
74 if [ -x /usr/sbin/truecrypt ] ; then
75 if grep -q truecrypt /proc/modules ; then
76 log_begin_msg "Unmapping truecrypt volumes."
77 MSG=$(truecrypt -d 2>1)
78 echo $MSG | grep "No volumes mapped" && eend 0
79 [ -z "$MSG" ] && eend 0 || eend 1
86 log_begin_msg_nn "Sending all processes the TERM signal: "
87 mysleep "$BLUE" ; log_end_msg $?
91 log_begin_msg_nn "Sending all processes the KILL signal: "
92 mysleep "$RED" ; log_end_msg $?
95 if grep -q nfsdir /proc/cmdline ; then
96 log_begin_msg "Bootoption nfsdir detected, syncing filesystems."
97 sync && sleep 1 ; log_end_msg $?
99 # Unmount network filesystems first before shutting down network
100 NETMOUNTS="$(awk '{if($1~/:/){print $2}}' /proc/mounts 2>/dev/null)"
101 if [ -n "$NETMOUNTS" ]; then
102 log_begin_msg "Unmounting network filesystems."
103 umount -t nfs,nfs4,smbfs -alvf 2>/dev/null
106 NETDEVICES="$(/sbin/ifconfig | awk '/^[^ ]+/ {print $1}' | grep -v '^lo$')"
107 if [ -n "$NETDEVICES" ]; then
108 pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; }
109 killall dhclient dhclient3 2>/dev/null
110 log_begin_msg "Shutting down network device..."
111 for n in $NETDEVICES; do
112 echo "${SUBMSG} ${WHITE}$n${NORMAL}"
113 ifdown $n 1>/dev/null 2>&1
115 done ; log_end_msg $?
117 log_begin_msg "Syncing local filesystems..."
118 sync && sleep 1 ; log_end_msg $?
121 # Turn off swap, then unmount file systems.
122 log_begin_msg "Turning off swap."
123 swapoff -a >/dev/null 2>&1 ; log_end_msg $?
126 log_begin_msg "Deactivating udev:"
127 echo -n " ${GREEN}-${NORMAL} "
128 /etc/init.d/udev stop ; log_end_msg $?
129 [ -n $INSTALLED ] || mkdir -p /dev/pts
130 [ -n $INSTALLED ] || cp -a /GRML/dev/console /GRML/dev/tty[0-9]* /GRML/dev/loop* /GRML/dev/initctl /GRML/dev/null /dev/
131 [ -n $INSTALLED ] || ln -s /GRML/dev/* /dev/ 2>/dev/null
133 # Read in boot parameters
134 CMDLINE="`cat /proc/cmdline 2>/dev/null`"
135 # noprompt or noeject option given?
136 NOPROMPT=${NOPROMPT:-''}
137 case "$CMDLINE" in *noprompt*) NOPROMPT="yes"; ;; esac
138 NOEJECT=${NOEJECT:-''}
139 case "$CMDLINE" in *noeject*) NOEJECT="yes"; ;; esac
140 [ -r /etc/noprompt ] && NOPROMPT='yes'
141 [ -r /etc/noeject ] && NOPROMPT='yes' && NOEJECT='yes'
143 # Turn on autoeject of CD-ROMs
144 if [ -z "$NOEJECT" ]; then
145 for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done
146 for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done
149 # Detected cdrom device
150 if [ -z "$INSTALLED" ]; then
151 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
154 # Umount everything but root
155 log_begin_msg "Unmounting file systems."
157 # Be safe in case someone messed with /etc/mtab
158 if [ -z "$INSTALLED" ] ; then
160 ln -snf /proc/mounts /etc/mtab
163 # Free loopback devices if necessary, so we can unmount the host media
164 for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
166 # Remove remaining unused modules (Kernel 2.4)
167 # rmmod -a >/dev/null 2>&1
169 umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 1>/dev/null 2>&1
173 # For a harddisk installation: mount / ro
174 [ -n "$INSTALLED" ] && mount -n -o remount,ro / 2>/dev/null
176 if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
177 # do not prompt for removal when running in grml2ram mode:
178 if ! mount | grep -q 'on /cdrom ' ; then
179 echo "CD not mounted, nothing to eject therefore."
182 [ -n "$CDROM" -a -z "$NOEJECT" ] && eject -p "$CDROM" 2>/dev/null
184 read -s -p "${GREEN}Please remove CD, close cdrom drive and hit return [auto 2 minutes].${NORMAL}" -t 120 a
189 echo "$message" >/dev/console
191 # Finally halt or reboot
192 /etc/init.d/$command stop
194 ## END OF FILE #################################################################