Subversion Repositories livecd

Rev

Rev 1 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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