Subversion Repositories livecd

Rev

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

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