2 # Filename: grml-reboot
3 # Purpose: reboot grml system
4 # Authors: grml-team (grml.org)
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 export PATH=/sbin:/bin:/usr/bin:/usr/sbin
12 . /etc/grml/lsb-functions
17 exec >/dev/console 2>&1 </dev/console
23 NOPROMPT=${NOPROMPT:-false}
24 NOEJECT=${NOEJECT:-false}
25 CMDLINE="$(cat /proc/cmdline 2>/dev/null)"
27 # Check if we are running from a GRML-CD or HD
28 [ -e /etc/grml_cd ] || INSTALLED=true
30 # Assume that we don't want the eject+prompt stuff when running in one
31 # of the special modes:
32 grep -qe 'toram' -qe '2ram' -qe 'usb' -qe 'serial' \
33 -qe 'fromhd' -qe 'isofrom' -qe 'fromiso' -qe 'findiso' \
34 /proc/cmdline && INSTALLED=true
37 if ! $INSTALLED ; then
38 # new live-initramfs layout:
39 if [ -d /live/image ] ; then
40 CDROM="$(awk '/ \/live\/image /{print $1;exit 0;}' /proc/mounts)"
41 MOUNTPATH="/live/image"
42 else # old unionfs layout:
43 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
47 # try to remove only removable devices
49 if [ -n "$CDROM" ] ; then
50 DEVICE="${CDROM##/dev/}"
51 DEVICE="${DEVICE%%[0-9]*}"
53 if [ -n "$DEVICE" ] ; then
54 # is it a removable device?
55 [ "$(cat /sys/block/${DEVICE}/removable 2>/dev/null)" = "1" ] && REMOVABLE=true
57 readlink /sys/block/${DEVICE} 2>/dev/null | grep -q '/usb' && USB_DEVICE=true
58 $USB_DEVICE && USB_INFO="$(cat /sys/block/${DEVICE}/device/model 2>/dev/null)"
66 message="grml system will be halted..."
71 message="Preparing for reboot..."
75 echo "Usage: call this script as \"halt\" or \"reboot\" please.">&2
81 for i in $(seq 1 40) ; do
83 echo -n "$1.${NORMAL}"
88 # Disable kernel messages
89 echo "0" > /proc/sys/kernel/printk
91 # make sure halt/reboot commands are available even if
92 # someone is using shutdown command or nfsroot is used:
93 cat /sbin/halt /sbin/reboot /etc/init.d/$command /etc/init.d/ups-monitor \
94 /etc/apcupsd/powerfail >/dev/null 2>&1
96 # We may kill our network connection here before unmounting NFS. Bad luck.
97 if [ -d /sys/bus/pcmcia -a -x /sbin/pccardctl ] ; then
98 # make sure we don't lose any data, see issue219 for details
99 log_begin_msg "Syncing devices..."
100 sync ; log_end_msg $?
101 log_begin_msg "Shutting down PCMCIA devices..."
102 pccardctl eject >/dev/null 2>&1
107 log_begin_msg_nn "Running /etc/init.d/rc ${level}: "
108 /etc/init.d/rc $level 1>/dev/null 2>&1 &
113 # Remove all truecrypt mappings...
114 if [ -x /usr/sbin/truecrypt ] ; then
115 if grep -q truecrypt /proc/modules ; then
116 log_begin_msg "Unmapping truecrypt volumes."
117 MSG=$(truecrypt -d 2>1)
118 echo $MSG | grep "No volumes mapped" && eend 0
119 [ -z "$MSG" ] && eend 0 || eend 1
126 log_begin_msg_nn "Sending all processes the TERM signal: "
127 mysleep "$BLUE" ; log_end_msg $?
131 log_begin_msg_nn "Sending all processes the KILL signal: "
132 mysleep "$RED" ; log_end_msg $?
134 # Turn off swap, then unmount file systems.
135 log_begin_msg "Turning off swap."
136 swapoff -a >/dev/null 2>&1 ; log_end_msg $?
139 log_begin_msg "Deactivating udev:"
140 echo -n " ${GREEN}-${NORMAL} "
141 /etc/init.d/udev stop ; log_end_msg $?
143 # noprompt and noeject handling
145 *noprompt*) NOPROMPT=true ; ;;
146 *noeject*) NOEJECT=true ; ;;
148 [ -r /etc/noprompt ] && NOPROMPT=true
149 [ -r /etc/noeject ] && NOPROMPT=true && NOEJECT=true
151 # Turn on autoeject of CD-ROMs
153 for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done
154 for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done
157 # Umount file systems
158 log_begin_msg "Syncing local filesystems..."
159 sync && sleep 1 ; log_end_msg $?
161 log_begin_msg "Unmounting file systems."
163 # Be safe in case someone messed with /etc/mtab
164 if ! $INSTALLED ; then
166 ln -snf /proc/mounts /etc/mtab
169 # Free loopback devices if necessary, so we can unmount the host media
170 for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
172 umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 1>/dev/null 2>&1
177 log_begin_msg "Unmounting network filesystems"
178 umount -t nfs,nfs4,smbfs -alvf 2>/dev/null ; log_end_msg $?
180 NETDEVICES="$(/sbin/ifconfig | awk '/^[^ ]+/ {print $1}' | grep -v '^lo$')"
181 if [ -n "$NETDEVICES" ]; then
182 pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; }
183 killall dhclient dhclient3 2>/dev/null
184 log_begin_msg "Shutting down network device..."
185 for n in $NETDEVICES; do
186 echo "${SUBMSG} ${WHITE}$n${NORMAL}"
187 ifdown $n 1>/dev/null 2>&1
189 done ; log_end_msg $?
192 # For a harddisk installation: mount / ro
193 $INSTALLED && mount -n -o remount,ro / 2>/dev/null
195 # Prompt for removal of live system device
196 if ! $INSTALLED && ! $NOPROMPT ; then
197 # do not prompt for removal when running in grml2ram mode:
198 if ! mount | grep -qe 'on /cdrom' -qe 'on /live/image' ; then
199 echo "Live System not mounted, nothing to eject therefore."
201 [ -d "$MOUNTPATH" ] && umount -l "$MOUNTPATH"
202 if ! $NOEJECT && [ -n "$CDROM" ] ; then
203 $REMOVABLE && eject -p "$CDROM" 2>/dev/null
206 if $USB_DEVICE ; then
207 # if we do not have any information about the usb model then fallback to the device name instead
208 [ -n "$USB_INFO" ] || USB_INFO=" (${CDROM})"
209 read -s -p "${GREEN}Please remove the USB device${USB_INFO} and press ENTER to continue [auto 2 minutes].${NORMAL}" -t 120 a
211 [ -n "$CDROM" ] && CDROM=" (${CDROM})"
212 read -s -p "${GREEN}Please remove the live system${CDROM}, close the tray (if any) and press ENTER to continue [auto 2 minutes].${NORMAL}" -t 120 a
218 echo "$message" >/dev/console
220 # Finally halt or reboot
221 /etc/init.d/$command stop
223 ## END OF FILE #################################################################