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
18 [ -c "$CONSOLE" ] && exec >"$CONSOLE" 2>&1 <"$CONSOLE"
24 NOPROMPT=${NOPROMPT:-false}
25 NOEJECT=${NOEJECT:-false}
26 CMDLINE="$(cat /proc/cmdline 2>/dev/null)"
28 # Check if we are running from a GRML-CD or HD
29 [ -e /etc/grml_cd ] || INSTALLED=true
31 # Assume that we don't want the eject+prompt stuff when running in one
32 # of the special modes:
33 grep -qe 'toram' -qe '2ram' -qe 'usb' -qe 'serial' \
34 -qe 'fromhd' -qe 'isofrom' -qe 'fromiso' -qe 'findiso' \
35 /proc/cmdline && INSTALLED=true
38 if ! $INSTALLED ; then
39 # new live-initramfs layout:
40 if [ -d /live/image ] ; then
41 CDROM="$(awk '/ \/live\/image /{print $1;exit 0;}' /proc/mounts)"
42 MOUNTPATH="/live/image"
43 else # old unionfs layout:
44 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
48 # try to remove only removable devices
50 if [ -n "$CDROM" ] ; then
51 DEVICE="${CDROM##/dev/}"
52 [ -d /sys/block/${DEVICE} ] || DEVICE="${DEVICE%%[0-9]*}"
54 if [ -n "$DEVICE" ] ; then
55 # is it a removable device?
56 [ "$(cat /sys/block/${DEVICE}/removable 2>/dev/null)" = "1" ] && REMOVABLE=true
58 readlink /sys/block/${DEVICE} 2>/dev/null | grep -q '/usb' && USB_DEVICE=true
59 $USB_DEVICE && USB_INFO=" ($(cat /sys/block/${DEVICE}/device/model 2>/dev/null))"
67 message="grml system will be halted..."
72 message="Preparing for reboot..."
76 echo "Usage: call this script as \"halt\" or \"reboot\" please.">&2
82 for i in $(seq 1 30) ; do
84 echo -n "$1.${NORMAL}"
89 # Disable kernel messages
90 echo "0" > /proc/sys/kernel/printk
92 # make sure halt/reboot commands are available even if
93 # someone is using shutdown command or nfsroot is used:
94 cat /sbin/halt /sbin/reboot /etc/init.d/$command /etc/init.d/ups-monitor \
95 /etc/apcupsd/powerfail >/dev/null 2>&1
97 # We may kill our network connection here before unmounting NFS. Bad luck.
98 if [ -d /sys/bus/pcmcia -a -x /sbin/pccardctl ] ; then
99 # make sure we don't lose any data, see issue219 for details
100 log_begin_msg "Syncing devices..."
101 sync ; log_end_msg $?
102 log_begin_msg "Shutting down PCMCIA devices..."
103 pccardctl eject >/dev/null 2>&1
108 log_begin_msg_nn "Running /etc/init.d/rc ${level}: "
109 /etc/init.d/rc $level 1>/dev/null 2>&1 &
114 # Remove all truecrypt mappings...
115 if [ -x /usr/sbin/truecrypt ] ; then
116 if grep -q truecrypt /proc/modules ; then
117 log_begin_msg "Unmapping truecrypt volumes."
118 MSG=$(truecrypt -d 2>1)
119 echo $MSG | grep "No volumes mapped" && eend 0
120 [ -z "$MSG" ] && eend 0 || eend 1
127 log_begin_msg_nn "Sending all processes the TERM signal: "
128 mysleep "$BLUE" ; log_end_msg $?
132 log_begin_msg_nn "Sending all processes the KILL signal: "
133 mysleep "$RED" ; log_end_msg $?
135 # Turn off swap, then unmount file systems.
136 log_begin_msg "Turning off swap."
137 swapoff -a >/dev/null 2>&1 ; log_end_msg $?
140 log_begin_msg "Deactivating udev:"
141 echo -n " ${GREEN}-${NORMAL} "
142 /etc/init.d/udev stop ; log_end_msg $?
144 # noprompt and noeject handling
146 *noprompt*) NOPROMPT=true ; ;;
147 *noeject*) NOEJECT=true ; ;;
149 [ -r /etc/noprompt ] && NOPROMPT=true
150 [ -r /etc/noeject ] && NOPROMPT=true && NOEJECT=true
152 if [ "$(/usr/bin/imvirt 2>/dev/null)" != "Physical" ] ; then
153 log_begin_msg "System seems to be a virtual machine, assuming noprompt as default."
158 # Turn on autoeject of CD-ROMs
160 for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done
161 for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done
164 # Umount file systems
165 log_begin_msg "Syncing local filesystems..."
166 sync && sleep 1 ; log_end_msg $?
168 log_begin_msg "Unmounting file systems."
170 # Be safe in case someone messed with /etc/mtab
171 if ! $INSTALLED ; then
173 ln -snf /proc/mounts /etc/mtab
176 # Free loopback devices if necessary, so we can unmount the host media
177 for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
179 umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 1>/dev/null 2>&1
184 log_begin_msg "Unmounting network filesystems"
185 umount -t nfs,nfs4,smbfs -alvf 2>/dev/null ; log_end_msg $?
187 NETDEVICES="$(/sbin/ifconfig | awk '/^[^ ]+/ {print $1}' | grep -v '^lo$')"
188 if [ -n "$NETDEVICES" ]; then
189 pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; }
190 killall dhclient dhclient3 2>/dev/null
191 log_begin_msg "Shutting down network device..."
192 for n in $NETDEVICES; do
193 echo "${SUBMSG} ${WHITE}$n${NORMAL}"
194 ifdown $n 1>/dev/null 2>&1
196 done ; log_end_msg $?
199 # For a harddisk installation: mount / ro
200 $INSTALLED && mount -n -o remount,ro / 2>/dev/null
202 # Prompt for removal of live system device
203 if ! $INSTALLED && ! $NOPROMPT ; then
204 # do not prompt for removal when running in grml2ram mode:
205 if ! mount | grep -qe 'on /cdrom' -qe 'on /live/image' ; then
206 echo "Live System not mounted, nothing to eject therefore."
208 [ -d "$MOUNTPATH" ] && umount -l "$MOUNTPATH"
209 if ! $NOEJECT && [ -n "$CDROM" ] ; then
210 $REMOVABLE && eject -p "$CDROM" 2>/dev/null
213 if $USB_DEVICE ; then
214 # if we do not have any information about the usb model then fallback to the device name instead
215 [ -n "$USB_INFO" ] || USB_INFO=" (${CDROM})"
216 read -s -p "${GREEN}Please remove the USB device${USB_INFO} and press ENTER to continue [auto 2 minutes].${NORMAL}" -t 120 a
218 [ -n "$CDROM" ] && CDROM=" (${CDROM})"
219 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
225 echo "$message" >/dev/console
227 # Finally halt or reboot
228 /etc/init.d/$command stop
230 ## END OF FILE #################################################################