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 ################################################################################
9 export PATH=/sbin:/bin:/usr/bin:/usr/sbin
12 . /etc/grml/lsb-functions
17 exec >/dev/console 2>&1 </dev/console
19 # Check if we are running from a GRML-CD or HD
21 [ -e /etc/grml_cd ] || INSTALLED=yes
22 # Assume that we don't want the eject+prompt stuff when running in one
23 # of the special modes:
24 grep -qe ' toram' -qe ' usb' -qe 'serial' -qe 'fromhd' /proc/cmdline && INSTALLED=yes
26 # check for boot via NFS:
28 if grep -qe nfsroot -qe nfsdir /proc/cmdline ; then
35 message="grml system will be halted..."
40 message="Preparing for reboot..."
44 echo "Usage: call this script as \"halt\" or \"reboot\" please.">&2
50 for i in $(seq 1 40) ; do
52 echo -n "$1.${NORMAL}"
60 NETDEVICES="$(/sbin/ifconfig | awk '/^[^ ]+/ {print $1}' | grep -v '^lo$')"
61 if [ -n "$NETDEVICES" ]; then
62 pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; }
63 killall dhclient dhclient3 2>/dev/null
64 log_begin_msg "Shutting down network device..."
65 for n in $NETDEVICES; do
66 echo "${SUBMSG} ${WHITE}$n${NORMAL}"
67 ifdown $n 1>/dev/null 2>&1
73 # Disable kernel messages
74 echo "0" > /proc/sys/kernel/printk
76 # make sure halt/reboot commands are available even if
77 # someone is using shutdown command or nfsroot is used:
78 cat /sbin/halt /sbin/reboot /etc/init.d/$command /etc/init.d/ups-monitor \
79 /etc/apcupsd/powerfail >/dev/null 2>&1
81 # We may kill our network connection here before unmounting NFS. Bad luck.
82 # poweroff pcmcia devices
83 if [ -d /sys/bus/pcmcia -a -x /sbin/pccardctl ] ; then
84 # make sure we don't lose any data, see issue219 for details
85 log_begin_msg "Syncing devices..."
87 log_begin_msg "Shutting down PCMCIA devices..."
88 pccardctl eject >/dev/null 2>&1
92 if [ -n "$INSTALLED" ] ; then
93 log_begin_msg_nn "Running /etc/init.d/rc ${level}: "
94 /etc/init.d/rc $level 1>/dev/null 2>&1 &
99 # Remove all truecrypt mappings...
100 if [ -x /usr/sbin/truecrypt ] ; then
101 if grep -q truecrypt /proc/modules ; then
102 log_begin_msg "Unmapping truecrypt volumes."
103 MSG=$(truecrypt -d 2>1)
104 echo $MSG | grep "No volumes mapped" && eend 0
105 [ -z "$MSG" ] && eend 0 || eend 1
112 log_begin_msg_nn "Sending all processes the TERM signal: "
113 mysleep "$BLUE" ; log_end_msg $?
117 log_begin_msg_nn "Sending all processes the KILL signal: "
118 mysleep "$RED" ; log_end_msg $?
120 # shut down network only when not booting via NFS:
121 if [ -z "$NFSBOOT" ] ; then
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 $?
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 # new live-initramfs layout:
153 if [ -d /live/image ] ; then
154 CDROM="$(awk '/ \/live\/image /{print $1;exit 0;}' /proc/mounts)"
155 else # old unionfs layout:
156 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
160 log_begin_msg "Syncing local filesystems..."
161 sync && sleep 1 ; log_end_msg $?
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 umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 1>/dev/null 2>&1
179 # shut down network only when not booting via NFS:
180 if [ -n "$NFSBOOT" ] ; then
181 log_begin_msg "Booting via NFS detected"
182 echo -n " ${GREEN}-${NORMAL} Unmounting network filesystems"
183 umount -t nfs,nfs4,smbfs -alvf 2>/dev/null ; log_end_msg $?
185 echo -n " ${GREEN}-${NORMAL} Finally shutting down network..."
186 shutdown_network ; log_end_msg $?
189 # For a harddisk installation: mount / ro
190 [ -n "$INSTALLED" ] && mount -n -o remount,ro / 2>/dev/null
192 if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
193 # do not prompt for removal when running in grml2ram mode:
194 if ! mount | grep -qe 'on /cdrom' -qe 'on /live/image' ; then
195 echo "CD not mounted, nothing to eject therefore."
197 [ -d /live/image ] && umount -l /live/image
198 [ -d /cdrom ] && umount -l /cdrom
199 [ -n "$CDROM" -a -z "$NOEJECT" ] && eject -p "$CDROM" 2>/dev/null
201 read -s -p "${GREEN}Please remove the disc, close the tray (if any) and press ENTER to continue [auto 2 minutes].${NORMAL}" -t 120 a
206 echo "$message" >/dev/console
208 # Finally halt or reboot
209 /etc/init.d/$command stop
211 ## END OF FILE #################################################################