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:
78 cat /sbin/halt /sbin/reboot >/dev/null
80 # We may kill our network connection here before unmounting NFS. Bad luck.
81 # poweroff pcmcia devices
82 if [ -d /sys/bus/pcmcia -a -x /sbin/pccardctl ] ; then
83 # make sure we don't lose any data, see issue219 for details
84 log_begin_msg "Syncing devices..."
86 log_begin_msg "Shutting down PCMCIA devices..."
87 pccardctl eject >/dev/null 2>&1
91 if [ -n "$INSTALLED" ] ; then
92 log_begin_msg_nn "Running /etc/init.d/rc ${level}: "
93 /etc/init.d/rc $level 1>/dev/null 2>&1 &
98 # Remove all truecrypt mappings...
99 if [ -x /usr/sbin/truecrypt ] ; then
100 if grep -q truecrypt /proc/modules ; then
101 log_begin_msg "Unmapping truecrypt volumes."
102 MSG=$(truecrypt -d 2>1)
103 echo $MSG | grep "No volumes mapped" && eend 0
104 [ -z "$MSG" ] && eend 0 || eend 1
111 log_begin_msg_nn "Sending all processes the TERM signal: "
112 mysleep "$BLUE" ; log_end_msg $?
116 log_begin_msg_nn "Sending all processes the KILL signal: "
117 mysleep "$RED" ; log_end_msg $?
119 # shut down network only when not booting via NFS:
120 if [ -z "$NFSBOOT" ] ; then
124 # Turn off swap, then unmount file systems.
125 log_begin_msg "Turning off swap."
126 swapoff -a >/dev/null 2>&1 ; log_end_msg $?
129 log_begin_msg "Deactivating udev:"
130 echo -n " ${GREEN}-${NORMAL} "
131 /etc/init.d/udev stop ; log_end_msg $?
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 # new live-initramfs layout:
152 if [ -d /live/image ] ; then
153 CDROM="$(awk '/ \/live\/image /{print $1;exit 0;}' /proc/mounts)"
154 else # old unionfs layout:
155 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
159 log_begin_msg "Syncing local filesystems..."
160 sync && sleep 1 ; log_end_msg $?
162 # Umount everything but root
163 log_begin_msg "Unmounting file systems."
165 # Be safe in case someone messed with /etc/mtab
166 if [ -z "$INSTALLED" ] ; then
168 ln -snf /proc/mounts /etc/mtab
171 # Free loopback devices if necessary, so we can unmount the host media
172 for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
174 umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 1>/dev/null 2>&1
178 # shut down network only when not booting via NFS:
179 if [ -n "$NFSBOOT" ] ; then
180 log_begin_msg "Booting via NFS detected"
181 echo -n " ${GREEN}-${NORMAL} Unmounting network filesystems"
182 umount -t nfs,nfs4,smbfs -alvf 2>/dev/null ; log_end_msg $?
184 echo -n " ${GREEN}-${NORMAL} Finally shutting down network..."
185 shutdown_network ; log_end_msg $?
188 # For a harddisk installation: mount / ro
189 [ -n "$INSTALLED" ] && mount -n -o remount,ro / 2>/dev/null
191 if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
192 # do not prompt for removal when running in grml2ram mode:
193 if ! mount | grep -qe 'on /cdrom' -qe 'on /live/image' ; then
194 echo "CD not mounted, nothing to eject therefore."
196 [ -d /live/image ] && umount -l /live/image
197 [ -d /cdrom ] && umount -l /cdrom
198 [ -n "$CDROM" -a -z "$NOEJECT" ] && eject -p "$CDROM" 2>/dev/null
200 read -s -p "${GREEN}Please remove CD, close cdrom drive and hit return [auto 2 minutes].${NORMAL}" -t 120 a
205 echo "$message" >/dev/console
207 # Finally halt or reboot
208 /etc/init.d/$command stop
210 ## END OF FILE #################################################################