From: Harald Hoyer Date: Wed, 15 Jul 2009 16:21:10 +0000 (+0200) Subject: add command line parameters to specify exact actions for root assembly X-Git-Tag: 0.5~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f874872fc2ec976888a5a3c430dac8924fa009ec;p=thirdparty%2Fdracut.git add command line parameters to specify exact actions for root assembly LVM rd_NO_LVM disable LVM detection rd_LVM_VG= only activate the volume groups with the given name crypto LUKS rd_NO_LUKS disable crypto LUKS detection rd_LUKS_UUID= only activate the LUKS partitions with the given UUID MD rd_NO_MD disable MD RAID detection rd_MD_UUID= only activate the raid sets with the given UUID DMRAID rd_NO_DM disable DM RAID detection rd_DM_UUID= only activate the raid sets with the given UUID --- diff --git a/dracut.8 b/dracut.8 index 4d6ac29b5..e121bf5b3 100644 --- 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= +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= +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= +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= +only activate the raid sets with the given UUID + .SH DHCP .TP .B root=dhcp diff --git a/modules.d/50plymouth/cryptroot-ask.sh b/modules.d/50plymouth/cryptroot-ask.sh index 2d0f3572f..75c6550dd 100755 --- a/modules.d/50plymouth/cryptroot-ask.sh +++ b/modules.d/50plymouth/cryptroot-ask.sh @@ -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 diff --git a/modules.d/90crypt/cryptroot-ask.sh b/modules.d/90crypt/cryptroot-ask.sh index d87c2ea88..5b5d895f7 100755 --- a/modules.d/90crypt/cryptroot-ask.sh +++ b/modules.d/90crypt/cryptroot-ask.sh @@ -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 diff --git a/modules.d/90crypt/install b/modules.d/90crypt/install index a3a856d02..9ffe90e4f 100755 --- a/modules.d/90crypt/install +++ b/modules.d/90crypt/install @@ -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 index 000000000..4a39c2138 --- /dev/null +++ b/modules.d/90crypt/parse-crypt.sh @@ -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 + diff --git a/modules.d/90dmraid/dmraid.sh b/modules.d/90dmraid/dmraid.sh index f6cb26fd4..f706e57b0 100755 --- a/modules.d/90dmraid/dmraid.sh +++ b/modules.d/90dmraid/dmraid.sh @@ -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 index 000000000..a047d2d12 --- /dev/null +++ b/modules.d/90dmraid/parse-dm.sh @@ -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 diff --git a/modules.d/90lvm/install b/modules.d/90lvm/install index cba321bb0..ad5e485bd 100755 --- a/modules.d/90lvm/install +++ b/modules.d/90lvm/install @@ -7,3 +7,4 @@ else fi inst "$moddir/lvm_scan.sh" /sbin/lvm_scan +inst_hook cmdline 30 "$moddir/parse-lvm.sh" diff --git a/modules.d/90lvm/lvm_scan.sh b/modules.d/90lvm/lvm_scan.sh index 489c7a145..81c48c037 100755 --- a/modules.d/90lvm/lvm_scan.sh +++ b/modules.d/90lvm/lvm_scan.sh @@ -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 index 000000000..00dba38a6 --- /dev/null +++ b/modules.d/90lvm/parse-lvm.sh @@ -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 + diff --git a/modules.d/90mdraid/61-mdadm.rules b/modules.d/90mdraid/61-mdadm.rules index 23c5baff3..87becdcd1 100644 --- a/modules.d/90mdraid/61-mdadm.rules +++ b/modules.d/90mdraid/61-mdadm.rules @@ -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" diff --git a/modules.d/90mdraid/65-md-incremental-imsm.rules b/modules.d/90mdraid/65-md-incremental-imsm.rules index edef6b0be..f6efb5608 100644 --- a/modules.d/90mdraid/65-md-incremental-imsm.rules +++ b/modules.d/90mdraid/65-md-incremental-imsm.rules @@ -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" diff --git a/modules.d/90mdraid/65-md-incremental.rules b/modules.d/90mdraid/65-md-incremental.rules index f679c4b98..38e7654da 100644 --- a/modules.d/90mdraid/65-md-incremental.rules +++ b/modules.d/90mdraid/65-md-incremental.rules @@ -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" diff --git a/modules.d/90mdraid/install b/modules.d/90mdraid/install index 039195733..9c29f77b2 100755 --- a/modules.d/90mdraid/install +++ b/modules.d/90mdraid/install @@ -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" diff --git a/modules.d/90mdraid/mdraid_start.sh b/modules.d/90mdraid/mdraid_start.sh index 7293dedf2..b63709c11 100755 --- a/modules.d/90mdraid/mdraid_start.sh +++ b/modules.d/90mdraid/mdraid_start.sh @@ -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 index 000000000..af89084d7 --- /dev/null +++ b/modules.d/90mdraid/parse-md.sh @@ -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 +