summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bächler <thomas@archlinux.org>2006-12-16 22:03:29 +0000
committerThomas Bächler <thomas@archlinux.org>2006-12-16 22:03:29 +0000
commit9b58da29d7ce93bf3dc258a28d2fae00eb181f7e (patch)
tree6cdc8ad24e4146b32d31355a08ce6642337f9773
parent567edd5aa95d5728b50f9fff6d71c368a7f3966a (diff)
rc.sysinit, rc.shutdown:
- Code cleanup - Added "verbose" commandline option for debugging - Fixed #5968 - Fixed #4648
-rwxr-xr-xrc.shutdown17
-rwxr-xr-xrc.single4
-rwxr-xr-xrc.sysinit166
3 files changed, 116 insertions, 71 deletions
diff --git a/rc.shutdown b/rc.shutdown
index d0a094e..31c1fa3 100755
--- a/rc.shutdown
+++ b/rc.shutdown
@@ -76,12 +76,27 @@ stat_busy "Unmounting Filesystems"
/bin/umount -a
stat_done
+# Kill non-root encrypted partition mappings
+if [ -f /etc/crypttab -a -n "$(grep -v ^# /etc/crypttab | grep -v ^$)" ]; then
+ stat_busy "Deactivating encrypted volumes"
+ CS=/sbin/cryptsetup.static
+ do_uncrypt() {
+ if [ $# -ge 3 ]; then
+ $CS remove $1 >/dev/null 2>&1
+ fi
+ }
+ while read line; do
+ eval do_uncrypt "$line"
+ done </etc/crypttab
+ stat_done
+fi
+
if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
if [ -d /etc/lvm -a -x /sbin/lvm ]; then
/bin/mount -n -t sysfs none /sys 2>/dev/null
if [ -d /sys/block ]; then
stat_busy "Deactivating LVM2 groups"
- /sbin/lvm vgchange --ignorelockingfailure -a n
+ /sbin/lvm vgchange --ignorelockingfailure -an >/dev/null 2>&1
stat_done
umount /sys
fi
diff --git a/rc.single b/rc.single
index 00b7da6..edd20af 100755
--- a/rc.single
+++ b/rc.single
@@ -36,14 +36,14 @@ if [ "$PREVLEVEL" != "N" ]; then
if [ -x /etc/start_udev -a -d /sys/block ]; then
# We have a start_udev script and /sys appears to be mounted, use UDev
- status "Starting UDev Daemon" /etc/start_udev
+ status "Starting UDev Daemon" /etc/start_udev
if [ "`pidof -o %PPID /sbin/udevd`" ]; then
# If an old udevd is kicking around, we'll have to remount pts and shm
umount /dev/shm /dev/pts >/dev/null 2>&1
mount /dev/pts
mount /dev/shm
fi
- else
+ else
# Static /dev, our last resort
status "Using static /dev filesystem" /bin/true
fi
diff --git a/rc.sysinit b/rc.sysinit
index d5bcf10..dbe8068 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -16,16 +16,22 @@ printsep
# start up our mini logger until syslog takes over
/sbin/minilogd
+# mount /proc
+mount -n -t proc none /proc
+
# anything more serious than KERN_WARNING goes to the console
-/bin/dmesg -n 3
+# 'verbose' cmdline parameter enables more messages
+if grep -qw verbose /proc/cmdline; then
+ /bin/dmesg -n 8
+else
+ /bin/dmesg -n 3
+fi
-# mount /proc and /sys
-mount -n -t proc none /proc
-[ "`grep sysfs /proc/filesystems`" ] && mount -n -t sysfs none /sys
-
+# mount /sys
+grep -qw sysfs /proc/filesystems && mount -n -t sysfs none /sys
# mount usbfs
-/sbin/modprobe usbcore >/dev/null 2>&1
-[ "`grep usbfs /proc/filesystems`" ] && mount -n -t usbfs none /proc/bus/usb
+/sbin/modprobe usbcore >/dev/null 2>&1
+grep -qw usbfs /proc/filesystems && mount -n -t usbfs none /proc/bus/usb
if [ -x /etc/start_udev -a -d /sys/block ]; then
# We have a start_udev script and /sys appears to be mounted, use UDev
@@ -49,29 +55,31 @@ if ! [ "$load_modules" = "off" ]; then
fi
# run udev uevents
-if [ "`pidof -o %PPID /sbin/udevd`" ]; then
+if pidof -o %PPID /sbin/udevd >/dev/null; then
status "Loading UDev uevents" /etc/start_udev uevents
fi
# If using an encrypted root fs, we should find the root dev in the initrd
+# FIXME: obsoleted by initramfs and udev
if [ -e /initrd/dev/mapper/root ]; then
mkdir /dev/mapper 2>/dev/null
cp -a /initrd/dev/mapper/root /dev/mapper/root
fi
# If necessary, find md devices and manually assemble RAID arrays
-if [ -f /etc/mdadm.conf -a "`grep ^ARRAY /etc/mdadm.conf 2>/dev/null`" ]; then
+if [ -f /etc/mdadm.conf -a "$(grep ^ARRAY /etc/mdadm.conf 2>/dev/null)" ]; then
# udev won't create these md nodes, so we do it ourselves
- for dev in `grep ^ARRAY /etc/mdadm.conf | awk '{print $2}'`; do
- path=`echo $dev | sed 's|/[^/]*$||'`
- node=`echo $dev | sed "s|^$path/||"`
- minor=`echo $node | sed 's|^[^0-9]*||'`
+ for dev in $(grep ^ARRAY /etc/mdadm.conf | awk '{print $2}'); do
+ path=$(echo $dev | sed 's|/[^/]*$||')
+ node=$(echo $dev | sed "s|^$path/||")
+ minor=$(echo $node | sed 's|^[^0-9]*||')
[ ! -e $path/$node ] && /bin/mknod $path/$node b 9 $minor
done
status "Activating RAID arrays" /sbin/mdadm --assemble --scan
fi
# Unmount and free up the old initrd if it exists
+# FIXME: obsoleted by initramfs
if [ -f /initrd/linuxrc ]; then
stat_busy "Freeing memory from Initial Ramdisk"
umount /initrd 2>/dev/null
@@ -79,43 +87,6 @@ if [ -f /initrd/linuxrc ]; then
stat_done
fi
-# Set up non-root encrypted partition mappings
-if [ -f /etc/crypttab ]; then
- CS=/sbin/cryptsetup.static
- while read line; do
- [ "$line" = "" ] && continue
- [ "`echo $line | grep ^#`" ] && continue
- # remove redundant whitespace and split up tokens
- line=`echo $line | awk '{print $0}'`
- cname=`echo $line | cut -d' ' -f1`
- csrc=`echo $line | cut -d' ' -f2`
- cpass=`echo $line | cut -d' ' -f3`
- copts=`echo $line | cut -d' ' -f4-`
- [ "$cpass" = "" ] && continue
-
- action=create
- $CS isLuks $csrc 2>/dev/null && action=luksOpen
-
- if [ "`echo $cpass | grep \\\"`" ]; then
- # Trim off the quotes around the password string
- cpass2=`echo $cpass | sed -e 's|^"||' -e 's|"$||'`
- # For some fun reason, the parameter ordering varies for
- # LUKS and non-LUKS devices. Joy.
- if `$CS isLuks $csrc 2>/dev/null`; then
- echo "$cpass2" | $CS $copts luksOpen $csrc $cname >/dev/null
- else
- echo "$cpass2" | $CS $copts create $cname $csrc >/dev/null
- fi
- else
- if `$CS isLuks $csrc 2>/dev/null`; then
- $CS -d $cpass $copts luksOpen $csrc $cname >/dev/null
- else
- $CS -d $cpass $copts create $cname $csrc >/dev/null
- fi
- fi
- done </etc/crypttab
-fi
-
if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
if [ -x /sbin/lvm -a -d /sys/block ]; then
# Kernel 2.6.x, LVM2 groups
@@ -126,6 +97,46 @@ if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then
fi
fi
+# Set up non-root encrypted partition mappings
+if [ -f /etc/crypttab -a -n "$(grep -v ^# /etc/crypttab | grep -v ^$)" ]; then
+ stat_busy "Unlocking encrypted volumes"
+ csfailed=0
+ CS=/sbin/cryptsetup.static
+ do_crypt() {
+ if [ $# -ge 3 ]; then
+ cname="$1"
+ csrc="$2"
+ cpass="$3"
+ shift 3
+ copts="$*"
+ if [ "${cpass:0:1}" != "/" ]; then
+ # For some fun reason, the parameter ordering varies for
+ # LUKS and non-LUKS devices. Joy.
+ if $CS isLuks $csrc 2>/dev/null; then
+ echo "$cpass" | $CS $copts luksOpen $csrc $cname >/dev/null
+ else
+ echo "$cpass" | $CS $copts create $cname $csrc >/dev/null
+ fi
+ else
+ if $CS isLuks $csrc 2>/dev/null; then
+ $CS -d $cpass $copts luksOpen $csrc $cname >/dev/null
+ else
+ $CS -d $cpass $copts create $cname $csrc >/dev/null
+ fi
+ fi
+ [ $? -ne 0 ] && csfailed=1
+ fi
+ }
+ while read line; do
+ eval do_crypt "$line"
+ done </etc/crypttab
+ if [ $csfailed -eq 0 ]; then
+ stat_done
+ else
+ stat_fail
+ fi
+fi
+
status "Mounting Root Read-only" /bin/mount -n -o remount,ro /
FORCEFSCK=
@@ -134,25 +145,37 @@ NETFS="nonfs,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,nousbfs,noshfs,nofuse"
if [ -x /sbin/fsck ]; then
stat_busy "Checking Filesystems"
- if [ "`cat /proc/cmdline | grep quiet`" ]; then
+ if grep -qw quiet /proc/cmdline; then
/sbin/fsck -A -T -C -a -t $NETFS $FORCEFSCK >/dev/null 2>&1
else
/sbin/fsck -A -T -C -a -t $NETFS $FORCEFSCK 2>/dev/null
fi
- if [ $? -gt 1 ]; then
+ fsckret=$?
+ if [ ${fsckret} -gt 1 ]; then
stat_fail
- echo
- echo "***************** FILESYSTEM CHECK FAILED ****************"
- echo "* *"
- echo "* Please repair manually and reboot. Note that the root *"
- echo "* file system is currently mounted read-only. To remount *"
- echo "* it read-write type: mount -n -o remount,rw / *"
- echo "* When you exit the maintenance shell the system will *"
- echo "* reboot automatically. *"
- echo "* *"
- echo "************************************************************"
- echo
- /sbin/sulogin -p
+ if [ $((${fsckret}&2)) -eq 2 ]; then
+ echo
+ echo "********************** REBOOT REQUIRED *********************"
+ echo "* *"
+ echo "* The sytem will be rebooted automatically in 15 seconds. *"
+ echo "* *"
+ echo "************************************************************"
+ echo
+ sleep 15
+ else
+ echo
+ echo "***************** FILESYSTEM CHECK FAILED ****************"
+ echo "* *"
+ echo "* Please repair manually and reboot. Note that the root *"
+ echo "* file system is currently mounted read-only. To remount *"
+ echo "* it read-write type: mount -n -o remount,rw / *"
+ echo "* When you exit the maintenance shell the system will *"
+ echo "* reboot automatically. *"
+ echo "* *"
+ echo "************************************************************"
+ echo
+ /sbin/sulogin -p
+ fi
echo "Automatic reboot in progress..."
/bin/umount -a
/bin/mount -n -o remount,ro /
@@ -170,8 +193,15 @@ stat_busy "Mounting Local Filesystems"
# re-mount /proc , /sys and usbfs so they can be written to /etc/mtab
umount /proc/bus/usb
umount /proc && mount -t proc none /proc
-[ "`grep sysfs /proc/filesystems`" ] && umount /sys && mount -t sysfs none /sys
-[ "`grep usbfs /proc/filesystems`" ] && mount -t usbfs none /proc/bus/usb
+grep -qw sysfs /proc/filesystems && umount /sys && mount -t sysfs none /sys
+if grep -qw usbfs /proc/filesystems; then
+ # Some people use custom permissions for their usbfs
+ if grep -qw /proc/bus/usb /etc/fstab; then
+ mount /proc/bus/usb
+ else
+ mount -t usbfs none /proc/bus/usb
+ fi
+fi
# now mount all the local filesystems
/bin/mount -a -t $NETFS
stat_done
@@ -239,7 +269,7 @@ echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh
stat_done
# If locale is *.utf set console to Unicode mode
-if [ "`echo $LOCALE | /bin/grep -i utf`" ]; then
+if [ "$(echo $LOCALE | /bin/grep -i utf)" ]; then
stat_busy "Setting Consoles to UTF-8"
/usr/bin/kbd_mode -u
/usr/bin/dumpkeys | /bin/loadkeys --unicode
@@ -250,7 +280,7 @@ fi
if [ "$CONSOLEFONT" != "" ]; then
stat_busy "Loading Console Font: $CONSOLEFONT"
- for i in `seq 1 12`; do
+ for i in $(seq 1 12); do
if [ "$CONSOLEMAP" != "" ]; then
/usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C /dev/vc/${i}
else