Subversion Repositories livecd

Rev

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

Rev 159 Rev 164
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
NOLOCALE=1
11
NOLOCALE=1
12
. /etc/init.d/functions
12
. /etc/init.d/functions
13
 
13
 
14
action() {
14
action() {
15
   echo -n "$1 "
15
   echo -n "$1 "
16
   shift
16
   shift
17
   if [ "$BOOTUP" = "color" ]; then
17
   if [ "$BOOTUP" = "color" ]; then
18
      "$@" && echo_success || echo_failure
18
      "$@" && echo_success || echo_failure
19
   else
19
   else
20
      "$@"
20
      "$@"
21
   fi
21
   fi
22
   echo
22
   echo
23
}
23
}
24
 
24
 
25
halt_crypto() {
25
halt_crypto() {
26
    fnval=0
26
    fnval=0
27
    while read dst src key; do
27
    while read dst src key; do
28
	[ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
28
	[ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
29
        if [ -b "/dev/mapper/$dst" ]; then
29
        if [ -b "/dev/mapper/$dst" ]; then
30
            if /sbin/dmsetup info "$dst" | grep -q '^Open count: *0$'; then
30
            if /sbin/dmsetup info "$dst" | grep -q '^Open count: *0$'; then
31
                /sbin/cryptsetup remove "$dst"
31
                /sbin/cryptsetup remove "$dst"
32
            else
32
            else
33
                fnval=1
33
                fnval=1
34
            fi
34
            fi
35
        fi
35
        fi
36
    done < /etc/crypttab
36
    done < /etc/crypttab
37
    return $fnval
37
    return $fnval
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
	kexec_command="/sbin/kexec"
49
	kexec_command="/sbin/kexec"
50
	;;
50
	;;
51
   *)
51
   *)
52
	echo $"$0: call me as 'halt' or 'reboot' please!"
52
	echo $"$0: call me as 'halt' or 'reboot' please!"
53
	exit 1
53
	exit 1
54
	;;
54
	;;
55
esac
55
esac
56
case "$1" in
56
case "$1" in
57
   *start)
57
   *start)
58
   	;;
58
   	;;
59
   *)
59
   *)
60
	echo $"Usage: $0 {start}"
60
	echo $"Usage: $0 {start}"
61
	exit 1
61
	exit 1
62
	;;
62
	;;
63
esac
63
esac
64
 
64
 
65
# Kill all processes.
65
# Kill all processes.
66
[ "${BASH+bash}" = bash ] && enable kill
66
[ "${BASH+bash}" = bash ] && enable kill
67
 
67
 
68
action $"Sending all processes the TERM signal..." /sbin/killall5 -15
68
action $"Sending all processes the TERM signal..." /sbin/killall5 -15
69
sleep 5
69
sleep 5
70
action $"Sending all processes the KILL signal..."  /sbin/killall5 -9
70
action $"Sending all processes the KILL signal..."  /sbin/killall5 -9
71
 
71
 
72
# Write to wtmp file before unmounting /var
72
# Write to wtmp file before unmounting /var
73
/sbin/halt -w
73
/sbin/halt -w
74
 
74
 
75
# Save mixer settings, here for lack of a better place.
75
# Save mixer settings, here for lack of a better place.
76
grep -q "\(alsa\)" /proc/devices
76
grep -q "\(alsa\)" /proc/devices
77
if [ $? = 0 -a -x /usr/sbin/alsactl ]; then
77
if [ $? = 0 -a -x /usr/sbin/alsactl ]; then
78
   action $"Saving mixer settings" alsactl store
78
   action $"Saving mixer settings" alsactl store
79
fi
79
fi
80
 
80
 
81
# Save random seed
81
# Save random seed
82
touch /var/lib/random-seed
82
touch /var/lib/random-seed
83
chmod 600 /var/lib/random-seed
83
chmod 600 /var/lib/random-seed
84
action $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
84
action $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
85
 
85
 
86
# Sync the system clock.
86
# Sync the system clock.
87
ARC=0
87
ARC=0
88
SRM=0
88
SRM=0
89
UTC=0
89
UTC=0
90
 
90
 
91
if [ -f /etc/sysconfig/clock ]; then
91
if [ -f /etc/sysconfig/clock ]; then
92
   . /etc/sysconfig/clock
92
   . /etc/sysconfig/clock
93
 
93
 
94
   # convert old style clock config to new values
94
   # convert old style clock config to new values
95
   if [ "${CLOCKMODE}" = "GMT" ]; then
95
   if [ "${CLOCKMODE}" = "GMT" ]; then
96
      UTC=true
96
      UTC=true
97
   elif [ "${CLOCKMODE}" = "ARC" ]; then
97
   elif [ "${CLOCKMODE}" = "ARC" ]; then
98
      ARC=true
98
      ARC=true
99
   fi
99
   fi
100
fi
100
fi
101
 
101
 
102
CLOCKDEF=""
102
CLOCKDEF=""
103
CLOCKFLAGS="$CLOCKFLAGS --systohc"
103
CLOCKFLAGS="$CLOCKFLAGS --systohc"
104
 
104
 
105
case "$UTC" in
105
case "$UTC" in
106
   yes|true)
106
   yes|true)
107
	CLOCKFLAGS="$CLOCKFLAGS -u";
107
	CLOCKFLAGS="$CLOCKFLAGS -u";
108
	CLOCKDEF="$CLOCKDEF (utc)";
108
	CLOCKDEF="$CLOCKDEF (utc)";
109
	;;
109
	;;
110
   no|false)
110
   no|false)
111
	CLOCKFLAGS="$CLOCKFLAGS --localtime";
111
	CLOCKFLAGS="$CLOCKFLAGS --localtime";
112
	CLOCKDEF="$CLOCKDEF (localtime)";
112
	CLOCKDEF="$CLOCKDEF (localtime)";
113
	;;
113
	;;
114
esac
114
esac
115
 
115
 
116
case "$ARC" in
116
case "$ARC" in
117
   yes|true)
117
   yes|true)
118
	CLOCKFLAGS="$CLOCKFLAGS -A";
118
	CLOCKFLAGS="$CLOCKFLAGS -A";
119
	CLOCKDEF="$CLOCKDEF (arc)";
119
	CLOCKDEF="$CLOCKDEF (arc)";
120
	;;
120
	;;
121
esac
121
esac
122
case "$SRM" in
122
case "$SRM" in
123
   yes|true)
123
   yes|true)
124
	CLOCKFLAGS="$CLOCKFLAGS -S";
124
	CLOCKFLAGS="$CLOCKFLAGS -S";
125
	CLOCKDEF="$CLOCKDEF (srm)";
125
	CLOCKDEF="$CLOCKDEF (srm)";
126
	;;
126
	;;
127
esac
127
esac
128
 
128
 
129
[ -x /sbin/hwclock ] && action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
129
[ -x /sbin/hwclock ] && action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
130
 
130
 
131
# Try to unmount tmpfs filesystems to avoid swapping them in.  Ignore failures.
131
# Try to unmount tmpfs filesystems to avoid swapping them in.  Ignore failures.
132
tmpfs=$(awk '$2 ~ /^\/($|proc|dev)/ { next; }
132
tmpfs=$(awk '$2 ~ /^\/($|proc|dev)/ { next; }
133
	     $3 == "tmpfs" { print $2; }' /proc/mounts | sort -r)
133
	     $3 == "tmpfs" { print $2; }' /proc/mounts | sort -r)
134
[ -n "$tmpfs" ] && fstab-decode umount $tmpfs 2>/dev/null
134
[ -n "$tmpfs" ] && fstab-decode umount $tmpfs 2>/dev/null
135
 
135
 
136
# Turn off swap, then unmount file systems.
136
# Turn off swap, then unmount file systems.
137
[ -f /proc/swaps ] && SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`
137
[ -f /proc/swaps ] && SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`
138
if [ -n "$SWAPS" ]; then
138
if [ -n "$SWAPS" ]; then
139
    action $"Turning off swap: " swapoff $SWAPS
139
    action $"Turning off swap: " swapoff $SWAPS
140
    for dst in $SWAPS; do
140
    for dst in $SWAPS; do
141
	if [[ "$dst" =~ "^/dev/mapper" ]] \
141
	if [[ "$dst" =~ "^/dev/mapper" ]] \
142
	    && [ "$(dmsetup status "$dst" | cut -d ' ' -f 3)" = crypt ]; then
142
	    && [ "$(dmsetup status "$dst" | cut -d ' ' -f 3)" = crypt ]; then
143
	    backdev=$(/sbin/cryptsetup status "$dst" \
143
	    backdev=$(/sbin/cryptsetup status "$dst" \
144
		| awk '$1 == "device:" { print $2 }')
144
		| awk '$1 == "device:" { print $2 }')
145
	    /sbin/cryptsetup remove "$dst"
145
	    /sbin/cryptsetup remove "$dst"
146
	    # Leave partition with a blank plain-text swap
146
	    # Leave partition with a blank plain-text swap
147
	    mkswap "$backdev" > /dev/null
147
	    mkswap "$backdev" > /dev/null
148
	fi
148
	fi
149
    done
149
    done
150
fi
150
fi
151
 
151
 
152
[ -x /sbin/quotaoff ] && action $"Turning off quotas: " /sbin/quotaoff -aug
152
[ -x /sbin/quotaoff ] && action $"Turning off quotas: " /sbin/quotaoff -aug
153
 
153
 
154
# Unmount file systems, killing processes if we have to.
154
# Unmount file systems, killing processes if we have to.
155
# Unmount loopback stuff first
155
# Unmount loopback stuff first
156
# __umount_loopback_loop
156
# __umount_loopback_loop
157
 
157
 
158
# Unmount RPC pipe file systems
158
# Unmount RPC pipe file systems
159
# __umount_loop '$3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' \
159
# __umount_loop '$3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' \
160
#    /proc/mounts \
160
#    /proc/mounts \
161
#    $"Unmounting pipe file systems: " \
161
#    $"Unmounting pipe file systems: " \
162
#    $"Unmounting pipe file systems (retry): " \
162
#    $"Unmounting pipe file systems (retry): " \
163
#    -f
163
#    -f
164
 
164
 
165
# LANG=C __umount_loop '$2 ~ /^\/$|^\/proc|^\/dev/{next}
165
# LANG=C __umount_loop '$2 ~ /^\/$|^\/proc|^\/dev/{next}
166
#	$3 == "tmpfs" || $3 == "proc" {print $2 ; next}
166
#	$3 == "tmpfs" || $3 == "proc" {print $2 ; next}
167
#	/(loopfs|autofs|nfs|cifs|smbfs|ncpfs|sysfs|^none|^\/dev\/ram|^\/dev\/root$)/ {next}
167
#	/(loopfs|autofs|nfs|cifs|smbfs|ncpfs|sysfs|^none|^\/dev\/ram|^\/dev\/root$)/ {next}
168
#	{print $2}' /proc/mounts \
168
#	{print $2}' /proc/mounts \
169
#	$"Unmounting file systems: " \
169
#	$"Unmounting file systems: " \
170
#	$"Unmounting file systems (retry): " \
170
#	$"Unmounting file systems (retry): " \
171
#	-f
171
#	-f
172
 
172
 
173
[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb
173
[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb
174
 
174
 
175
[ -f /etc/crypttab ] && \
175
[ -f /etc/crypttab ] && \
176
    LANG=C action $"Stopping disk encryption: " halt_crypto
176
    LANG=C action $"Stopping disk encryption: " halt_crypto
177
 
177
 
178
# remove the crash indicator flag
178
# remove the crash indicator flag
179
rm -f /.autofsck
179
rm -f /.autofsck
180
 
180
 
181
# Try all file systems other than root, essential filesystems and RAM disks,
181
# Try all file systems other than root, essential filesystems and RAM disks,
182
# one last time.
182
# one last time.
183
awk '$2 !~ /\/(|dev|proc|selinux)$/ && $1 !~ /^\/dev\/ram/ { print $2 }' \
183
awk '$2 !~ /\/(|dev|proc|selinux)$/ && $1 !~ /^\/dev\/ram/ { print $2 }' \
184
    /proc/mounts | grep -v "/livecd/" | sort -r | \
184
    /proc/mounts | grep -v "/livecd/" | sort -r | \
185
  while read line; do
185
  while read line; do
186
    fstab-decode umount -f $line
186
    fstab-decode umount -f $line
187
done
187
done
188
 
188
 
189
if [ -x /sbin/halt.local ]; then
189
if [ -x /sbin/halt.local ]; then
190
   /sbin/halt.local
190
   /sbin/halt.local
191
fi
191
fi
192
 
192
 
193
# Remount read only anything that's left mounted.
193
# Remount read only anything that's left mounted.
194
# echo $"Remounting remaining filesystems readonly"
194
# echo $"Remounting remaining filesystems readonly"
195
mount | awk '{ print $3 }' | while read line; do
195
mount | awk '{ print $3 }' | while read line; do
196
    fstab-decode mount -n -o ro,remount $line
196
    fstab-decode mount -n -o ro,remount $line
197
done
197
done
198
 
198
 
199
# Now halt or reboot.
199
# Now halt or reboot.
200
echo $"$message"
200
echo $"$message"
201
if [ -f /fastboot ]; then
201
if [ -f /fastboot ]; then
202
 echo $"On the next boot fsck will be skipped."
202
 echo $"On the next boot fsck will be skipped."
203
elif [ -f /forcefsck ]; then
203
elif [ -f /forcefsck ]; then
204
 echo $"On the next boot fsck will be forced."
204
 echo $"On the next boot fsck will be forced."
205
fi
205
fi
206
 
206
 
207
if [ "$command" = /sbin/halt -a -r /etc/ups/upsmon.conf -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
207
if [ "$command" = /sbin/halt -a -r /etc/ups/upsmon.conf -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
208
	. /etc/sysconfig/ups
208
	. /etc/sysconfig/ups
209
	if [ "$SERVER" = "yes" -a "$MODEL" = "upsdrvctl" ] ; then
209
	if [ "$SERVER" = "yes" -a "$MODEL" = "upsdrvctl" ] ; then
210
		/sbin/upsdrvctl shutdown
210
		/sbin/upsdrvctl shutdown
211
	elif [ "$SERVER" = "yes" -a "$MODEL" != "NONE" -a -n "$MODEL" -a -n "$DEVICE" ] ; then
211
	elif [ "$SERVER" = "yes" -a "$MODEL" != "NONE" -a -n "$MODEL" -a -n "$DEVICE" ] ; then
212
		$MODEL $OPTIONS_HALT -k $DEVICE
212
		$MODEL $OPTIONS_HALT -k $DEVICE
213
	fi
213
	fi
214
fi
214
fi
215
 
215
 
216
# ------------------ LiveCD -------------------------
216
# ------------------ LiveCD -------------------------
217
 
217
 
-
 
218
# dir of mounted live system: /$MOUNTDIR/live
-
 
219
MOUNTDIR=livecd
-
 
220
 
218
# eject CDROM (if CDROM is not on NFS)
221
# source functions of liblinuxlive
-
 
222
. /$MOUNTDIR/live/liblinuxlive
-
 
223
 
-
 
224
# root on NFS?
219
more /proc/cmdline | grep -q "nfsroot="
225
NFSROOT=$( cmdline_value nfsroot )
-
 
226
 
-
 
227
# noeject set?
-
 
228
NOEJECT=$( cmdline_parameter noeject )
-
 
229
 
-
 
230
# eject CDROM 
-
 
231
# if CDROM is not on NFS and if noeject is not set
220
if [ "$?" != "0" ]; then
232
if [ ! $NFSROOT ] && [ ! $NOEJECT ]; then
221
    echo "Ejecting CD-ROM ..."
233
    echo -n "Ejecting CD-ROM ... "
222
    # eject
-
 
223
    eject "/livecd/live`grep livecd/live/livecd /proc/mounts|awk '{print $1}'`"
234
    eject "/livecd/live`grep $MOUNTDIR/live/livecd /proc/mounts|awk '{print $1}'`"
224
    echo
235
    echo
225
fi
236
fi
226
 
237
 
227
if [ "${command##*/}" = "reboot" ]; then
238
if [ "${command##*/}" = "reboot" ]; then
228
  echo "Rebooting."; sleep 1
239
  echo "Rebooting."; sleep 1
229
  /livecd/live/bin/busybox reboot 2>/dev/null
240
  /livecd/live/bin/busybox reboot 2>/dev/null
230
  reboot
241
  reboot
231
else
242
else
232
  echo "Poweroff."; sleep 1  
243
  echo "Poweroff."; sleep 1  
233
  /livecd/live/bin/busybox poweroff 2>/dev/null
244
  /livecd/live/bin/busybox poweroff 2>/dev/null
234
  poweroff
245
  poweroff
235
fi
246
fi
236
 
247
 
237
# ------------------ LiveCD -------------------------
248
# ------------------ LiveCD -------------------------
238
 
249
 
239
# First, try kexec. If that fails, fall back to rebooting the old way.
250
# First, try kexec. If that fails, fall back to rebooting the old way.
240
[ -n "$kexec_command" ] && $kexec_command -e -x >& /dev/null
251
[ -n "$kexec_command" ] && $kexec_command -e -x >& /dev/null
241
 
252
 
242
HALTARGS="-d"
253
HALTARGS="-d"
243
[ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"
254
[ -f /poweroff -o ! -f /halt ] && HALTARGS="$HALTARGS -p"
244
 
255
 
245
exec $command $HALTARGS
256
exec $command $HALTARGS