Move the sourcing of software.sh to genkernel
[genkernel.git] / defaults / linuxrc
index 23ec2b0538d7f05029a9e803a3da3328fc41909d..f434339d128d00f5826f20ec19d2504e79777dcd 100755 (executable)
@@ -39,6 +39,7 @@ FAKE_ROOT=''
 REAL_ROOTFLAGS=''
 ROOTFSTYPE='auto'
 CRYPT_SILENT=0
+mkdir -p /etc/cmdline /etc/modprobe.d
 for x in ${CMDLINE}
 do
        case "${x}" in
@@ -240,6 +241,13 @@ do
                nounionfs)
                        USE_UNIONFS_NORMAL=0
                        ;;
+               *=*)
+                       case "${x%%=*}" in
+                       *.*)
+                               echo "${x#*.}" >> "/etc/module_options/${x%%.*}.conf"
+                       ;;
+                       esac
+               ;;
        esac
 done
 
@@ -250,7 +258,12 @@ fi
 
 # Set variables based on the value of REAL_ROOT
 case "${REAL_ROOT}" in
-       ZFS*)
+       ZFS=*)
+               ZFS_POOL=${REAL_ROOT#*=}
+               ZFS_POOL=${ZFS_POOL%%/*}
+               USE_ZFS=1
+       ;;
+       ZFS)
                USE_ZFS=1
        ;;
 esac
@@ -258,12 +271,15 @@ esac
 # Verify that it is safe to use ZFS
 if [ "USE_ZFS" = "1" ]
 then
-       if [ -x /sbin/zfs ]
+       if [ -x /sbin/zfs -a -x /sbin/zpool ]
        then
                MY_HWOPTS="${MY_HWOPTS} zfs"
        else
-               bad_msg 'zfs binary not found: aborting use of zfs!'
                USE_ZFS=0
+
+               [ -x /sbin/zfs ] || bad_msg '/sbin/zfs not found!'
+               [ -x /sbin/zpool ] || bad_msg '/sbin/zpool not found!'
+               bad_msg 'Aborting use of zfs!'
        fi
 fi
 
@@ -277,14 +293,16 @@ mount_devfs
 # Mount sysfs
 mount_sysfs
 
-# Setup hotplugging for firmware loading
-setup_hotplug
-
-# Start mdev
+# Initialize mdev
 if [ "${KV_2_6_OR_GREATER}" ]
 then
        good_msg 'Activating mdev'
-       ( cd /sys && mdev -s ) || bad_msg "Failed to receive dynamic updates from mdev"
+
+       # Serialize hotplug events
+       touch /dev/mdev.seq
+
+       # Setup hotplugging for firmware loading
+       echo /sbin/mdev > /proc/sys/kernel/hotplug
 fi
 
 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
@@ -308,6 +326,12 @@ else
        good_msg 'Skipping module load; no modules in the ramdisk!'
 fi
 
+# Ensure that device nodes are properly configured
+if [ "${KV_2_6_OR_GREATER}" ]
+then
+       mdev -s || bad_msg "mdev -s failed"
+fi
+
 # Apply scan delay if specified
 sdelay
 
@@ -359,7 +383,7 @@ then
                                fi
 
                                if [ ${retval} -ne 0 ]; then
-                                       RESUME_DEV=$(blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null)
+                                       RESUME_DEV=$(blkid -o device -l -t "${REAL_RESUME}")
                                        retval=$?
                                fi
 
@@ -467,7 +491,7 @@ do
                                fi
 
                                if [ ${retval} -ne 0 ]; then
-                                       ROOT_DEV=$(blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null)
+                                       ROOT_DEV=$(blkid -o device -l -t "${REAL_ROOT}")
                                        retval=$?
                                fi
 
@@ -481,16 +505,24 @@ do
                                fi
                                ;;
                        ZFS*)
+                               if [ "${USE_ZFS}" = '0' ]; then
+                                       prompt_user "REAL_ROOT" "root block device"
+                                       continue
+                               fi
+                                       
                                ROOT_DEV="${REAL_ROOT#*=}"
                                if [ "${ROOT_DEV}" != 'ZFS' ] 
                                then
-                                       zfs get type ${ROOT_DEV} > /dev/null
-
-                                       if [ "$?" = '0' ]
+                                       if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ]
                                        then
                                                got_good_root=1;
                                                REAL_ROOT=${ROOT_DEV}
                                                ROOTFSTYPE=zfs
+                                       else
+                                               bad_msg "${ROOT_DEV} is not a filesystem"
+                                               prompt_user "REAL_ROOT" "root block device"
+                                               got_good_root=0
+                                               continue
                                        fi
                                else
                                        BOOTFS=$(/sbin/zpool list -H -o bootfs)
@@ -512,6 +544,8 @@ do
                                                
                                                done;
 
+                                       else
+                                               got_good_root=0
                                        fi
 
                                fi
@@ -558,7 +592,12 @@ do
 
                if [ "${ROOTFSTYPE}" = 'zfs' ]
                then
-                       MOUNT_STATE=rw
+                       if [ "zfs get -H -o value mountpoint ${REAL_ROOT}" = 'legacy' ]
+                       then
+                               MOUNT_STATE=rw
+                       else
+                               MOUNT_STATE=rw,zfsutil
+                       fi
                else
                        MOUNT_STATE=ro
                fi
@@ -780,7 +819,7 @@ then
                fi
        done
 
-       mkdir initramfs proc tmp sys 2>/dev/null
+       mkdir initramfs proc tmp sys run 2>/dev/null
        chmod 1777 tmp
 
        fi
@@ -821,8 +860,13 @@ for fs in $fslist; do
        # and not a mountpoint
        [ -z "$dev" ] && continue
        fstype=$(get_mount_fstype $fs)
-       # ro must be trailing, and the options will always contain at least 'defaults'
-       opts="$(get_mount_options $fs | strip_mount_options),ro"
+       if get_mount_options $fs | fgrep -q bind ; then
+               opts='bind'
+               dev=${NEW_ROOT}${dev}
+       else
+               # ro must be trailing, and the options will always contain at least 'defaults'
+               opts="$(get_mount_options $fs | strip_mount_options),ro"
+       fi
        mnt=${NEW_ROOT}${fs}
        cmd="mount -t $fstype -o $opts $dev $mnt"
        good_msg "Mounting $dev as ${fs}: $cmd"
@@ -845,7 +889,7 @@ verbose_kmsg
 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
 
 cd "${CHROOT}"
-mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
+mkdir "${CHROOT}/proc" "${CHROOT}/sys" "${CHROOT}/run" 2>/dev/null
 echo -ne "${BOLD}.${NORMAL}"
 
 # If devtmpfs is mounted, try move it to the new root