X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=etc%2Finit.d%2Fgrml-reboot;h=c90fa8c3aad689dd5aa299432a9abb9a9fdd2cac;hb=899ef33564704d947c8c3abe95ec2455e1dcd43c;hp=5adc812a524fe4c188ac888210a3c4d8aa2b9e28;hpb=1038215c918fc3bcc695697321bcc638458bb9f6;p=grml-etc.git diff --git a/etc/init.d/grml-reboot b/etc/init.d/grml-reboot index 5adc812..c90fa8c 100755 --- a/etc/init.d/grml-reboot +++ b/etc/init.d/grml-reboot @@ -1,10 +1,9 @@ -#!/bin/sh +#!/bin/bash # Filename: grml-reboot # Purpose: reboot grml system -# Authors: grml-team (grml.org), (c) Klaus Knopper, (c) Michael Prokop +# Authors: grml-team (grml.org) # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Mon Jun 25 23:53:08 CEST 2007 [mika] ################################################################################ export PATH=/sbin:/bin:/usr/bin:/usr/sbin @@ -15,14 +14,52 @@ export PATH=/sbin:/bin:/usr/bin:/usr/sbin cd / # Clean input/output -exec >/dev/console 2>&1 "$CONSOLE" 2>&1 <"$CONSOLE" + +# default variables +INSTALLED=false +REMOVABLE=false +USB_DEVICE=false +NOPROMPT=${NOPROMPT:-false} +NOEJECT=${NOEJECT:-false} +CMDLINE="$(cat /proc/cmdline 2>/dev/null)" # Check if we are running from a GRML-CD or HD -INSTALLED="" -[ -e /GRML/etc/grml_cd ] || INSTALLED=yes +[ -e /etc/grml_cd ] || INSTALLED=true + # Assume that we don't want the eject+prompt stuff when running in one # of the special modes: -grep -qe ' toram' -qe ' usb' -qe 'serial' -qe 'fromhd' /proc/cmdline && INSTALLED=yes +grep -qe 'toram' -qe '2ram' -qe 'usb' -qe 'serial' \ + -qe 'fromhd' -qe 'isofrom' -qe 'fromiso' -qe 'findiso' \ + /proc/cmdline && INSTALLED=true + +# detect cdrom device +if ! $INSTALLED ; then + # new live-initramfs layout: + if [ -d /live/image ] ; then + CDROM="$(awk '/ \/live\/image /{print $1;exit 0;}' /proc/mounts)" + MOUNTPATH="/live/image" + else # old unionfs layout: + CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)" + MOUNTPATH="/cdrom" + fi + + # try to remove only removable devices + DEVICE="" + if [ -n "$CDROM" ] ; then + DEVICE="${CDROM##/dev/}" + [ -d /sys/block/${DEVICE} ] || DEVICE="${DEVICE%%[0-9]*}" + + if [ -n "$DEVICE" ] ; then + # is it a removable device? + [ "$(cat /sys/block/${DEVICE}/removable 2>/dev/null)" = "1" ] && REMOVABLE=true + # is it a usb device? + readlink /sys/block/${DEVICE} 2>/dev/null | grep -q '/usb' && USB_DEVICE=true + $USB_DEVICE && USB_INFO=" ($(cat /sys/block/${DEVICE}/device/model 2>/dev/null))" + fi + fi +fi case "$0" in *halt) @@ -42,8 +79,8 @@ case "$0" in esac mysleep() { - for i in `seq 1 40` ; do - usleep 75000 + for i in $(seq 1 30) ; do + sleep 0.1 echo -n "$1.${NORMAL}" done echo "" @@ -52,8 +89,12 @@ mysleep() { # Disable kernel messages echo "0" > /proc/sys/kernel/printk +# make sure halt/reboot commands are available even if +# someone is using shutdown command or nfsroot is used: +cat /sbin/halt /sbin/reboot /etc/init.d/$command /etc/init.d/ups-monitor \ + /etc/apcupsd/powerfail >/dev/null 2>&1 + # We may kill our network connection here before unmounting NFS. Bad luck. -# poweroff pcmcia devices if [ -d /sys/bus/pcmcia -a -x /sbin/pccardctl ] ; then # make sure we don't lose any data, see issue219 for details log_begin_msg "Syncing devices..." @@ -63,8 +104,7 @@ if [ -d /sys/bus/pcmcia -a -x /sbin/pccardctl ] ; then log_end_msg $? fi -if [ -n "$INSTALLED" ] ; then - echo +if $INSTALLED ; then log_begin_msg_nn "Running /etc/init.d/rc ${level}: " /etc/init.d/rc $level 1>/dev/null 2>&1 & mysleep "$GREEN" @@ -92,33 +132,6 @@ sleep 1 log_begin_msg_nn "Sending all processes the KILL signal: " mysleep "$RED" ; log_end_msg $? -# check for nfsdir -if grep -q nfsdir /proc/cmdline ; then - log_begin_msg "Bootoption nfsdir detected, syncing filesystems." - sync && sleep 1 ; log_end_msg $? -else - # Unmount network filesystems first before shutting down network - NETMOUNTS="$(awk '{if($1~/:/){print $2}}' /proc/mounts 2>/dev/null)" - if [ -n "$NETMOUNTS" ]; then - log_begin_msg "Unmounting network filesystems." - umount -t nfs,nfs4,smbfs -alvf 2>/dev/null - fi - # Shutdown network - NETDEVICES="$(/sbin/ifconfig | awk '/^[^ ]+/ {print $1}' | grep -v '^lo$')" - if [ -n "$NETDEVICES" ]; then - pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; } - killall dhclient dhclient3 2>/dev/null - log_begin_msg "Shutting down network device..." - for n in $NETDEVICES; do - echo "${SUBMSG} ${WHITE}$n${NORMAL}" - ifdown $n 1>/dev/null 2>&1 - ifconfig $n down - done ; log_end_msg $? - fi - log_begin_msg "Syncing local filesystems..." - sync && sleep 1 ; log_end_msg $? -fi - # Turn off swap, then unmount file systems. log_begin_msg "Turning off swap." swapoff -a >/dev/null 2>&1 ; log_end_msg $? @@ -127,36 +140,35 @@ swapoff -a >/dev/null 2>&1 ; log_end_msg $? log_begin_msg "Deactivating udev:" echo -n " ${GREEN}-${NORMAL} " /etc/init.d/udev stop ; log_end_msg $? -[ -n $INSTALLED ] || mkdir -p /dev/pts -[ -n $INSTALLED ] || cp -a /GRML/dev/console /GRML/dev/tty[0-9]* /GRML/dev/loop* /GRML/dev/initctl /GRML/dev/null /dev/ -[ -n $INSTALLED ] || ln -s /GRML/dev/* /dev/ 2>/dev/null - -# Read in boot parameters -CMDLINE="`cat /proc/cmdline 2>/dev/null`" -# noprompt or noeject option given? -NOPROMPT=${NOPROMPT:-''} -case "$CMDLINE" in *noprompt*) NOPROMPT="yes"; ;; esac -NOEJECT=${NOEJECT:-''} -case "$CMDLINE" in *noeject*) NOEJECT="yes"; ;; esac -[ -r /etc/noprompt ] && NOPROMPT='yes' -[ -r /etc/noeject ] && NOPROMPT='yes' && NOEJECT='yes' + +# noprompt and noeject handling +case "$CMDLINE" in + *noprompt*) NOPROMPT=true ; ;; + *noeject*) NOEJECT=true ; ;; +esac +[ -r /etc/noprompt ] && NOPROMPT=true +[ -r /etc/noeject ] && NOPROMPT=true && NOEJECT=true + +if [ "$(/usr/bin/imvirt 2>/dev/null)" != "Physical" ] ; then + log_begin_msg "System seems to be a virtual machine, assuming noprompt as default." + NOPROMPT=true + log_end_msg 0 +fi # Turn on autoeject of CD-ROMs -if [ -z "$NOEJECT" ]; then +if $NOEJECT ; then for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done fi -# Detected cdrom device -if [ -z "$INSTALLED" ]; then - CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)" -fi +# Umount file systems +log_begin_msg "Syncing local filesystems..." +sync && sleep 1 ; log_end_msg $? -# Umount everything but root log_begin_msg "Unmounting file systems." # Be safe in case someone messed with /etc/mtab -if [ -z "$INSTALLED" ] ; then +if ! $INSTALLED ; then rm -f /etc/mtab ln -snf /proc/mounts /etc/mtab fi @@ -164,25 +176,48 @@ fi # Free loopback devices if necessary, so we can unmount the host media for i in /dev/loop*; do losetup -d $i 2>/dev/null; done -# Remove remaining unused modules (Kernel 2.4) -# rmmod -a >/dev/null 2>&1 - -umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 2>/dev/null +umount -t notmpfs,nosysfs,noproc,nousbfs -adrvf 1>/dev/null 2>&1 log_end_msg 0 +# Network stuff +log_begin_msg "Unmounting network filesystems" +umount -t nfs,nfs4,smbfs -alvf 2>/dev/null ; log_end_msg $? + +NETDEVICES="$(/sbin/ifconfig | awk '/^[^ ]+/ {print $1}' | grep -v '^lo$')" +if [ -n "$NETDEVICES" ]; then + pidof pump >/dev/null 2>&1 && { pump -k ; sleep 2; } + killall dhclient dhclient3 2>/dev/null + log_begin_msg "Shutting down network device..." + for n in $NETDEVICES; do + echo "${SUBMSG} ${WHITE}$n${NORMAL}" + ifdown $n 1>/dev/null 2>&1 + ifconfig $n down + done ; log_end_msg $? +fi + # For a harddisk installation: mount / ro -[ -n "$INSTALLED" ] && mount -n -o remount,ro / 2>/dev/null +$INSTALLED && mount -n -o remount,ro / 2>/dev/null -if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then +# Prompt for removal of live system device +if ! $INSTALLED && ! $NOPROMPT ; then # do not prompt for removal when running in grml2ram mode: - if ! mount | grep -q 'on /cdrom ' ; then - echo "CD not mounted, nothing to eject therefore." + if ! mount | grep -qe 'on /cdrom' -qe 'on /live/image' ; then + echo "Live System not mounted, nothing to eject therefore." else - umount -l /cdrom - [ -n "$CDROM" -a -z "$NOEJECT" ] && eject -p "$CDROM" 2>/dev/null + [ -d "$MOUNTPATH" ] && umount -l "$MOUNTPATH" + if ! $NOEJECT && [ -n "$CDROM" ] ; then + $REMOVABLE && eject -p "$CDROM" 2>/dev/null + fi echo - read -s -p "${GREEN}Please remove CD, close cdrom drive and hit return [auto 2 minutes].${NORMAL}" -t 120 a + if $USB_DEVICE ; then + # if we do not have any information about the usb model then fallback to the device name instead + [ -n "$USB_INFO" ] || USB_INFO=" (${CDROM})" + read -s -p "${GREEN}Please remove the USB device${USB_INFO} and press ENTER to continue [auto 2 minutes].${NORMAL}" -t 120 a + else + [ -n "$CDROM" ] && CDROM=" (${CDROM})" + 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 + fi fi fi