dracut.sh: add --persistent-policy option
authorHarald Hoyer <harald@redhat.com>
Fri, 16 Aug 2013 09:52:07 +0000 (11:52 +0200)
committerHarald Hoyer <harald@redhat.com>
Fri, 16 Aug 2013 09:52:07 +0000 (11:52 +0200)
--persistent-policy <policy>:
    Use <policy> to address disks and partitions.
    <policy> can be any directory name found in /dev/disk.
    E.g. "by-uuid", "by-label"

dracut-bash-completion.sh
dracut-functions.sh
dracut.8.asc
dracut.sh
modules.d/95rootfs-block/module-setup.sh

index 66b9bc9..f822058 100644 (file)
@@ -40,7 +40,7 @@ _dracut() {
                               --omit-drivers --modules --omit --drivers --filesystems --install
                               --fwdir --libdirs --fscks --add-fstab --mount --device --nofscks
                               --kmoddir --conf --confdir --tmpdir --stdlog --compress --prefix
-                              --kernel-cmdline --sshkey'
+                              --kernel-cmdline --sshkey --persistent-policy'
         )
 
         if __contains_word "$prev" ${OPTS[ARG]}; then
@@ -56,6 +56,9 @@ _dracut() {
                         -a|-m|-o|--add|--modules|--omit)
                                 comps=$(dracut --list-modules 2>/dev/null)
                         ;;
+                        --persistent-policy)
+                                comps=$(cd /dev/disk/; echo *)
+                        ;;
                         --kver)
                                 comps=$(cd /lib/modules; echo [0-9]*)
                         ;;
index 1a73e60..68b0a56 100755 (executable)
@@ -303,7 +303,16 @@ get_persistent_dev() {
     _dev=$(get_maj_min "$1")
     [ -z "$_dev" ] && return
 
-    for i in /dev/mapper/* /dev/disk/by-uuid/* /dev/disk/by-id/*; do
+    for i in \
+        /dev/mapper/* \
+        /dev/disk/$persistent_policy/* \
+        /dev/disk/by-uuid/* \
+        /dev/disk/by-label/* \
+        /dev/disk/by-partuuid/* \
+        /dev/disk/by-partlabel/* \
+        /dev/disk/by-id/* \
+        /dev/disk/by-path/* \
+        ; do
         [[ $i == /dev/mapper/control ]] && continue
         [[ $i == /dev/mapper/mpath* ]] && continue
         _tmp=$(get_maj_min "$i")
@@ -314,6 +323,22 @@ get_persistent_dev() {
     done
 }
 
+shorten_persistent_dev() {
+    local dev="$1"
+    case "$dev" in
+        /dev/disk/by-uuid/*)
+            printf "%s" "UUID=${dev##*/}";;
+        /dev/disk/by-label/*)
+            printf "%s" "LABEL=${dev##*/}";;
+        /dev/disk/by-partuuid/*)
+            printf "%s" "PARTUUID=${dev##*/}";;
+        /dev/disk/by-partlabel/*)
+            printf "%s" "PARTLABEL=${dev##*/}";;
+        *)
+            printf "%s" "$dev";;
+    esac
+}
+
 # find_block_device <mountpoint>
 # Prints the major and minor number of the block device
 # for a given mountpoint.
index 08af94e..714ba85 100644 (file)
@@ -325,6 +325,11 @@ provide a valid _/etc/fstab_.
 **-N, --no-hostonly**::
     Disable Host-Only mode
 
+**--persistent-policy** _<policy>_::
+    Use _<policy>_ to address disks and partitions.
+    _<policy>_ can be any directory name found in /dev/disk.
+    E.g. "by-uuid", "by-label"
+
 **--fstab**::
     Use _/etc/fstab_ instead of _/proc/self/mountinfo_.
 
index d3e750b..d0d1c11 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -132,8 +132,12 @@ Creates initial ramdisk images for preloading modules
                          /usr/lib/dracut/modules.d.
                          Useful when running dracut from a git checkout.
   -H, --hostonly        Host-Only mode: Install only what is needed for
-                         booting the local host instead of a generic host.
+                        booting the local host instead of a generic host.
   -N, --no-hostonly     Disables Host-Only mode
+  --persistent-policy [POLICY]
+                        Use [POLICY] to address disks and partitions.
+                        POLICY can be any directory name found in /dev/disk.
+                        E.g. "by-uuid", "by-label"
   --fstab               Use /etc/fstab to determine the root device.
   --add-fstab [FILE]    Add file to the initramfs fstab
   --mount "[DEV] [MP] [FSTYPE] [FSOPTS]"
@@ -328,6 +332,7 @@ TEMP=$(unset POSIXLY_CORRECT; getopt \
     --long host-only \
     --long no-hostonly \
     --long no-host-only \
+    --long persistent-policy: \
     --long fstab \
     --long help \
     --long bzip2 \
@@ -408,6 +413,8 @@ while :; do
                        hostonly_l="yes" ;;
         -N|--no-hostonly|--no-host-only)
                        hostonly_l="no" ;;
+        --persistent-policy)
+                       persistent_policy="$2"; shift;;
         --fstab)       use_fstab_l="yes" ;;
         -h|--help)     long_usage; exit 1 ;;
         -i|--include)  push include_src "$2"
index 6792f1d..6654b98 100755 (executable)
@@ -13,9 +13,9 @@ depends() {
 cmdline() {
     local dev=/dev/block/$(find_root_block_device)
     if [ -e $dev ]; then
-        printf " root=%s" $(get_persistent_dev "$dev")
-        printf " rootflags=%s" $(find_mp_fsopts /)
-        printf " rootfstype=%s" $(find_mp_fstype /)
+        printf " root=%s" "$(shorten_persistent_dev "$(get_persistent_dev "$dev")")"
+        printf " rootflags=%s" "$(find_mp_fsopts /)"
+        printf " rootfstype=%s" "$(find_mp_fstype /)"
     fi
 }