Subversion Repositories livecd

Rev

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

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