]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - rc.d/rc.sysinit
avoid loading /etc/modules contents twice (modules-load.d/modules.conf is symlink...
[projects/rc-scripts.git] / rc.d / rc.sysinit
index ba6948374c5b2add61a8059ee1e41da39fc1cb73..d486c8e797bb5ab269b6cc345a49f044d2ad2e12 100755 (executable)
@@ -37,7 +37,7 @@ fi
 CONSOLE_LOGLEVEL=1
 
 # Read functions
-. /etc/rc.d/init.d/functions
+. /lib/rc-scripts/functions
 
 disable_selinux() {
        local _d selinuxfs _t _r
@@ -83,13 +83,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,13 +103,15 @@ 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
 }
 
@@ -160,8 +168,15 @@ else
 fi
 
 if ! is_yes "$VSERVER" ; then
+       if [ -d /run ]; then
+               is_fsmounted tmpfs /run || mount -n -t tmpfs run /run
+       fi
+
        # 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
+
+       # Early sysctls
+       sysctl -e -p /etc/sysctl.conf > /dev/null 2>&1
 
        # Only read this once.
        cmdline=$(cat /proc/cmdline)
@@ -172,9 +187,8 @@ if ! is_yes "$VSERVER" ; then
        # sysfs is also needed before any other things (under kernel > 2.5)
        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
 
@@ -199,7 +213,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)
@@ -252,8 +266,11 @@ if ! is_yes "$VSERVER"; then
                dmesg -n $CONSOLE_LOGLEVEL
        fi
 
-       if ! is_no "$START_UDEV" && [ -x /sbin/start_udev ]; then
+       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
+               [ -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
@@ -270,69 +287,13 @@ if ! is_yes "$VSERVER"; then
                /sbin/blogd
        fi
 
-       # cgroup/cpuset support
-       if grep -q cgroup /proc/filesystems 2>/dev/null ; then
-               if ! grep -q cgroup /etc/fstab 2>/dev/null ; then
-                       # creating is more convenient than artificial conflict with older udev
-                       mkdir -p /dev/cgroup
-                       # mount w/o options enables all available cgroup subsystems
-                       modprobe -s blk-cgroup 2> /dev/null
-                       mount -n -t cgroup none /dev/cgroup
-               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
@@ -424,7 +385,7 @@ 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" != "aufs" -a "$_ROOTFS_TYPE" != "nfs" -a "$_ROOTFS_TYPE" != "romfs" -a "$_ROOTFS_TYPE" != "squashfs" -a "$_ROOTFS_PASSNO" != 0 -a -e $_ROOTFS_DEVICE ]; then
+       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
 
@@ -508,29 +469,30 @@ if ! is_yes "$VSERVER"; then
        [ -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/cgroup; then
-               mount -f -t cgroup none /dev/cgroup
-       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
 
@@ -609,9 +571,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 [ -x /sbin/multipath ] && ! is_no "$DM_MULTIPATH"; then
                # first make nodes that were discarded due (possible) new /dev mount
                modprobe -s dm-mod
                /sbin/dmsetup mknodes
@@ -652,27 +623,34 @@ if ! is_yes "$VSERVER"; then
        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 ! is_no "$LVM2" && [ -x /sbin/vgscan -a -x /sbin/vgchange ] || is_yes "$EVMS_LVM"; then
+               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 >/dev/null 2>&1
-                       lvmignorelock=""
+                       lvmignorelocking=""
+                       lvmsysinit=""
                elif [ "$lvmversion" = "2" ] ; then
                        modprobe -s dm-mod >/dev/null 2>&1
-                       lvmignorelock="--ignorelockingfailure"
+                       lvmignorelocking="--ignorelockingfailure"
+                       lvmsysinit="--sysinit"
                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=""
+                       lvmignorelocking=""
+                       lvmsysinit=""
                fi
 
-               run_cmd "Scanning for LVM volume groups" /sbin/vgscan $lvmignorelock
-               run_cmd "Activating LVM volume groups" /sbin/vgchange -a y $lvmignorelock
+               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 $lvmignorelock
+                       /sbin/vgmknodes $lvmignorelocking
                        # display VG statistics
-                       /sbin/vgdisplay -s $lvmignorelock
+                       /sbin/vgdisplay -s $lvmignorelocking
                fi
        fi
 
@@ -691,9 +669,9 @@ if ! is_yes "$VSERVER"; then
                        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
+                               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
+                                       /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
@@ -771,8 +749,8 @@ if ! is_yes "$VSERVER"; then
                        # 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
+                                       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
@@ -835,7 +813,7 @@ if ! is_yes "$VSERVER"; then
        # option is removed from /etc/mtab
        if [ -z "$fastboot" ] && grep "^[^#].*encryption=" /etc/fstab 2>/dev/null | grep -v -q "noauto" 2>/dev/null; then
                show "Checking encrypted filesystems"; started
-               LOOPLIST="$(awk '
+               LOOPLIST="$(LC_ALL=C awk '
                FILENAME=="/proc/mounts" {
                        TAB[$2]=$1;
                }
@@ -878,7 +856,7 @@ if ! is_yes "$VSERVER"; then
                fi
 
                show "Remounting encrypted filesystems back in rw mode"; busy
-               awk '
+               LC_ALL=C awk '
                FILENAME=="/proc/mounts" {
                        TAB[$2]=$1;
                }
@@ -918,8 +896,8 @@ if ! is_yes "$VSERVER"; then
        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
@@ -997,9 +975,8 @@ else
 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
@@ -1026,7 +1003,7 @@ if ! is_yes "$VSERVER"; then
 
        # 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
This page took 0.038143 seconds and 4 git commands to generate.