Rev 1 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#!/bin/bash## halt This file is executed by init when it goes into runlevel# 0 (halt) or runlevel 6 (reboot). It kills all processes,# unmounts file systems and then either halts or reboots.## Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org># Modified for RHS Linux by Damien Neil### Modified for LiveCD (Urs Beyerle)# - do not umount loop device# - do not umount swap# - do not umount /livecd/live/...# - run /livecd/live/bin/busybox reboot|poweroff at the very end#NOLOCALE=1. /etc/init.d/functionsruncmd() {echo -n "$1 "shiftif [ "$BOOTUP" = "color" ]; then$* && echo_success || echo_failureelse$*fiecho}halt_get_remaining() {awk '$2 ~ /^\/$|^\/proc|^\/dev/{next}$3 == "tmpfs" || $3 == "proc" {print $2 ; next}/(^#|loopfs|autofs|sysfs|devfs|^none|^\/dev\/ram|^\/dev\/root)/ {next}{print $2}' /proc/mounts}# See how we were called.case "$0" in*halt)message=$"Halting system..."command="/sbin/halt";;*reboot)message=$"Please stand by while rebooting the system..."command="/sbin/reboot";;*)echo $"$0: call me as 'halt' or 'reboot' please!"exit 1;;esaccase "$1" in*start);;*)echo $"Usage: $0 {start}"exit 1;;esac# Kill all processes.[ "${BASH+bash}" = bash ] && enable killruncmd $"Sending all processes the TERM signal..." /sbin/killall5 -15sleep 5runcmd $"Sending all processes the KILL signal..." /sbin/killall5 -9# Write to wtmp file before unmounting /var/sbin/halt -w# Save mixer settings, here for lack of a better place.grep -q "\(alsa\)" /proc/devicesif [ $? = 0 -a -x /usr/sbin/alsactl ]; thenruncmd $"Saving mixer settings" alsactl storefi# Save random seedtouch /var/lib/random-seedchmod 600 /var/lib/random-seedruncmd $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null# Sync the system clock.ARC=0SRM=0UTC=0if [ -f /etc/sysconfig/clock ]; then. /etc/sysconfig/clock# convert old style clock config to new valuesif [ "${CLOCKMODE}" = "GMT" ]; thenUTC=trueelif [ "${CLOCKMODE}" = "ARC" ]; thenARC=truefifiCLOCKDEF=""CLOCKFLAGS="$CLOCKFLAGS --systohc"case "$UTC" inyes|true)CLOCKFLAGS="$CLOCKFLAGS -u";CLOCKDEF="$CLOCKDEF (utc)";;;no|false)CLOCKFLAGS="$CLOCKFLAGS --localtime";CLOCKDEF="$CLOCKDEF (localtime)";;;esaccase "$ARC" inyes|true)CLOCKFLAGS="$CLOCKFLAGS -A";CLOCKDEF="$CLOCKDEF (arc)";;;esaccase "$SRM" inyes|true)CLOCKFLAGS="$CLOCKFLAGS -S";CLOCKDEF="$CLOCKDEF (srm)";;;esacruncmd $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS# Turn off swap, then unmount file systems. - not on LiveCD!# [ -f /proc/swaps ] && SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`# [ -n "$SWAPS" ] && runcmd $"Turning off swap: " swapoff $SWAPS[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quotaoff -aug# Unmount file systems, killing processes if we have to.# Unmount loopback stuff firstremaining=`awk '!/^#/ && $1 ~ /^\/dev\/lo_fake/ && $2 != "/" {print $2}' /proc/mounts`devremaining=`awk '!/^#/ && $1 ~ /^\/dev\/lo_fake/ && $2 != "/" {print $1}' /proc/mounts`[ -n "$remaining" ] && {sig=retry=3while [ -n "$remaining" -a "$retry" -gt 0 ]doif [ "$retry" -lt 3 ]; thenruncmd $"Unmounting loopback filesystems (retry):" umount $remainingelseruncmd $"Unmounting loopback filesystems: " umount $remainingfifor dev in $devremaining ; dolosetup $dev > /dev/null 2>&1 && \runcmd $"Detaching loopback device $dev: " losetup -d $devdoneremaining=`awk '!/^#/ && $1 ~ /^\/dev\/lo_fake/ && $2 != "/" {print $2}' /proc/mounts`devremaining=`awk '!/^#/ && $1 ~ /^\/dev\/lo_fake/ && $2 != "/" {print $1}' /proc/mounts`[ -z "$remaining" ] && break/sbin/fuser -k -m $sig $remaining >/dev/nullsleep 5retry=$(($retry -1))sig=-9done}# Unmount RPC pipe file systemssig=retry=3remaining=`awk '!/^#/ && $3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts`while [ -n "$remaining" -a "$retry" -gt 0 ]doif [ "$retry" -lt 3 ]; thenruncmd $"Unmounting pipe file systems (retry): " umount -f $remainingelseruncmd $"Unmounting pipe file systems: " umount -f $remainingfisleep 2remaining=`awk '!/^#/ && $3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts`[ -z "$remaining" ] && break/sbin/fuser -k -m $sig $remaining >/dev/nullsleep 5retry=$(($retry-1))sig=-9donesig=retry=3remaining=`halt_get_remaining | grep -v "/livecd/live" | sort -r`while [ -n "$remaining" -a "$retry" -gt 0 ]doif [ "$retry" -lt 3 ]; thenLANG=C runcmd $"Unmounting file systems (retry): " umount -f $remainingelseLANG=C runcmd $"Unmounting file systems: " umount -f $remainingfisleep 2remaining=`halt_get_remaining | grep -v "/livecd/live" | sort -r`[ -z "$remaining" ] && break/sbin/fuser -k -m $sig $remaining >/dev/nullsleep 5retry=$(($retry-1))sig=-9done[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb# remove the crash indicator flagrm -f /.autofsck# Try all file systems other than root and RAM disks, one last time.mount | awk '!/( \/ |^\/dev\/root|^\/dev\/ram| \/proc )/ { print $3 }' | \while read line; doumount -f $linedone# Remount read only anything that's left mounted.# echo $"Remounting remaining filesystems readonly"# -------- We don't do this on the LiveCD -----------# mount | awk '{ print $3 }' | while read line; do# mount -n -o ro,remount $line# done# Now halt or reboot.echo $"$message"if [ -f /fastboot ]; thenecho $"On the next boot fsck will be skipped."elif [ -f /forcefsck ]; thenecho $"On the next boot fsck will be forced."fiif [ "$command" = /sbin/halt -a -r /etc/ups/upsmon.conf -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then. /etc/sysconfig/upsif [ "$SERVER" = "yes" -a "$MODEL" = "upsdrvctl" ] ; then/sbin/upsdrvctl shutdownelif [ "$SERVER" = "yes" -a "$MODEL" != "NONE" -a -n "$MODEL" -a -n "$DEVICE" ] ; then$MODEL $OPTIONS_HALT -k $DEVICEfifiif [ -x /sbin/halt.local ]; then/sbin/halt.localfi# ------------------ LiveCD -------------------------# dir of mounted live system: /$MOUNTDIR/liveMOUNTDIR=livecd# source functions of liblinuxlive. /$MOUNTDIR/live/liblinuxlive# root on NFS?NFSROOT=$( cmdline_value nfsroot )# noeject set?NOEJECT=$( cmdline_parameter noeject )# eject CDROM# if CDROM is not on NFS and if noeject is not setif [ ! $NFSROOT ] && [ ! $NOEJECT ]; thenCDROM_DEV=$( grep /$MOUNTDIR/live/livecd /proc/mounts | awk '{print $1}' )echo -n "Ejecting CD-ROM $CDROM_DEV ... "eject $CDROM_DEV 2>/dev/null || ejectechofiif [ "${command##*/}" = "reboot" ]; thenecho "Rebooting."; sleep 1/livecd/live/bin/busybox reboot 2>/dev/nullrebootelseecho "Poweroff."; sleep 1/livecd/live/bin/busybox poweroff 2>/dev/nullpowerofffi# ------------------ LiveCD -------------------------HALTARGS="-i -d"[ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"exec $command $HALTARGS