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: Mon Mär 10 18:45:36 CET 2008 [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 /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 # make sure halt/reboot commands are available even if
56 # someone is using shutdown command:
57 cat /sbin/halt /sbin/reboot >/dev/null
59 # We may kill our network connection here before unmounting NFS. Bad luck.
60 # poweroff pcmcia devices
61 if [ -d /sys/bus/pcmcia -a -x /sbin/pccardctl ] ; then
62 # make sure we don't lose any data, see issue219 for details
63 log_begin_msg "Syncing devices..."
65 log_begin_msg "Shutting down PCMCIA devices..."
66 pccardctl eject >/dev/null 2>&1
70 if [ -n "$INSTALLED" ] ; then
71 log_begin_msg_nn "Running /etc/init.d/rc ${level}: "
72 /etc/init.d/rc $level 1>/dev/null 2>&1 &
77 # Remove all truecrypt mappings...
78 if [ -x /usr/sbin/truecrypt ] ; then
79 if grep -q truecrypt /proc/modules ; then
80 log_begin_msg "Unmapping truecrypt volumes."
81 MSG=$(truecrypt -d 2>1)
82 echo $MSG | grep "No volumes mapped" && eend 0
83 [ -z "$MSG" ] && eend 0 || eend 1
90 log_begin_msg_nn "Sending all processes the TERM signal: "
91 mysleep "$BLUE" ; log_end_msg $?
95 log_begin_msg_nn "Sending all processes the KILL signal: "
96 mysleep "$RED" ; log_end_msg $?
99 if grep -q nfsdir /proc/cmdline ; then
100 log_begin_msg "Bootoption nfsdir detected, syncing filesystems."
101 sync && sleep 1 ; log_end_msg $?
103 # Unmount network filesystems first before shutting down network
104 NETMOUNTS="$(awk '{if($1~/:/){print $2}}' /proc/mounts 2>/dev/null)"
105 if [ -n "$NETMOUNTS" ]; then
106 log_begin_msg "Unmounting network filesystems."
107 umount -t nfs,nfs4,smbfs -alvf 2>/dev/null
110 NETDEVICES="$(/sbin/ifconfig | awk '/^[^ ]+/ {print $1}' | grep -v '^lo$')"
111 if [ -n "$NETDEVICES" ]; then
112 pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; }
113 killall dhclient dhclient3 2>/dev/null
114 log_begin_msg "Shutting down network device..."
115 for n in $NETDEVICES; do
116 echo "${SUBMSG} ${WHITE}$n${NORMAL}"
117 ifdown $n 1>/dev/null 2>&1
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 $?
130 log_begin_msg "Deactivating udev:"
131 echo -n " ${GREEN}-${NORMAL} "
132 /etc/init.d/udev stop ; log_end_msg $?
133 [ -n $INSTALLED ] || mkdir -p /dev/pts
134 [ -n $INSTALLED ] || cp -a /GRML/dev/console /GRML/dev/tty[0-9]* /GRML/dev/loop* /GRML/dev/initctl /GRML/dev/null /dev/
135 [ -n $INSTALLED ] || ln -s /GRML/dev/* /dev/ 2>/dev/null
137 # Read in boot parameters
138 CMDLINE="`cat /proc/cmdline 2>/dev/null`"
139 # noprompt or noeject option given?
140 NOPROMPT=${NOPROMPT:-''}
141 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 # Turn on autoeject of CD-ROMs
148 if [ -z "$NOEJECT" ]; then
149 for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done
150 for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done
153 # Detected cdrom device
154 if [ -z "$INSTALLED" ]; then
155 # new live-initramfs layout:
156 if [ -d /live/image ] ; then
157 CDROM="$(awk '/ \/live\/image /{print $1;exit 0;}' /proc/mounts)"
158 else # old unionfs layout:
159 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
163 # Umount everything but root
164 log_begin_msg "Unmounting file systems."
166 # Be safe in case someone messed with /etc/mtab
167 if [ -z "$INSTALLED" ] ; then
169 ln -snf /proc/mounts /etc/mtab
172 # Free loopback devices if necessary, so we can unmount the host media
173 for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
175 # Remove remaining unused modules (Kernel 2.4)
176 # rmmod -a >/dev/null 2>&1
178 umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 1>/dev/null 2>&1
182 # For a harddisk installation: mount / ro
183 [ -n "$INSTALLED" ] && mount -n -o remount,ro / 2>/dev/null
185 if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
186 # do not prompt for removal when running in grml2ram mode:
187 if ! mount | grep -qe 'on /cdrom' -qe 'on /live/image' ; then
188 echo "CD not mounted, nothing to eject therefore."
190 [ -d /live/image ] && umount -l /live/image
191 [ -d /cdrom ] && umount -l /cdrom
192 [ -n "$CDROM" -a -z "$NOEJECT" ] && eject -p "$CDROM" 2>/dev/null
194 read -s -p "${GREEN}Please remove CD, close cdrom drive and hit return [auto 2 minutes].${NORMAL}" -t 120 a
199 echo "$message" >/dev/console
201 # Finally halt or reboot
202 /etc/init.d/$command stop
204 ## END OF FILE #################################################################