]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - rc.d/rc.sysinit
move mdadm and lvm init to functions for better maintainability
[projects/rc-scripts.git] / rc.d / rc.sysinit
index 6153c426ad2fafb6354029d54508534a3998b56c..bf98870e8c9b89c773959d47e430d86589e9e96b 100755 (executable)
@@ -37,7 +37,65 @@ fi
 CONSOLE_LOGLEVEL=1
 
 # Read functions
-. /etc/rc.d/init.d/functions
+. /lib/rc-scripts/functions
+
+modprobe_c_cache=""
+modprobe_c() {
+       if [ "$modprobe_c_cache" ]; then
+               echo "$modprobe_c_cache"
+               return
+       fi
+       modprobe_c_cache=$(modprobe -c)
+}
+
+# parse kernel cmdline
+# needs /proc mounted
+parse_cmdline() {
+       read cmdline < /proc/cmdline
+       local arg
+
+       for arg in $cmdline; do
+               case "$arg" in
+               pld.no-upstart)
+                       # default is set in /etc/sysconfig/system or detected in init.d/functions
+                       USE_UPSTART=no
+               ;;
+               noudev)
+                       # default is set in /etc/sysconfig/system
+                       START_UDEV=no
+               ;;
+               nomdadm)
+                       # default is set in /etc/sysconfig/system
+                       MDADM=no
+               ;;
+               nomultipath)
+                       # default is set in /etc/sysconfig/system
+                       DM_MULTIPATH=no
+               ;;
+               nousb)
+                       nousb=1
+               ;;
+               nohdparm)
+                       nohdparm=1
+               ;;
+               fastboot)
+                       fastboot=1
+               ;;
+               nopnp)
+                       nopnp=1
+               ;;
+               nomodules)
+                       nomodules=1
+               ;;
+               nofirewire)
+                       nofirewire=1
+               ;;
+               nofsck)
+                       nofsck=1
+               ;;
+               esac
+       done
+}
 
 disable_selinux() {
        local _d selinuxfs _t _r
@@ -72,7 +130,7 @@ relabel_selinux() {
 
 # Remove duplicate entries from mtab (for vserver guest use only)
 clean_vserver_mtab() {
-       :>/etc/mtab.clean
+       /etc/mtab.clean
        while read device mountpoint line; do
                grep -qs "$mountpoint" /etc/mtab.clean || \
                        echo "$device $mountpoint $line" >> /etc/mtab.clean
@@ -83,13 +141,19 @@ clean_vserver_mtab() {
 
 # Loads modules from /etc/modules, /etc/modules.X.Y and /etc/modules.X.Y.Z
 load_kernel_modules() {
+       local modules_file=$1
+       local _x _y _z v v1 old_IFS kernel kerneleq
        {
-               local _x _y v _z
-               read  _x _y v _z
+               read _x _y v _z
                old_IFS=$IFS
-               IFS='.'
+               # strip _* or -* from versions like: "2.6.25_vanilla-1", "2.6.25-1"
+               IFS='_-'
                set -- $v
+               v1=${1}
+               IFS='.'
+               set -- $v1
                IFS=$old_IFS
+
                kernel="$1.$2"
                kerneleq="$1.$2.$3"
        } < /proc/version
@@ -97,36 +161,183 @@ load_kernel_modules() {
        local module args
        # Loop over every line in modules file
        ( \
-               grep -hvE '^(#|[[:blank:]]*$)' /etc/modules /etc/modules.$kernel /etc/modules.$kerneleq 2>/dev/null
+               grep -hvE '^(#|[[:blank:]]*$)' /etc/$modules_file /etc/$modules_file.$kernel /etc/$modules_file.$kerneleq 2>/dev/null
                echo '' # make sure there is a LF at the end
        ) | while read module args; do
                [ -z "$module" ] && continue
                # strip comments
                args=${args%%#*}
-               modprobe -s $module -- $args
+               show "Loading %s kernel module(s)" "$module"
+               busy
+               modprobe -s $module -- $args && ok || fail
        done
 }
 
-# boot logging to /var/log/boot.msg. install showconsole package to get it.
-if [ -x /sbin/blogd ] && ! is_no "$RC_BOOTLOG"; then
+# launch repair shell
+# which after exiting will reboot
+repair_shell() {
+       local reason="$2"
+
+       # don't use '\n' in nls macro !
+       echo
+       echo
+       echo "$reason"
+       nls "*** Dropping you to a shell; the system will reboot"
+       nls "*** when you leave the shell."
+       echo
+
+       [ "$SELINUX" = "1" ] && disable_selinux
+       if ! is_no "$RUN_SULOGIN_ON_ERR"; then
+               /sbin/sulogin
+       else
+               /bin/sh
+       fi
+
+       run_cmd "Unmounting file systems" umount -a
+       run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
+       run_cmd "Automatic reboot in progress" reboot
+}
+
+check_root_fs() {
+       show "Checking root filesystem"; started
+       initlog -c "fsck -C -T -a $fsckoptions /"
+       rc=$?
+
+       # A return of 4 or higher means there were serious problems.
+       if [ $rc -gt 3 ]; then
+               [ -e /proc/splash ] && echo "verbose" > /proc/splash
+
+               PS1="$(nls '(Repair filesystem)# ')"; export PS1
+               repair_shell "$(nls '*** An error occurred during the file system check.')"
+
+       # A return of 2 or 3 means that filesystem was repaired but we need
+       # to reboot.
+       elif [ "$rc" = "2" -o "$rc" = "3" ]; then
+               [ -e /proc/splash ] && echo "verbose" > /proc/splash
+               echo
+               nls "*** Filesystem was repaired but system needs to be"
+               nls "*** rebooted before mounting it."
+               nls "*** REBOOTING ***"
+               echo
+
+               run_cmd "Unmounting file systems" umount -a
+               mount -n -o remount,ro /
+               run_cmd "Automatic reboot in progress" reboot
+       elif [ "$rc" = "1" ]; then
+               _RUN_QUOTACHECK=1
+       fi
+}
+
+# Add raid devices
+init_mdadm() {
+       if [ ! -x /sbin/mdadm -o ! -f /etc/mdadm.conf ]; then
+               return
+       fi
+
+       modprobe -s md
+       local rc=0
+       if [ -f /proc/mdstat ]; then
+               golvm=0
+
+               if grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf; then
+                       show "Starting up RAID devices"; busy
+                       /sbin/mdadm --assemble --scan --auto=yes
+                       rc=$?
+                       if [ "$rc" -eq 0 -o "$rc" -eq 2 ]; then
+                               # rc is used later, too so set sane value
+                               rc=0
+                               deltext; ok
+                               golvm=1
+                       else
+                               deltext; fail
+                       fi
+
+               fi
+
+               # A non-zero return means there were problems
+               if [ $rc -gt 0 ]; then
+                       [ -e /proc/splash ] && echo "verbose" > /proc/splash
+                       show "Starting up RAID devices"; fail
+
+                       PS1="$(nls '(RAID Repair)# ')"; export PS1
+                       repair_shell "$(nls '*** An error occurred during the RAID startup.')"
+               fi
+
+               # LVM on RAID (keep in sync with LVM init)
+               if [ "$golvm" -eq "1" ]; then
+                       if [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
+                               run_cmd "Scanning for LVM volume groups (on RAID)" /sbin/vgscan $lvmignorelocking
+                               run_cmd "Activating LVM volume groups (on RAID)" /sbin/vgchange -a y $lvmsysinit
+                               [ "$lvmversion" = "2" ] && /sbin/vgmknodes
+                       fi
+               fi
+               show "Starting up RAID devices"; ok
+       fi
+       return $rc
+}
+
+# Init LVM
+init_lvm() {
+       if [ ! -x /sbin/vgscan -o ! -x /sbin/vgchange ] && ! is_yes "$EVMS_LVM"; then
+               return
+       fi
+
+       if is_no "$LVM2"; then
+               lvmversion=$(LC_ALL=C /sbin/vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}')
+       else
+               lvmversion=2
+       fi
+
+       if [ "$lvmversion" = "1" ] ; then
+               modprobe -s lvm-mod
+               lvmignorelocking=""
+               lvmsysinit=""
+       elif [ "$lvmversion" = "2" ] ; then
+               modprobe -s dm-mod
+               lvmignorelocking="--ignorelockingfailure"
+               lvmsysinit="--sysinit"
+       else
+               modprobe -s lvm-mod
+               # device mapper (2.5+ and patched 2.4)
+               modprobe -s dm-mod
+               lvmignorelocking=""
+               lvmsysinit=""
+       fi
+
+       run_cmd "Scanning for LVM volume groups" /sbin/vgscan $lvmignorelocking
+       run_cmd "Activating LVM volume groups" /sbin/vgchange -a y $lvmsysinit
+       if [ "$lvmversion" = "2" ]; then
+               /sbin/vgmknodes $lvmignorelocking
+               # display VG statistics
+               /sbin/vgdisplay -s $lvmignorelocking
+       fi
+}
+
+# boot logging to /var/log/boot.log. install showconsole package to get it.
+if ! is_no "$RC_BOOTLOG" && [ -x /sbin/blogd ]; then
        RC_BOOTLOG=1
 else
        RC_BOOTLOG=
 fi
 
-if ! is_yes "$VSERVER" ; then
+if ! is_yes "$VSERVER"; then
        # we need /proc mounted before everything
-       is_fsmounted proc /proc || mount -n -o gid=17 -t proc /proc /proc
+       is_fsmounted proc /proc || mount -n /proc || mount -n -o gid=17,hidepid=2 -t proc /proc /proc
 
-       # Only read this once.
-       cmdline=$(cat /proc/cmdline)
+       parse_cmdline
+
+       if [ -d /run ]; then
+               is_fsmounted tmpfs /run || mount -n -t tmpfs run /run
+       fi
+
+       # Early sysctls
+       sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
 
        # sysfs is also needed before any other things (under kernel > 2.5)
-       if grep -q sysfs /proc/filesystems 2>/dev/null ; then
+       if grep -q sysfs /proc/filesystems 2>/dev/null; then
                is_fsmounted sysfs /sys || mount -n -o gid=17 -t sysfs sysfs /sys
-               if [ "$(kernelver)" -ge "002006014" ] && \
-                       grep -q securityfs /proc/filesystems 2>/dev/null ; then
-                               mount -n -o gid=17 -t securityfs securityfs /sys/kernel/security
+               if grep -q securityfs /proc/filesystems 2>/dev/null; then
+                       mount -n -o gid=17 -t securityfs securityfs /sys/kernel/security
                fi
        fi
 
@@ -151,7 +362,7 @@ if ! is_yes "$VSERVER" ; then
        fi
 
        # Disable splash when requested
-       [ -e /proc/splash ] && is_no "$BOOT_SPLASH" && echo "0" > /proc/splash
+       is_no "$BOOT_SPLASH" && [ -e /proc/splash ] && echo "0" > /proc/splash
 
        # Check SELinux status
        selinuxfs=$(awk '/ selinuxfs / { print $2 }' /proc/mounts 2> /dev/null)
@@ -186,7 +397,7 @@ fi
 
 # Set the hostname
 if [ -z "${HOSTNAME}" ]; then
-       show "$(nls 'Host:') $(hostname)" ; ok
+       show "$(nls 'Host:') $(hostname)"; ok
 else
        run_cmd "$(nls 'Host:') ${HOSTNAME}" hostname ${HOSTNAME}
 fi
@@ -204,12 +415,13 @@ if ! is_yes "$VSERVER"; then
                dmesg -n $CONSOLE_LOGLEVEL
        fi
 
-       if ! is_no "$START_UDEV"; then
-               if [ -x /sbin/start_udev ]; then
-                       /sbin/start_udev
-               elif [ -x /lib/firmware/firmware-loader.sh ]; then
-                       /sbin/sysctl -e -w kernel.hotplug=/lib/firmware/firmware-loader.sh
-               fi
+       if ! is_no "$START_UDEV" && [ -x /sbin/start_udev ] && [[ "$container" != lxc* ]]; then
+               is_fsmounted devtmpfs /dev || mount -n -t devtmpfs devtmpfs /dev
+               load_kernel_modules modules.preudev
+               /sbin/start_udev
+               use_upstart && [ -x /sbin/initctl ] && /sbin/initctl -q start udev
+       elif [ -x /lib/firmware/firmware-loader.sh ]; then
+               /sbin/sysctl -e -w kernel.hotplug=/lib/firmware/firmware-loader.sh > /dev/null 2>&1
        fi
 
        # Unmount the initrd, if necessary
@@ -224,83 +436,32 @@ if ! is_yes "$VSERVER"; then
                /sbin/blogd
        fi
 
-       # cpuset support (mount if not found in fstab - should be ^# excluded?)
-       if grep -q cgroup /proc/filesystems 2>/dev/null ; then
-               if ! grep -q cgroup /etc/fstab 2>/dev/null ; then
-                       mount -n -t cgroup none /dev/cpuset -o cpuset,noprefix
-                       [ $? -eq 0 ] && echo "/sbin/cpuset_release_agent" > /dev/cpuset/release_agent
-               fi
-       elif grep -q cpuset /proc/filesystems 2>/dev/null ; then
-               if ! grep -q cpuset /etc/fstab 2>/dev/null ; then
-                       mount -n -t cpuset none /dev/cpuset
-               fi
-       fi
-
        # Configure Linux kernel (initial configuration, some required modules still
        # may be missing).
        sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
 
-       # Set the system clock.
-       ARC=0
-       SRM=0
-       UTC=0
-
-       if [ -f /etc/sysconfig/clock ]; then
-               . /etc/sysconfig/clock
-
-               # convert old style clock config to new values
-               if [ "${CLOCKMODE}" = "GMT" ]; then
-                       UTC=true
-               elif [ "${CLOCKMODE}" = "ARC" ]; then
-                       ARC=true
-               fi
-       fi
-
-       if grep "system serial" /proc/cpuinfo 2>/dev/null | grep -q MILO 2>/dev/null ; then
-               ARC=true
-       fi
-
-       CLOCKDEF=""
-       CLOCKFLAGS="--hctosys"
-
-       if is_yes "$UTC" ; then
-               CLOCKFLAGS="$CLOCKFLAGS --utc"
-               CLOCKDEF="$CLOCKDEF (utc)"
-       else
-               CLOCKFLAGS="$CLOCKFLAGS --localtime"
-               CLOCKDEF="$CLOCKDEF (local)"
-       fi
-
-       if is_yes "$ARC" ; then
-               CLOCKFLAGS="$CLOCKFLAGS -A"
-               CLOCKDEF="$CLOCKDEF (arc)"
-       fi
-
-       if is_yes "$SRM" ; then
-               CLOCKFLAGS="$CLOCKFLAGS -S"
-               CLOCKDEF="$CLOCKDEF (srm)"
-       fi
-
        # Check if timezone definition is available
-       if [ -e /etc/localtime -a -e /dev/rtc ] ; then
-               if run_cmd "$(nls 'Setting clock')$CLOCKDEF" hwclock $CLOCKFLAGS; then
+       if [ -e /etc/localtime ] && [ -e /dev/rtc -o -e /dev/rtc0 ] ; then
+               if run_cmd "$(nls 'Setting clock')" hwclock --hctosys; then
                        show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
                fi
        else
                TIME_SETUP_DELAYED=yes
        fi
 
+       delay_cryptsetup=0
        if [ -f /etc/crypttab ] && ! is_empty_file /etc/crypttab; then
                # XXX might need modules dep
                # Device mapper & related initialization
                if ! grep -qF device-mapper /proc/devices; then
-                       modprobe dm-mod
+                       modprobe -s dm-mod
                fi
 
-               # but should do this before swapon?
                . /etc/rc.d/init.d/cryptsetup
                show "Starting disk encryption"
-               init_crypto 0 && ok || fail
+               init_crypto 0
+               delay_cryptsetup=$?
+               [ $delay_cryptsetup = 0 ] && ok || fail
        fi
 
        # Start up swapping
@@ -308,13 +469,13 @@ if ! is_yes "$VSERVER"; then
 
        # Initialize USB controllers
        usb=0
-       if ! strstr "$cmdline" "nousb" && ! is_fsmounted usbfs /proc/bus/usb ; then
-               aliases=$(/sbin/modprobe -c | awk '/^alias[\t ]+usb-controller/ { print $3 }')
+       if [ -z "$nousb" ] && ! is_fsmounted usbfs /proc/bus/usb; then
+               aliases=$(modprobe_c | awk '/^alias[\t ]+usb-controller/ { print $3 }')
                if [ -n "$aliases" -a "$aliases" != "off" ] ; then
-                       /sbin/modprobe -s usbcore
+                       modprobe -s usbcore
                        for alias in $aliases ; do
                                [ "$alias" = "off" ] && continue
-                               run_cmd "$(nls 'Initializing USB controller') ($alias)" /sbin/modprobe -s $alias
+                               run_cmd "$(nls 'Initializing USB controller') ($alias)" modprobe -s $alias
                        done
                        [ $? -eq 0 -a -n "$aliases" ] && usb=1
                fi
@@ -323,35 +484,33 @@ if ! is_yes "$VSERVER"; then
                fi
        fi
 
-       if [ "$usb" = "1" ] && ! is_fsmounted usbfs /proc/bus/usb ; then
+       if [ "$usb" = "1" -a -d /proc/bus/usb ] && ! is_fsmounted usbfs /proc/bus/usb ; then
                run_cmd "Mounting USB filesystem" mount -n -t usbfs -o devgid=78,devmode=664 usbfs /proc/bus/usb
        fi
 
        needusbstorage=
        if [ "$usb" = "1" ]; then
-               needusbstorage=$(LC_ALL=C cat /proc/bus/usb/devices 2>/dev/null|grep -e "^I.*Cls=08" 2>/dev/null)
+               needusbstorage=$(cat /proc/bus/usb/devices 2>/dev/null | grep -e "^I.*Cls=08" 2>/dev/null)
                if [ "$(kernelverser)" -lt "002006" ]; then
-                       LC_ALL=C grep -q 'hid' /proc/bus/usb/drivers 2>/dev/null || run_cmd "Initializing USB HID interface" modprobe hid 2> /dev/null
+                       grep -Fq 'hid' /proc/bus/usb/drivers 2>/dev/null || run_cmd "Initializing USB HID interface" modprobe -s hid
                        mouseoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=02" 2>/dev/null)
                        kbdoutput=$(cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=01" 2>/dev/null)
                        if [ -n "$kbdoutput" ]; then
-                               run_cmd "Initializing USB keyboard" modprobe keybdev
+                               run_cmd "Initializing USB keyboard" modprobe -s keybdev
                        fi
                        if [ -n "$mouseoutput" ]; then
-                               run_cmd "Initializing USB mouse" modprobe mousedev
+                               run_cmd "Initializing USB mouse" modprobe -s mousedev
                        fi
                fi
        fi
 
        # Setup hdparm thing (if exists and is needed)
-       if ! strstr "$cmdline" nohdparm; then
+       if [ -z "$nohdparm" ]; then
                [ -x /etc/rc.d/rc.hdparm ] && /etc/rc.d/rc.hdparm
        fi
 
-       if [ -f /fastboot ] || strstr "$cmdline" "fastboot"; then
-               fastboot=yes
-       else
-               fastboot=
+       if [ -z "$fastboot" ] && [ -f /fastboot ]; then
+               fastboot=1
        fi
 
        if [ -f /fsckoptions ]; then
@@ -373,66 +532,17 @@ if ! is_yes "$VSERVER"; then
        _ROOTFS_DEVICE=$(awk '($1 !~ /^#/ && $2 == "/" && NF >= 6) { print $1}' /etc/fstab)
        _ROOTFS_TYPE=$(awk '$2 == "/" && $3 != "rootfs" { print $3 }' /proc/mounts 2>/dev/null)
 
-       if [ -z "$fastboot" -a "$_ROOTFS_TYPE" != "nfs" -a "$_ROOTFS_TYPE" != "romfs" -a "$_ROOTFS_PASSNO" != 0 -a -e $_ROOTFS_DEVICE ]; then
-               show "Checking root filesystem"; started
-               initlog -c "fsck -C -T -a $fsckoptions /"
-
-               rc=$?
-
-               # A return of 4 or higher means there were serious problems.
-               if [ $rc -gt 3 ]; then
-                       [ -e /proc/splash ] && echo "verbose" > /proc/splash
-                       # don't use '\n' in nls macro !
-                       echo
-                       echo
-                       nls "*** An error occurred during the file system check."
-                       nls "*** Dropping you to a shell; the system will reboot"
-                       nls "*** when you leave the shell."
-                       echo
-
-                       PS1="`nls '(Repair filesystem)# '`"; export PS1
-                       [ "$SELINUX" = "1" ] && disable_selinux
-                       if ! is_no "$RUN_SULOGIN_ON_ERR"; then
-                               /sbin/sulogin
-                       else
-                               /bin/sh
-                       fi
-
-                       run_cmd "Unmounting file systems" umount -a
-                       mount -n -o remount,ro /
-                       run_cmd "Automatic reboot in progress" reboot
-               # A return of 2 or 3 means that filesystem was repaired but we need
-               # to reboot.
-               elif [ "$rc" = "2" -o "$rc" = "3" ]; then
-                       [ -e /proc/splash ] && echo "verbose" > /proc/splash
-                       echo
-                       nls "*** Filesystem was repaired but system needs to be"
-                       nls "*** rebooted before mounting it."
-                       nls "*** REBOOTING ***"
-                       echo
-
-                       run_cmd "Unmounting file systems" umount -a
-                       mount -n -o remount,ro /
-                       run_cmd "Automatic reboot in progress" reboot
-               elif [ "$rc" = "1" ]; then
-                       _RUN_QUOTACHECK=1
-               fi
-       fi
-
-       # Check for arguments
-       if strstr "$cmdline" nopnp; then
-               PNP=
-       else
-               PNP=yes
+       if [ -z "$fastboot" -a "$_ROOTFS_TYPE" != "aufs" -a "$_ROOTFS_TYPE" != "nfs" -a "$_ROOTFS_TYPE" != "romfs" -a "$_ROOTFS_TYPE" != "squashfs" -a "$_ROOTFS_PASSNO" != 0 -a -e $_ROOTFS_DEVICE ] && [[ "$container" != lxc* ]]; then
+               check_root_fs
        fi
 
        # set up pnp and kernel pnp
-       if [ -n "$PNP" ]; then
-               if ! is_no "$RUN_USERPNP" && [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then
+       if is_yes "$RUN_USERPNP" || is_yes "$RUN_KERNELPNP"; then
+               if [ -z "$nopnp" ] && is_yes "$RUN_USERPNP" && [ -x /sbin/isapnp -a -f /etc/isapnp/isapnp.conf ]; then
                        run_cmd "Setting up ISA PNP devices (userspace pnp)" /sbin/isapnp /etc/isapnp/isapnp.conf
                fi
-               if ! is_no "$RUN_KERNELPNP"; then
-                       /sbin/modprobe isa-pnp 2> /dev/null
+               if [ -z "$nopnp" ] && is_yes "$RUN_KERNELPNP"; then
+                       modprobe -s isa-pnp
                        if [ -e /proc/isapnp -a -f /etc/isapnp/isapnp-kernel.conf ]; then
                                show "Setting up ISA PNP devices (kernelspace pnp)"; busy
                                grep -v "^#" /etc/isapnp/isapnp-kernel.conf 2>/dev/null >/proc/isapnp && (deltext; ok) || (deltext; fail)
@@ -453,15 +563,16 @@ if ! is_yes "$VSERVER"; then
 
        # Clean up SELinux labels
        if [ -n "$SELINUX" ]; then
-               for file in /etc/mtab /etc/cryptomtab /etc/ld.so.cache ; do
+               for file in /etc/mtab /etc/cryptomtab /etc/ld.so.cache; do
                        [ -r $file ] && restorecon $file >/dev/null 2>&1
                done
        fi
 
-       if [ -f /etc/crypttab ] && ! is_empty_file /etc/crypttab; then
-               # XXX, this must be probably done after random is initialized from /var/run/random-seed
+       if [ "$delay_cryptsetup" != 0 ]; then
                show "Starting disk encryption using the RNG"
-               init_crypto 1 && ok || fail
+               init_crypto 1
+               delay_cryptsetup=$?
+               [ $delay_cryptsetup = 0 ] && ok || fail
        fi
 else
        # Start logging console output since we have all /dev stuff setup
@@ -494,36 +605,40 @@ fi
 
 if ! is_yes "$VSERVER"; then
        # Clear mtab
-       :>/etc/mtab
-       [ -f /etc/cryptomtab ] && :>/etc/cryptomtab
+       /etc/mtab
+       [ -f /etc/cryptomtab ] && /etc/cryptomtab
 
        # Enter root, /proc, /sys and other into mtab.
-       mount -f /
-       mount -f /proc
+       mount -f / 2> /dev/null
+       mount -f /proc 2> /dev/null
+       if is_fsmounted devtmpfs /dev; then
+               mount -f -t devtmpfs devtmpfs /dev 2> /dev/null
+       fi
+       if is_fsmounted tmpfs /run; then
+               mount -f -t tmpfs run /run 2> /dev/null
+       fi
+
        if is_fsmounted usbfs /proc/bus/usb; then
-               mount -f -t usbfs -o devgid=78,devmode=664 usbfs /proc/bus/usb
+               mount -f -t usbfs -o devgid=78,devmode=664 usbfs /proc/bus/usb 2> /dev/null
        fi
 
        if is_fsmounted sysfs /sys; then
-               mount -f -t sysfs sysfs /sys
+               mount -f -t sysfs sysfs /sys 2> /dev/null
                if is_fsmounted securityfs /sys/kernel/security ; then
-                       mount -f -t securityfs securityfs /sys/kernel/security
+                       mount -f -t securityfs securityfs /sys/kernel/security 2> /dev/null
                fi
        fi
 
        if is_fsmounted selinuxfs /selinux; then
-               mount -f -t selinuxfs selinuxfs /selinux
+               mount -f -t selinuxfs selinuxfs /selinux 2> /dev/null
        fi
 
-       if is_fsmounted cgroup /dev/cpuset; then
-               mount -f -t cgroup -o cpuset,noprefix none /dev/cpuset
-       elif is_fsmounted cpuset /dev/cpuset; then
-               mount -f -t cpuset none /dev/cpuset
-       fi
+       emit --no-wait root-filesystem
+       emit --no-wait virtual-filesystems
 
        if [ ! -f /proc/modules ]; then
                USEMODULES=
-       elif ! strstr "$cmdline" nomodules; then
+       elif [ -z "$nomodules" ]; then
                USEMODULES=y
        else
                USEMODULES=
@@ -565,30 +680,30 @@ if ! is_yes "$VSERVER"; then
 
        # Load usb storage here, to match most other things
        if [ -n "$needusbstorage" ]; then
-               modprobe usb-storage >/dev/null 2>&1
+               modprobe -s usb-storage
        fi
 
        # Load firewire devices
-       if ! strstr "$cmdline" nofirewire; then
-               aliases=$(/sbin/modprobe -c | awk '/^alias ieee1394-controller/ { print $3 }')
+       if [ -z "$nofirewire" ]; then
+               aliases=$(modprobe_c | awk '/^alias ieee1394-controller/ { print $3 }')
                if [ -n "$aliases" -a "$aliases" != "off" ] ; then
                        for alias in $aliases ; do
                                [ "$alias" = "off" ] && continue
-                               run_cmd "$(nls 'Initializing firewire controller') ($alias)" /sbin/modprobe $alias
+                               run_cmd "$(nls 'Initializing firewire controller') ($alias)" modprobe $alias
                        done
-                       LC_ALL=C grep -E "SBP2" /proc/bus/ieee1394/devices 2>/dev/null && /sbin/modprobe -s sbp2 > /dev/null 2>&1
+                       grep -E "SBP2" /proc/bus/ieee1394/devices 2>/dev/null && modprobe -s sbp2
                fi
        fi
 
        # Load sound modules if they need persistent DMA buffers
-       if /sbin/modprobe -c | grep -q "^options sound dmabuf=1"; then
+       if modprobe_c | grep -q "^options sound dmabuf=1"; then
                RETURN=0
-               alias=$(/sbin/modprobe -c | grep -sE "^alias[[:space:]]+sound[[:space:]]+" 2>/dev/null | awk '{ print $3 }')
+               alias=$(modprobe_c | grep -sE "^alias[[:space:]]+sound[[:space:]]+" 2>/dev/null | awk '{ print $3 }')
                if [ -n "$alias" -a "$alias" != "off" ] ; then
                        run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
                        RETURN=$?
                fi
-               alias=$(/sbin/modprobe -c | grep -sE "^alias[[:space:]]+sound-slot-0[[:space:]]+" 2>/dev/null | awk '{ print $3 }')
+               alias=$(modprobe_c | grep -sE "^alias[[:space:]]+sound-slot-0[[:space:]]+" 2>/dev/null | awk '{ print $3 }')
                if [ -n "$alias" -a "$alias" != "off" ] ; then
                        run_cmd "$(nls 'Loading sound module') ($alias)" modprobe -s $alias
                        RETURN=$?
@@ -596,9 +711,18 @@ if ! is_yes "$VSERVER"; then
        fi
 
        # Load modules
-       load_kernel_modules
+       if ! use_upstart; then
+               load_kernel_modules modules
+               for f in /etc/modules-load.d/*.conf; do
+                       # already loaded by implicit "modules" load
+                       [ "${f##*/}" = "modules.conf" ] && continue
+
+                       [ -r $f ] || continue
+                       load_kernel_modules ${f##/etc/}
+               done
+       fi
 
-       if [ -x /sbin/multipath ]; then
+       if ! is_no "$DM_MULTIPATH" [ -x /sbin/multipath ]; then
                # first make nodes that were discarded due (possible) new /dev mount
                modprobe -s dm-mod
                /sbin/dmsetup mknodes
@@ -607,28 +731,28 @@ if ! is_yes "$VSERVER"; then
                /sbin/dmsetup ls --target multipath --exec '/sbin/kpartx -a -p p'
        fi
 
-       if [ -x /sbin/dmraid ]; then
+       if ! is_no "$DMRAID" && [ -x /sbin/dmraid ]; then
                run_cmd "Activating ATARAID devices" /sbin/dmraid -ay
        fi
 
        # Find and activate volume groups:
        # EVMS
-       if [ -x /sbin/evms_activate ]; then
+       if is_yes "$EVMS_LVM" && [ -x /sbin/evms_activate ]; then
                if [ "$(kernelverser)" -lt "002006" ]; then
                        # Linux 2.4 core modules
-                       modprobe -s evms > /dev/null 2>&1
-                       modprobe -s evms_passthru > /dev/null 2>&1
-                       modprobe -s ldev_mgr > /dev/null 2>&1
-                       modprobe -s dos_part > /dev/null 2>&1
+                       modprobe -s evms
+                       modprobe -s evms_passthru
+                       modprobe -s ldev_mgr
+                       modprobe -s dos_part
                else
                        # Linux 2.6 core module
-                       modprobe -s evmscore > /dev/null 2>&1
+                       modprobe -s evmscore
                fi
 
-               is_yes "$EVMS_GUID_PTABLE" && modprobe -s gpt_part >/dev/null 2>&1
-               is_yes "$EVMS_LVM" && modprobe -s lvm_vge >/dev/null 2>&1
-               is_yes "$EVMS_AIX" && modprobe -s AIXlvm_vge >/dev/null 2>&1
-               is_yes "$EVMS_OS2" && modprobe -s os2lvm_vge >/dev/null 2>&1
+               is_yes "$EVMS_GUID_PTABLE" && modprobe -s gpt_part
+               is_yes "$EVMS_LVM" && modprobe -s lvm_vge
+               is_yes "$EVMS_AIX" && modprobe -s AIXlvm_vge
+               is_yes "$EVMS_OS2" && modprobe -s os2lvm_vge
                run_cmd "Discovering EVMS volumes" /sbin/evms_activate
                if is_yes "$EVMS_LVM" && is_yes "$EVMS_LVM_COMPAT_NODES" ; then
                        # Link nodes for compatibility with LVM
@@ -638,131 +762,25 @@ if ! is_yes "$VSERVER"; then
                fi
        fi
 
-       # LVM (keep in sync with LVM starting after RAID run!)
-       if is_yes "$EVMS_LVM" || [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
-               lvmversion=$(LC_ALL=C /sbin/vgchange --version 2>/dev/null | awk '/LVM version:/{if ($3 >= 2) print "2"}')
-               if [ "$lvmversion" = "1" ] ; then
-                       modprobe -s lvm-mod >/dev/null 2>&1
-                       lvmignorelock=""
-               elif [ "$lvmversion" = "2" ] ; then
-                       modprobe -s dm-mod >/dev/null 2>&1
-                       lvmignorelock="--ignorelockingfailure"
-               else
-                       modprobe -s lvm-mod >/dev/null 2>&1
-                       # device mapper (2.5+ and patched 2.4)
-                       modprobe -s dm-mod >/dev/null 2>&1
-                       lvmignorelock=""
-               fi
-
-               run_cmd "Scanning for LVM volume groups" /sbin/vgscan $lvmignorelock
-               run_cmd "Activating LVM volume groups" /sbin/vgchange -a y $lvmignorelock
-               if [ "$lvmversion" = "2" ]; then
-                       /sbin/vgmknodes
-                       # display VG statistics
-                       /sbin/vgdisplay -s
-               fi
+       # Init LVM
+       if ! is_no "$LVM2"; then
+               init_lvm
        fi
 
-       # Add raid devices
-       if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ] || [ -f /etc/raidtab ]; then
-               modprobe -s md >/dev/null 2>&1
-               if [ -f /proc/mdstat ]; then
-                       goraidtab=1
-                       golvm=0
-                       rc=0
-                       if [ -x /sbin/mdadm -a -f /etc/mdadm.conf ]; then
-                               if (grep -qE "^([[:blank:]]|)ARRAY[[:blank:]]" /etc/mdadm.conf 2>/dev/null); then
-                                       show "Starting up RAID devices"; busy
-                                       /sbin/mdadm --assemble --scan --auto=yes
-                                       rc=$?
-                                       if [ "$rc" -eq 0 -o "$rc" -eq 2 ]; then
-                                               # rc is used later, too so set sane value
-                                               rc=0
-                                               deltext; ok
-                                               goraidtab=0
-                                               golvm=1
-                                       else
-                                               deltext; fail
-                                       fi
-
-                               fi
-                       fi
-
-                       if [ -f /etc/raidtab -a "$goraidtab" -eq 1 ]; then
-                               for i in $(awk '!/^#/ && /raiddev/{print $2}' /etc/raidtab 2>/dev/null); do
-                                       golvm=1
-                                       RAIDDEV=$(basename $i)
-                                       RAIDSTAT=$(grep "^$RAIDDEV : active" /proc/mdstat 2>/dev/null)
-                                       show "Starting up RAID device %s" $RAIDDEV
-                                       busy
-                                       if [ -z "$RAIDSTAT" ]; then
-                                               # Try raidstart first...if that fails then
-                                               # fall back to raid0run and if that fails too
-                                               # fall back to raidadd, raidrun.
-                                               RESULT=1
-                                               if [ -x /sbin/raidstart ]; then
-                                                       /sbin/raidstart $i
-                                                       RESULT=$?
-                                               fi
-                                               if [ $RESULT -gt 0 -a -x /sbin/raid0run ]; then
-                                                       /sbin/raid0run $i
-                                                       RESULT=$?
-                                               fi
-                                               if [ $RESULT -gt 0 -a -x /sbin/raidadd -a -x /sbin/raidrun ]; then
-                                                       /sbin/raidadd $i
-                                                       /sbin/raidrun $i
-                                                       RESULT=$?
-                                               fi
-                                               if [ $RESULT -gt 0 ]; then
-                                                       rc=1
-                                                       fail
-                                               else
-                                                       ok
-                                               fi
-                                       else
-                                               ok
-                                       fi
-                               done
-                       fi
+       if [ "$delay_cryptsetup" != 0 ]; then
+               show "Starting disk encryption"
+               init_crypto 1
+               delay_cryptsetup=$?
+               [ $delay_cryptsetup = 0 ] && ok || fail
+       fi
 
-                       # A non-zero return means there were problems
-                       if [ $rc -gt 0 ]; then
-                               [ -e /proc/splash ] && echo "verbose" > /proc/splash
-                               show "Starting up RAID devices"; fail
-                               echo
-                               echo
-                               nls "*** An error occurred during the RAID startup."
-                               nls "*** Dropping you to a shell; the system will reboot"
-                               nls "*** when you leave the shell."
-                               echo
-
-                               PS1="$(nls '(RAID Repair)# ')"; export PS1
-                               [ "$SELINUX" = "1" ] && disable_selinux
-                               if ! is_no "$RUN_SULOGIN_ON_ERR"; then
-                                       /sbin/sulogin
-                               else
-                                       /bin/sh
-                               fi
-
-                               run_cmd "Unmounting file systems" umount -a
-                               run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
-                               run_cmd "Automatic reboot in progress" reboot
-                       fi
-                       # LVM on RAID (keep in sync with LVM setting few lines above)
-                       if [ "$golvm" -eq "1" ]; then
-                               if [ -x /sbin/vgscan -a -x /sbin/vgchange ]; then
-                                       run_cmd "Scanning for LVM volume groups (on RAID)" /sbin/vgscan $lvmignorelock
-                                       run_cmd "Activating LVM volume groups (on RAID)" /sbin/vgchange -a y $lvmignorelock
-                                       [ "$lvmversion" = "2" ] && /sbin/vgmknodes
-                               fi
-                       fi
-                       show "Starting up RAID devices"; ok
-               fi
+       if ! is_no "$MDADM"; then
+               init_mdadm
        fi
 
        _RUN_QUOTACHECK=0
        # Check filesystems
-       if [ -z "$fastboot" ] && ! strstr "$cmdline" nofsck; then
+       if [ -z "$fastboot" ] && [ -z "$nofsck" ]; then
                rc_splash "fsck start"
                show "Checking filesystems"; started
                initlog -c "fsck -C -T -R -A -a -P $fsckoptions"
@@ -772,24 +790,10 @@ if ! is_yes "$VSERVER"; then
                # A return of 2 or higher means there were serious problems
                if [ $rc -gt 1 ]; then
                        [ -e /proc/splash ] && echo "verbose" > /proc/splash
-                       echo
-                       echo
-                       nls "*** An error occurred during the file system check."
-                       nls "*** Dropping you to a shell; the system will reboot"
-                       nls "*** when you leave the shell."
-                       echo
 
                        PS1="$(nls '(Repair filesystem)# ')"; export PS1
-                       [ "$SELINUX" = "1" ] && disable_selinux
-                       if ! is_no "$RUN_SULOGIN_ON_ERR"; then
-                               /sbin/sulogin
-                       else
-                               /bin/sh
-                       fi
+                       repair_shell "$(nls '*** An error occurred during the file system check.')"
 
-                       run_cmd "Unmounting file systems" umount -a
-                       run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
-                       run_cmd "Automatic reboot in progress" reboot
                elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
                        _RUN_QUOTACHECK=1
                fi
@@ -799,7 +803,6 @@ if ! is_yes "$VSERVER"; then
        # Mount all other filesystems (except for NFS and /proc, which is already
        # mounted). Contrary to standard usage,
        # filesystems are NOT unmounted in single user mode.
-
        run_cmd "Mounting local filesystems" mount -a -t nonfs,nfs4,smbfs,ncpfs,proc,cifs -O no_netdev
 
        # now we have /usr mounted, recheck if we have gettext and tput available.
@@ -835,30 +838,16 @@ if ! is_yes "$VSERVER"; then
                # A return of 2 or higher means there were serious problems.
                if [ $rc -gt 1 ]; then
                        [ -e /proc/splash ] && echo "verbose" > /proc/splash
-                       echo
-                       echo
-                       nls "*** An error occurred during the file system check."
-                       nls "*** Dropping you to a shell; the system will reboot"
-                       nls "*** when you leave the shell."
-                       echo
 
                        PS1="$(nls '(Repair filesystem)# ')"; export PS1
-                       [ "$SELINUX" = "1" ] && disable_selinux
-                       if ! is_no "$RUN_SULOGIN_ON_ERR"; then
-                               /sbin/sulogin
-                       else
-                               /bin/sh
-                       fi
+                       repair_shell "$(nls '*** An error occurred during the file system check.')"
 
-                       run_cmd "Unmounting file systems" umount -a
-                       run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
-                       run_cmd "Automatic reboot in progress" reboot
                elif [ "$rc" = "1" -a -x /sbin/quotacheck ]; then
                        _RUN_QUOTACHECK=1
                fi
 
                show "Remounting encrypted filesystems back in rw mode"; busy
-               awk '
+               LC_ALL=C awk '
                FILENAME=="/proc/mounts" {
                        TAB[$2]=$1;
                }
@@ -873,7 +862,7 @@ if ! is_yes "$VSERVER"; then
 
        # /var/log should be writable now, so start saving the boot output
        if [ "$RC_BOOTLOG" ]; then
-               echo > /var/log/boot.msg
+               echo > /var/log/boot.log
                killall -IO blogd
        fi
 
@@ -886,14 +875,20 @@ if ! is_yes "$VSERVER"; then
                run_cmd "Turning on quotas for local filesystems" /sbin/quotaon -aug
        fi
 
+       emit --no-wait local-filesystems
+
+       # FIXME: this should be delayed until remote filesystems are mounted,
+       #        especialy when /usr or other standard fs is remote
+       emit --no-wait filesystem
+
        # Turn on process accounting
        if [ -x /etc/rc.d/rc.acct ]; then
                /etc/rc.d/rc.acct start
        fi
 
        # Set the clock if timezone definition wasn't available (eg. /usr not mounted)
-       if is_yes "$TIME_SETUP_DELAYED" && [ -e /dev/rtc ]; then
-               if run_cmd "$(nls 'Setting clock')$CLOCKDEF" hwclock $CLOCKFLAGS; then
+       if is_yes "$TIME_SETUP_DELAYED" && [ -e /dev/rtc -o -e /dev/rtc0 ]; then
+               if run_cmd "$(nls 'Setting clock')" hwclock --hctosys; then
                        show "$(nls 'Today`s date:') $(LC_CTYPE=C date)"; ok
                fi
        fi
@@ -903,17 +898,23 @@ if ! is_yes "$VSERVER"; then
                . /etc/rc.d/rc.serial
        fi
 
-       if [ -f /proc/sys/kernel/panic -a -n "$PANIC_REBOOT_TIME" -a "$PANIC_REBOOT_TIME" -gt "0" ]; then
+       if [ -n "$PANIC_REBOOT_TIME" -a "$PANIC_REBOOT_TIME" -gt "0" -a -f /proc/sys/kernel/panic ]; then
                show 'Setting %s seconds for kernel reboot after panic' "$PANIC_REBOOT_TIME"; busy
-               if (sysctl -w kernel.panic=$PANIC_REBOOT_TIME >/dev/null 2>&1); then ok; else fail; fi
+               # NOTE: you should use /etc/sysctl.conf instead
+               if sysctl -w kernel.panic=$PANIC_REBOOT_TIME >/dev/null 2>&1; then ok; else fail; fi
        fi
 
        # ... and here finish configuring parameters
        sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
 else
+       emit --no-wait root-filesystem
+       emit --no-wait virtual-filesystems
+       emit --no-wait local-filesystems
+       emit --no-wait filesystem
+
        # /var/log should be writable now, so start saving the boot output
        if [ "$RC_BOOTLOG" ]; then
-               echo > /var/log/boot.msg
+               echo > /var/log/boot.log
                killall -IO blogd
        fi
 
@@ -939,7 +940,7 @@ for afile in /var/lock/* /var/run/*; do
                        ;;
                esac
        else
-               [ "$bafile" != "hwprofile" ] && rm -f $afile 2> /dev/null
+               [ "$bafile" != "hwprofile" -a "$bafile" != "random-seed" ] && rm -f $afile 2> /dev/null
        fi
 done
 
@@ -953,21 +954,20 @@ rm -rf /tmp/.X*-unix /tmp/.ICE-unix /tmp/.font-unix /tmp/hsperfdata_* \
 {
 # Clean up utmp/wtmp
 if ! is_no "$NEED_XFILES"; then
-       :>/var/run/utmpx
+       /var/run/utmpx
        touch /var/log/wtmpx
        chown root:utmp /var/run/utmpx /var/log/wtmpx
        chmod 0664 /var/run/utmpx /var/log/wtmpx
 else
-       :>/var/run/utmp
+       /var/run/utmp
        touch /var/log/wtmp
        chown root:utmp /var/run/utmp /var/log/wtmp
        chmod 0664 /var/run/utmp /var/log/wtmp
 fi
 
 # Clean /tmp
-if is_yes "$CLEAN_TMP"; then
-       # XXX LC_ALL needed here
-       rm -rf /tmp/* /tmp/.[a-zA-Z0-9]*
+if is_yes "$CLEAN_TMP" && ! is_fsmounted tmpfs /tmp; then
+       LC_ALL=C rm -rf /tmp/* /tmp/.[a-zA-Z0-9]*
 fi
 
 # System protected dirs
@@ -979,6 +979,7 @@ if ! is_yes "$VSERVER"; then
        run_cmd "Enabling swap space" true
        # Right, now turn on swap in case we swap to files
        swapon -a >/dev/null 2>&1
+       emit --no-wait all-swaps
 
        # If a SCSI tape has been detected, load the st module unconditionally
        # since many SCSI tapes don't deal well with st being loaded and unloaded
@@ -986,14 +987,14 @@ if ! is_yes "$VSERVER"; then
                if grep -qv ' 9 st' /proc/devices 2>/dev/null; then
                        if [ -n "$USEMODULES" ] ; then
                                # Try to load the module. If it fails, ignore it...
-                               insmod -p st >/dev/null 2>&1 && modprobe -s st >/dev/null 2>&1
+                               insmod -p st >/dev/null 2>&1 && modprobe -s st
                        fi
                fi
        fi
 
        # Now that we have all of our basic modules loaded and the kernel going,
        # let's dump the syslog ring somewhere so we can find it later
-       dmesg > /var/log/dmesg
+       dmesg --raw > /var/log/dmesg
        i=5
        while [ $i -ge 0 ]; do
                if [ -f /var/log/dmesg.$i ]; then
@@ -1004,6 +1005,8 @@ if ! is_yes "$VSERVER"; then
        done
        cp -f /var/log/dmesg /var/log/dmesg.0
        chmod 0600 /var/log/dmesg /var/log/dmesg.0
+else
+       emit --no-wait all-swaps
 fi
 
 if ! is_no "$RC_PROMPT"; then
@@ -1027,3 +1030,6 @@ if ! is_no "$RC_PROMPT"; then
        rm -f /var/run/getkey_done
 fi
 echo
+
+emit --no-wait pld.sysinit-done
+
This page took 0.08014 seconds and 4 git commands to generate.