add command line parameters to specify exact actions for root assembly
authorHarald Hoyer <harald@redhat.com>
Wed, 15 Jul 2009 16:21:10 +0000 (18:21 +0200)
committerHarald Hoyer <harald@redhat.com>
Wed, 15 Jul 2009 16:27:21 +0000 (18:27 +0200)
LVM
       rd_NO_LVM
              disable LVM detection

       rd_LVM_VG=<volume group name>
              only activate the volume groups with the given name

crypto LUKS
       rd_NO_LUKS
              disable crypto LUKS detection

       rd_LUKS_UUID=<luks uuid>
              only activate the LUKS partitions with the given UUID

MD
       rd_NO_MD
              disable MD RAID detection

       rd_MD_UUID=<md uuid>
              only activate the raid sets with the given UUID

DMRAID
       rd_NO_DM
              disable DM RAID detection

       rd_DM_UUID=<dmraid uuid>
              only activate the raid sets with the given UUID

16 files changed:
dracut.8
modules.d/50plymouth/cryptroot-ask.sh
modules.d/90crypt/cryptroot-ask.sh
modules.d/90crypt/install
modules.d/90crypt/parse-crypt.sh [new file with mode: 0755]
modules.d/90dmraid/dmraid.sh
modules.d/90dmraid/parse-dm.sh [new file with mode: 0644]
modules.d/90lvm/install
modules.d/90lvm/lvm_scan.sh
modules.d/90lvm/parse-lvm.sh [new file with mode: 0644]
modules.d/90mdraid/61-mdadm.rules
modules.d/90mdraid/65-md-incremental-imsm.rules
modules.d/90mdraid/65-md-incremental.rules
modules.d/90mdraid/install
modules.d/90mdraid/mdraid_start.sh
modules.d/90mdraid/parse-md.sh [new file with mode: 0644]

index 4d6ac29b50352fb38657a3697cdc32edfb4594bf..e121bf5b39a5d5e7641b802602edcf3424486944 100644 (file)
--- a/dracut.8
+++ b/dracut.8
@@ -78,6 +78,38 @@ root filesystem.
 specify e.g. \fI/dev/sda1\fR or
 \fI/dev/disk/by-path/pci-0000:00:1f.1-scsi-0:0:1:0-part1\fR
 
+.SH LVM
+.TP
+.B rd_NO_LVM
+disable LVM detection
+.TP
+.B rd_LVM_VG=<volume group name>
+only activate the volume groups with the given name
+
+.SH crypto LUKS
+.TP
+.B rd_NO_LUKS
+disable crypto LUKS detection
+.TP
+.B rd_LUKS_UUID=<luks uuid>
+only activate the LUKS partitions with the given UUID
+
+.SH MD
+.TP
+.B rd_NO_MD
+disable MD RAID detection
+.TP
+.B rd_MD_UUID=<md uuid>
+only activate the raid sets with the given UUID
+
+.SH DMRAID
+.TP
+.B rd_NO_DM
+disable DM RAID detection
+.TP
+.B rd_DM_UUID=<dmraid uuid>
+only activate the raid sets with the given UUID
+
 .SH DHCP
 .TP
 .B root=dhcp
index 2d0f3572f50a9f4ef615905d63500c72f50a2c38..75c6550dd7c3a4e63cea03651641561dbadbd2e1 100755 (executable)
@@ -9,13 +9,33 @@
 # we already asked for this device
 [ -f /tmp/cryptroot-asked-$2 ] && exit 0
 
-# flock against other interactive activities
-{ flock -s 9; 
-/bin/plymouth ask-for-password --prompt "$1 is password protected" --command="/sbin/cryptsetup luksOpen -T1 $1 $2"
-} 9>/.console.lock
+. /lib/dracut-lib.sh
+LUKS=$(getargs rd_LUKS_UUID=)
+ask=1
+
+if [ -n "$LUKS" ]; then
+    ask=0
+    for luks in $LUKS; do
+       if [ "${2##$luks}" != "$2" ]; then
+           ask=1
+       fi
+    done
+fi
+
+if [ $ask -gt 0 ]; then
+    # flock against other interactive activities
+    { flock -s 9; 
+       /bin/plymouth ask-for-password \
+           --prompt "$1 is password protected" \
+           --command="/sbin/cryptsetup luksOpen -T1 $1 $2"
+    } 9>/.console.lock
+fi
 
 # mark device as asked
 >> /tmp/cryptroot-asked-$2
 
+unset LUKS
+unset ask
+unset luks
 exit 0
 
index d87c2ea88c019c3be3149427bca17c52b9a22a7e..5b5d895f710a56de236af863f6732ff90f402fff 100755 (executable)
@@ -9,11 +9,26 @@
 # we already asked for this device
 [ -f /tmp/cryptroot-asked-$2 ] && exit 0
 
-# flock against other interactive activities
-{ flock -s 9; 
-    echo -n "$1 is password protected " 
-    /sbin/cryptsetup luksOpen -T1 $1 $2
-} 9>/.console.lock
+. /lib/dracut-lib.sh
+LUKS=$(getargs rd_LUKS_UUID=)
+ask=1
+
+if [ -n "$LUKS" ]; then
+    ask=0
+    for luks in $LUKS; do
+       if [ "${2##$luks}" != "$2" ]; then
+           ask=1
+       fi
+    done
+fi
+
+if [ $ask -gt 0 ]; then
+    # flock against other interactive activities
+    { flock -s 9; 
+       echo -n "$1 is password protected " 
+       /sbin/cryptsetup luksOpen -T1 $1 $2
+    } 9>/.console.lock
+fi
 
 # mark device as asked
 >> /tmp/cryptroot-asked-$2
index a3a856d02aca3f797fe9ea20e17b26d032c38fd4..9ffe90e4f2337936469bf609a0b9608a50f83494 100755 (executable)
@@ -3,3 +3,4 @@ inst cryptsetup
 instmods dm_crypt cbc aes sha256 xts
 inst_rules "$moddir/70-luks.rules"
 inst "$moddir"/cryptroot-ask.sh /sbin/cryptroot-ask
+inst_hook cmdline 30 "$moddir/parse-crypt.sh"
diff --git a/modules.d/90crypt/parse-crypt.sh b/modules.d/90crypt/parse-crypt.sh
new file mode 100755 (executable)
index 0000000..4a39c21
--- /dev/null
@@ -0,0 +1,6 @@
+initrdargs="$initrdargs rd_NO_LUKS rd_LUKS_UUID" 
+
+if getarg rd_NO_LUKS; then
+    rm -f /etc/udev/rules.d/70-luks.rules
+fi
+
index f6cb26fd4e1bf2b4785aadd34ae7a26d1d8c5e13..f706e57b05c0d30819ba1be91926291a49cca120 100755 (executable)
@@ -2,7 +2,19 @@
 
 if $UDEV_QUEUE_EMPTY >/dev/null 2>&1; then
     [ -h "$job" ] && rm -f "$job"
+    DM_RAIDS=$(getargs rd_DM_UUID=)
     # run dmraid if udev has settled
-    dmraid -ay 
+    info "Scanning for dmraid devices $DM_RAIDS"
+    SETS=$(dmraid -c -s)
+    info "Found dmraid sets:"
+    echo $SETS|vinfo
+    for r in $DM_RAIDS; do 
+       for s in $SETS; do 
+           if [ "${s##$r}" != "$s" ]; then
+               info "Activating $s"
+               dmraid -ay $s | vinfo
+           fi
+       done
+    done
 fi
 
diff --git a/modules.d/90dmraid/parse-dm.sh b/modules.d/90dmraid/parse-dm.sh
new file mode 100644 (file)
index 0000000..a047d2d
--- /dev/null
@@ -0,0 +1,5 @@
+initrdargs="$initrdargs rd_DM_UUID rd_NO_DM" 
+
+if getarg rd_NO_DM; then
+    rm /etc/udev/rules.d/61-dmraid*.rules
+fi
\ No newline at end of file
index cba321bb0b84e747393de9ca692724cd6131ef40..ad5e485bde4a366b08aac278ff3c645d109cc01b 100755 (executable)
@@ -7,3 +7,4 @@ else
 fi
 
 inst "$moddir/lvm_scan.sh" /sbin/lvm_scan
+inst_hook cmdline 30 "$moddir/parse-lvm.sh"
index 489c7a145f2b477a29f7b83d8e74b3df59752a2c..81c48c03738e40d8b069d09f90071e5c42a3c3e1 100755 (executable)
@@ -4,12 +4,14 @@ if $UDEV_QUEUE_EMPTY >/dev/null 2>&1; then
     [ -h "$job" ] && rm -f "$job"
     # run lvm scan if udev has settled
 
+    VGS=$(getargs rd_LVM_VG=)
+
     [ -d /etc/lvm ] || mkdir -p /etc/lvm
     # build a list of devices to scan
     lvmdevs=$(
        for f in /tmp/.lvm_scan-*; do
            [ -e "$f" ] || continue
-           echo ${f##/tmp/.lvm_scan-}
+           echo -n "${f##/tmp/.lvm_scan-} "
        done
        )
     {
@@ -19,10 +21,12 @@ if $UDEV_QUEUE_EMPTY >/dev/null 2>&1; then
            printf '"a|^/dev/%s$|", ' $dev;
        done;
        echo '"r/.*/" ]';
+       echo 'types = [ "blkext", 1024 ]'
        echo '}';         
     } > /etc/lvm/lvm.conf
 
-    lvm vgscan
-    lvm vgchange -ay
+    info "Scanning devices $lvmdevs for LVM volume groups $VGS"
+    lvm vgscan 2>&1 | vinfo
+    lvm vgchange -ay $VGS 2>&1 | vinfo
 fi
 
diff --git a/modules.d/90lvm/parse-lvm.sh b/modules.d/90lvm/parse-lvm.sh
new file mode 100644 (file)
index 0000000..00dba38
--- /dev/null
@@ -0,0 +1,6 @@
+initrdargs="$initrdargs rd_NO_LVM rd_LVM_VG" 
+
+if getarg rd_NO_LVM; then
+    rm -f /etc/udev/rules.d/64-lvm*.rules
+fi
+
index 23c5baff36043b67ac09b1f2e096e606ac613035..87becdcd1d944a4aa551d3de1df06041b4595658 100644 (file)
@@ -1,20 +1 @@
-# This file causes block devices with Linux RAID (mdadm) signatures to
-# automatically cause mdadm to be run.
-# See udev(8) for syntax
-
-SUBSYSTEM!="block", GOTO="raid_end"
-ACTION!="add|change", GOTO="raid_end"
-KERNEL=="md/*", GOTO="raid_end"
-
-KERNEL=="md*", IMPORT{program}="vol_id --export $tempnode"
-ENV{ID_FS_TYPE}=="linux_raid_member", \
-    TEST!="/tmp/.mdraid_start-%k", \
-    RUN+="/sbin/mdadm -I $env{DEVNAME}", \
-    RUN+="/bin/sh -c '>/tmp/.mdraid_start-%k; /bin/ln -s /sbin/mdraid_start /initqueue/mdraid_start.sh'"
-
-ENV{ID_FS_TYPE}=="linux_raid_member", \
-    TEST!="/tmp/.mdraid_start-%k", \
-    ATTR{partition}!="?*", \
-    RUN+="/sbin/partx -d $env{DEVNAME}"
-
-LABEL="raid_end"
+SUBSYSTEM=="block", ACTION=="add|change", KERNEL=="md[0-9]*|md_d[0-9]*|md/*", IMPORT{program}="vol_id --export $tempnode"
index edef6b0be5da4f3a2d242bdd17130dc248bc016a..f6efb5608abe5218cc1f4de34df69c08fd474033 100644 (file)
@@ -2,15 +2,20 @@
 # automatically cause mdadm to be run.
 # See udev(8) for syntax
 
-SUBSYSTEM=="block", ACTION=="add", \
-        ENV{ID_FS_TYPE}=="linux_raid_member|isw_raid_member", \
-        TEST!="/tmp/.mdraid_start-%k", \
-       IMPORT{program}="/sbin/mdadm --examine --export $tempnode", \
-       RUN+="/sbin/mdadm -I --no-degraded $env{DEVNAME}", \
-       RUN+="/bin/sh -c '>/tmp/.mdraid_start-%k; /bin/ln -s /sbin/mdraid_start /initqueue/mdraid_start.sh'"
-
-SUBSYSTEM=="block", ACTION=="add", \
-        ENV{ID_FS_TYPE}=="linux_raid_member|isw_raid_member", \
-        TEST!="/tmp/.mdraid_start-%k", \
-       ATTR{partition}!="?*", \
-       RUN+="/sbin/partx -d $env{DEVNAME}"
+ACTION!="add", GOTO="md_inc_end"
+SUBSYSTEM!="block", GOTO="md_inc_end"
+ENV{ID_FS_TYPE}!="linux_raid_member|isw_raid_member", GOTO="md_inc_end"
+
+TEST=="/tmp/.mdraid_start-%k", GOTO="md_inc_end"
+
+IMPORT{program}="/sbin/mdadm --examine --export $tempnode"
+
+# UUID CHECK
+
+LABEL="do_md_inc"
+
+RUN+="/sbin/mdadm -I --no-degraded $env{DEVNAME}", RUN+="/bin/sh -c '>/tmp/.mdraid_start-%k; /bin/ln -s /sbin/mdraid_start /initqueue/mdraid_start.sh'"
+
+ATTR{partition}!="?*", RUN+="/sbin/partx -d $env{DEVNAME}"
+
+LABEL="md_inc_end"
index f679c4b985973d380d6f5b64b0744ba3e1f7671d..38e7654da4435f635882b175ee30312de06307c1 100644 (file)
@@ -2,13 +2,22 @@
 # automatically cause mdadm to be run.
 # See udev(8) for syntax
 
-SUBSYSTEM=="block", ACTION=="add", ENV{ID_FS_TYPE}=="linux_raid_member", \
-        TEST!="/tmp/.mdraid_start-%k", \
-       IMPORT{program}="/sbin/mdadm --examine --export $tempnode", \
-       RUN+="/sbin/mdadm -I $env{DEVNAME}", \
-       RUN+="/bin/sh -c '>/tmp/.mdraid_start-%k; /bin/ln -s /sbin/mdraid_start /initqueue/mdraid_start.sh'"
-
-SUBSYSTEM=="block", ACTION=="add", ENV{ID_FS_TYPE}=="linux_raid_member", \
-        TEST!="/tmp/.mdraid_start-%k", \
-       ATTR{partition}!="?*", \
-       RUN+="/sbin/partx -d $env{DEVNAME}"
+ACTION!="add", GOTO="md_inc_end"
+SUBSYSTEM!="block", GOTO="md_inc_end"
+ENV{ID_FS_TYPE}!="linux_raid_member", GOTO="md_inc_end"
+
+TEST=="/tmp/.mdraid_start-%k", GOTO="md_inc_end"
+
+IMPORT{program}="/sbin/mdadm --examine --export $tempnode"
+
+# UUID CHECK
+
+LABEL="do_md_inc"
+
+RUN+="/sbin/mdadm -I --no-degraded $env{DEVNAME}"
+
+RUN+="/bin/sh -c '>/tmp/.mdraid_start-%k; /bin/ln -s /sbin/mdraid_start /initqueue/mdraid_start.sh'"
+
+ATTR{partition}!="?*", RUN+="/sbin/partx -d $env{DEVNAME}"
+
+LABEL="md_inc_end"
index 0391957333780d6befc7b90f4a3e6633e6fc9331..9c29f77b219fbfcf522ae55f34237590b0ae141f 100755 (executable)
@@ -12,14 +12,16 @@ instmods =drivers/md
 if [ -x /lib/udev/vol_id ]; then
     inst_rules "$moddir/61-mdadm.rules"
 else
-    if mdadm -Q -e imsm /dev/null &> /dev/null; then
-        inst_rules "$moddir/65-md-incremental-imsm.rules"
-    else
-        inst_rules "$moddir/65-md-incremental.rules"
-    fi
     inst_rules 64-md-raid.rules
 fi
 
+if mdadm -Q -e imsm /dev/null &> /dev/null; then
+    inst_rules "$moddir/65-md-incremental-imsm.rules"
+else
+    inst_rules "$moddir/65-md-incremental.rules"
+fi
+
+
 [ -f /etc/mdadm/mdadm.conf ] && inst /etc/mdadm/mdadm.conf /etc/mdadm.conf
 [ -f /etc/mdadm.conf ] && inst /etc/mdadm.conf
 if [ -x  /sbin/mdmon ] ; then
@@ -28,4 +30,4 @@ if [ -x  /sbin/mdmon ] ; then
 fi 
 
 inst "$moddir/mdraid_start.sh" /sbin/mdraid_start
-inst grep
+inst_hook cmdline 30 "$moddir/parse-md.sh"
index 7293dedf243b9f788007cc0026c508f0400caf0d..b63709c1139850b9077e218cea35f6523680bdf3 100755 (executable)
@@ -3,15 +3,16 @@
 if $UDEV_QUEUE_EMPTY >/dev/null 2>&1; then
     [ -h "$job" ] && rm -f "$job"
     # run mdadm if udev has settled
-    mdadm -IRs
+    info "Assembling MD RAID arrays"
+
     # and activate any containers
     for md in /dev/md?*; do
         case $md in
-            /dev/md*p*) ;;
-            *)
-                if mdadm --export --detail $md | grep -q container; then
-                    mdadm -IR $md
-                fi
+           /dev/md*p*) ;;
+           *)
+               info "Starting MD RAID array $md"
+                mdadm -R $md 2>&1 | vinfo
+                mdadm -IR $md 2>&1 | vinfo
         esac
     done
 fi
diff --git a/modules.d/90mdraid/parse-md.sh b/modules.d/90mdraid/parse-md.sh
new file mode 100644 (file)
index 0000000..af89084
--- /dev/null
@@ -0,0 +1,27 @@
+initrdargs="$initrdargs rd_MD_UUID rd_NO_MD" 
+
+if $(getarg rd_NO_MD); then
+    rm /etc/udev/rules.d/65-md-incremental*.rules
+else
+    MD_UUID=$(getargs rd_MD_UUID=)
+
+    # rewrite the md rules to only process the specified raid array
+    if [ -n "$MD_UUID" ]; then
+       for f in /etc/udev/rules.d/65-md-incremental*.rules; do
+           [ -e "$f" ] || continue
+           mv $f ${f}.bak 
+           while read line; do 
+               if [ "${line/UUID CHECK//}" != "$line" ]; then
+                   for uuid in $MD_UUID; do
+                       printf 'ENV{MD_UUID}=="%s", GOTO="do_md_inc"\n' $uuid
+                   done;
+                   printf 'GOTO="md_inc_end"\n';               
+               else
+                   echo $line; 
+               fi
+           done < ${f}.bak > $f
+           rm ${f}.bak 
+       done
+    fi
+fi
+