Subversion Repositories livecd

Rev

Rev 214 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 beyerle@PS 1
#!/bin/bash
2
#
3
# halt          This file is executed by init when it goes into runlevel
4
#               0 (halt) or runlevel 6 (reboot). It kills all processes,
5
#               unmounts file systems and then either halts or reboots.
6
#
7
# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
8
#               Modified for RHS Linux by Damien Neil
9
#
10
 
11
#
12
# Modified for LiveCD (Urs Beyerle)
13
# - do not umount loop device
14
# - do not umount swap
15
# - do not umount /livecd/live/... 
16
# - run /livecd/live/bin/busybox reboot|poweroff at the very end
17
#
18
 
19
NOLOCALE=1
20
. /etc/init.d/functions
21
 
22
runcmd() {
23
   echo -n "$1 "
24
   shift
25
   if [ "$BOOTUP" = "color" ]; then
26
      $* && echo_success || echo_failure
27
   else
28
      $*
29
   fi
30
   echo
31
}
32
 
33
halt_get_remaining() {
34
	awk '$2 ~ /^\/$|^\/proc|^\/dev/{next}
35
	     $3 == "tmpfs" || $3 == "proc" {print $2 ; next}
36
	     /(^#|loopfs|autofs|sysfs|devfs|^none|^\/dev\/ram|^\/dev\/root)/ {next}
37
	     {print $2}' /proc/mounts
38
}
39
 
40
# See how we were called.
41
case "$0" in
42
   *halt)
43
	message=$"Halting system..."
44
	command="/sbin/halt"
45
	;;
46
   *reboot)
47
	message=$"Please stand by while rebooting the system..."
48
	command="/sbin/reboot"
49
	;;
50
   *)
51
	echo $"$0: call me as 'halt' or 'reboot' please!"
52
	exit 1
53
	;;
54
esac
55
case "$1" in
56
   *start)
57
   	;;
58
   *)
59
	echo $"Usage: $0 {start}"
60
	exit 1
61
	;;
62
esac
63
 
64
# Kill all processes.
65
[ "${BASH+bash}" = bash ] && enable kill
66
 
67
runcmd $"Sending all processes the TERM signal..." /sbin/killall5 -15
68
sleep 5
69
runcmd $"Sending all processes the KILL signal..."  /sbin/killall5 -9
70
 
71
# Write to wtmp file before unmounting /var
72
/sbin/halt -w
73
 
74
# Save mixer settings, here for lack of a better place.
75
grep -q "\(alsa\)" /proc/devices
76
if [ $? = 0 -a -x /usr/sbin/alsactl ]; then
77
   runcmd $"Saving mixer settings" alsactl store
78
fi
79
 
80
# Save random seed
81
touch /var/lib/random-seed
82
chmod 600 /var/lib/random-seed
83
runcmd $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
84
 
85
# Sync the system clock.
86
ARC=0
87
SRM=0
88
UTC=0
89
 
90
if [ -f /etc/sysconfig/clock ]; then
91
   . /etc/sysconfig/clock
92
 
93
   # convert old style clock config to new values
94
   if [ "${CLOCKMODE}" = "GMT" ]; then
95
      UTC=true
96
   elif [ "${CLOCKMODE}" = "ARC" ]; then
97
      ARC=true
98
   fi
99
fi
100
 
101
CLOCKDEF=""
102
CLOCKFLAGS="$CLOCKFLAGS --systohc"
103
 
104
case "$UTC" in
105
   yes|true)
106
	CLOCKFLAGS="$CLOCKFLAGS -u";
107
	CLOCKDEF="$CLOCKDEF (utc)";
108
	;;
109
   no|false)
110
	CLOCKFLAGS="$CLOCKFLAGS --localtime";
111
	CLOCKDEF="$CLOCKDEF (localtime)";
112
	;;
113
esac
114
 
115
case "$ARC" in
116
   yes|true)
117
	CLOCKFLAGS="$CLOCKFLAGS -A";
118
	CLOCKDEF="$CLOCKDEF (arc)";
119
	;;
120
esac
121
case "$SRM" in
122
   yes|true)
123
	CLOCKFLAGS="$CLOCKFLAGS -S";
124
	CLOCKDEF="$CLOCKDEF (srm)";
125
	;;
126
esac
127
 
128
runcmd $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
129
 
130
# Turn off swap, then unmount file systems. - not on LiveCD!
131
# [ -f /proc/swaps ] && SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`
132
# [ -n "$SWAPS" ] && runcmd $"Turning off swap: " swapoff $SWAPS
133
 
134
[ -x /sbin/quotaoff ] && runcmd $"Turning off quotas: " /sbin/quotaoff -aug
135
 
136
# Unmount file systems, killing processes if we have to.
137
# Unmount loopback stuff first
138
remaining=`awk '!/^#/ && $1 ~ /^\/dev\/lo_fake/ && $2 != "/" {print $2}' /proc/mounts`
139
devremaining=`awk '!/^#/ && $1 ~ /^\/dev\/lo_fake/ && $2 != "/" {print $1}' /proc/mounts`
140
[ -n "$remaining" ] && {
141
	sig=
142
	retry=3
143
	while [ -n "$remaining" -a "$retry" -gt 0 ]
144
	do
145
		if [ "$retry" -lt 3 ]; then
146
			runcmd $"Unmounting loopback filesystems (retry):" umount $remaining
147
		else
148
			runcmd $"Unmounting loopback filesystems: " umount $remaining
149
		fi
150
		for dev in $devremaining ; do
151
			losetup $dev > /dev/null 2>&1 && \
152
				runcmd $"Detaching loopback device $dev: " losetup -d $dev
153
		done
154
		remaining=`awk '!/^#/ && $1 ~ /^\/dev\/lo_fake/ && $2 != "/" {print $2}' /proc/mounts`
155
		devremaining=`awk '!/^#/ && $1 ~ /^\/dev\/lo_fake/ && $2 != "/" {print $1}' /proc/mounts`
156
		[ -z "$remaining" ] && break
157
		/sbin/fuser -k -m $sig $remaining >/dev/null
158
		sleep 5
159
		retry=$(($retry -1))
160
		sig=-9
161
	done
162
}
163
 
164
# Unmount RPC pipe file systems
165
sig=
166
retry=3
167
remaining=`awk '!/^#/ && $3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts`
168
 
169
while [ -n "$remaining" -a "$retry" -gt 0 ]
170
do
171
	if [ "$retry" -lt 3 ]; then
172
		runcmd $"Unmounting pipe file systems (retry): "  umount -f $remaining
173
	else
174
		runcmd $"Unmounting pipe file systems: "  umount -f $remaining
175
	fi
176
	sleep 2
177
	remaining=`awk '!/^#/ && $3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' /proc/mounts`
178
	[ -z "$remaining" ] && break
179
	/sbin/fuser -k -m $sig $remaining >/dev/null
180
	sleep 5
181
	retry=$(($retry-1))
182
	sig=-9
183
done
184
 
185
sig=
186
retry=3
187
remaining=`halt_get_remaining | grep -v "/livecd/live" | sort -r`
188
 
189
while [ -n "$remaining" -a "$retry" -gt 0 ]
190
do
191
	if [ "$retry" -lt 3 ]; then
192
		LANG=C runcmd $"Unmounting file systems (retry): "  umount -f $remaining
193
	else
194
		LANG=C runcmd $"Unmounting file systems: "  umount -f $remaining
195
	fi
196
	sleep 2
197
	remaining=`halt_get_remaining | grep -v "/livecd/live" | sort -r`
198
	[ -z "$remaining" ] && break
199
	/sbin/fuser -k -m $sig $remaining >/dev/null
200
	sleep 5
201
	retry=$(($retry-1))
202
	sig=-9
203
done
204
 
205
[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb
206
 
207
# remove the crash indicator flag
208
rm -f /.autofsck
209
 
210
# Try all file systems other than root and RAM disks, one last time.
211
mount |  awk '!/( \/ |^\/dev\/root|^\/dev\/ram| \/proc )/ { print $3 }' | \
212
  while read line; do
213
    umount -f $line
214
done
215
 
216
# Remount read only anything that's left mounted.
217
# echo $"Remounting remaining filesystems readonly" 
218
# -------- We don't do this on the LiveCD -----------
219
# mount | awk '{ print $3 }' | while read line; do
220
#     mount -n -o ro,remount $line
221
# done
222
 
223
# Now halt or reboot.
224
echo $"$message"
225
if [ -f /fastboot ]; then
226
 echo $"On the next boot fsck will be skipped."
227
elif [ -f /forcefsck ]; then
228
 echo $"On the next boot fsck will be forced."
229
fi
230
 
231
if [ "$command" = /sbin/halt -a -r /etc/ups/upsmon.conf -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
232
	. /etc/sysconfig/ups
233
	if [ "$SERVER" = "yes" -a "$MODEL" = "upsdrvctl" ] ; then
234
		/sbin/upsdrvctl shutdown
235
	elif [ "$SERVER" = "yes" -a "$MODEL" != "NONE" -a -n "$MODEL" -a -n "$DEVICE" ] ; then
236
		$MODEL $OPTIONS_HALT -k $DEVICE
237
	fi
238
fi
239
 
240
if [ -x /sbin/halt.local ]; then
241
   /sbin/halt.local
242
fi
243
 
244
# ------------------ LiveCD -------------------------
245
 
214 beyerleu 246
# dir of mounted live system: /$MOUNTDIR/live
247
MOUNTDIR=livecd
248
 
249
# source functions of liblinuxlive
250
. /$MOUNTDIR/live/liblinuxlive
251
 
252
# root on NFS?
253
NFSROOT=$( cmdline_value nfsroot )
254
 
255
# noeject set?
256
NOEJECT=$( cmdline_parameter noeject )
257
 
258
# eject CDROM 
259
# if CDROM is not on NFS and if noeject is not set
260
if [ ! $NFSROOT ] && [ ! $NOEJECT ]; then
261
    CDROM_DEV=$( grep /$MOUNTDIR/live/livecd /proc/mounts | awk '{print $1}' )
262
    echo -n "Ejecting CD-ROM $CDROM_DEV ... "
263
    eject $CDROM_DEV 2>/dev/null || eject
1 beyerle@PS 264
    echo
265
fi
266
 
267
if [ "${command##*/}" = "reboot" ]; then
268
  echo "Rebooting."; sleep 1
269
  /livecd/live/bin/busybox reboot 2>/dev/null
270
  reboot
271
else
272
  echo "Poweroff."; sleep 1  
273
  /livecd/live/bin/busybox poweroff 2>/dev/null
274
  poweroff
275
fi
276
 
277
# ------------------ LiveCD -------------------------
278
 
279
HALTARGS="-i -d"
280
[ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"
281
 
282
exec $command $HALTARGS