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: Tue May 20 01:28:38 CEST 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
27 # check for boot via NFS:
29 if grep -qe nfsroot -qe nfsdir /proc/cmdline ; then
36 message="grml system will be halted..."
41 message="Preparing for reboot..."
45 echo "Usage: call this script as \"halt\" or \"reboot\" please.">&2
51 for i in $(seq 1 40) ; do
53 echo -n "$1.${NORMAL}"
61 NETDEVICES="$(/sbin/ifconfig | awk '/^[^ ]+/ {print $1}' | grep -v '^lo$')"
62 if [ -n "$NETDEVICES" ]; then
63 pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; }
64 killall dhclient dhclient3 2>/dev/null
65 log_begin_msg "Shutting down network device..."
66 for n in $NETDEVICES; do
67 echo "${SUBMSG} ${WHITE}$n${NORMAL}"
68 ifdown $n 1>/dev/null 2>&1
74 # Disable kernel messages
75 echo "0" > /proc/sys/kernel/printk
77 # make sure halt/reboot commands are available even if
78 # someone is using shutdown command:
79 cat /sbin/halt /sbin/reboot >/dev/null
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 if [ -z "$INSTALLED" ] ; then
136 cp -a /GRML/dev/console /GRML/dev/tty[0-9]* /GRML/dev/loop* /GRML/dev/initctl /GRML/dev/null /dev/
137 ln -s /GRML/dev/* /dev/ 2>/dev/null
140 # Read in boot parameters
141 CMDLINE="$(cat /proc/cmdline 2>/dev/null)"
142 # noprompt or noeject option given?
143 NOPROMPT=${NOPROMPT:-''}
144 case "$CMDLINE" in *noprompt*) NOPROMPT="yes"; ;; esac
145 NOEJECT=${NOEJECT:-''}
146 case "$CMDLINE" in *noeject*) NOEJECT="yes"; ;; esac
147 [ -r /etc/noprompt ] && NOPROMPT='yes'
148 [ -r /etc/noeject ] && NOPROMPT='yes' && NOEJECT='yes'
150 # Turn on autoeject of CD-ROMs
151 if [ -z "$NOEJECT" ]; then
152 for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done
153 for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done
156 # Detected cdrom device
157 if [ -z "$INSTALLED" ]; then
158 # new live-initramfs layout:
159 if [ -d /live/image ] ; then
160 CDROM="$(awk '/ \/live\/image /{print $1;exit 0;}' /proc/mounts)"
161 else # old unionfs layout:
162 CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
166 log_begin_msg "Syncing local filesystems..."
167 sync && sleep 1 ; log_end_msg $?
169 # Umount everything but root
170 log_begin_msg "Unmounting file systems."
172 # Be safe in case someone messed with /etc/mtab
173 if [ -z "$INSTALLED" ] ; then
175 ln -snf /proc/mounts /etc/mtab
178 # Free loopback devices if necessary, so we can unmount the host media
179 for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
181 umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 1>/dev/null 2>&1
185 # shut down network only when not booting via NFS:
186 if [ -n "$NFSBOOT" ] ; then
187 log_begin_msg "Booting via NFS detected"
188 echo -n " ${GREEN}-${NORMAL} Unmounting network filesystems"
189 umount -t nfs,nfs4,smbfs -alvf 2>/dev/null ; log_end_msg $?
191 echo -n " ${GREEN}-${NORMAL} Finally shutting down network..."
192 shutdown_network ; log_end_msg $?
195 # For a harddisk installation: mount / ro
196 [ -n "$INSTALLED" ] && mount -n -o remount,ro / 2>/dev/null
198 if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
199 # do not prompt for removal when running in grml2ram mode:
200 if ! mount | grep -qe 'on /cdrom' -qe 'on /live/image' ; then
201 echo "CD not mounted, nothing to eject therefore."
203 [ -d /live/image ] && umount -l /live/image
204 [ -d /cdrom ] && umount -l /cdrom
205 [ -n "$CDROM" -a -z "$NOEJECT" ] && eject -p "$CDROM" 2>/dev/null
207 read -s -p "${GREEN}Please remove CD, close cdrom drive and hit return [auto 2 minutes].${NORMAL}" -t 120 a
212 echo "$message" >/dev/console
214 # Finally halt or reboot
215 /etc/init.d/$command stop
217 ## END OF FILE #################################################################