From: Harald Hoyer Date: Mon, 8 Mar 2021 09:12:54 +0000 (+0100) Subject: refactor: factor out label_uuid_to_dev X-Git-Tag: 054~319 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3532978de04c78f53664dad7b37705a49a7ee54;p=thirdparty%2Fdracut.git refactor: factor out label_uuid_to_dev --- diff --git a/modules.d/01fips/fips.sh b/modules.d/01fips/fips.sh index 53d507e91..5717e07a0 100755 --- a/modules.d/01fips/fips.sh +++ b/modules.d/01fips/fips.sh @@ -18,18 +18,8 @@ mount_boot() if [ -n "$boot" ]; then case "$boot" in - LABEL=*) - boot="$(echo $boot | sed 's,/,\\x2f,g')" - boot="/dev/disk/by-label/${boot#LABEL=}" - ;; - UUID=*) - boot="/dev/disk/by-uuid/${boot#UUID=}" - ;; - PARTUUID=*) - boot="/dev/disk/by-partuuid/${boot#PARTUUID=}" - ;; - PARTLABEL=*) - boot="/dev/disk/by-partlabel/${boot#PARTLABEL=}" + LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*) + boot="$(label_uuid_to_dev "$boot")" ;; /dev/*) ;; diff --git a/modules.d/90dmsquash-live/dmsquash-generator.sh b/modules.d/90dmsquash-live/dmsquash-generator.sh index cce29b9cc..1a4070443 100755 --- a/modules.d/90dmsquash-live/dmsquash-generator.sh +++ b/modules.d/90dmsquash-live/dmsquash-generator.sh @@ -16,28 +16,14 @@ fi [ "${liveroot%%:*}" = "live" ] || exit 0 case "$liveroot" in - live:LABEL=*|LABEL=*) \ - root="${root#live:}" - root="${root//\//\\x2f}" - root="live:/dev/disk/by-label/${root#LABEL=}" + live:LABEL=*|LABEL=* | live:UUID=*|UUID=* | live:PARTUUID=*|PARTUUID=* | live:PARTLABEL=*|PARTLABEL=*) + root="live:$(label_uuid_to_dev "${root#live:}")" rootok=1 ;; - live:CDLABEL=*|CDLABEL=*) \ + live:CDLABEL=*|CDLABEL=*) root="${root#live:}" - root="${root//\//\\x2f}" + root="$(echo "$root" | sed 's,/,\\x2f,g;s, ,\\x20,g')" root="live:/dev/disk/by-label/${root#CDLABEL=}" rootok=1 ;; - live:UUID=*|UUID=*) \ - root="${root#live:}" - root="live:/dev/disk/by-uuid/${root#UUID=}" - rootok=1 ;; - live:PARTUUID=*|PARTUUID=*) \ - root="${root#live:}" - root="live:/dev/disk/by-partuuid/${root#PARTUUID=}" - rootok=1 ;; - live:PARTLABEL=*|PARTLABEL=*) \ - root="${root#live:}" - root="live:/dev/disk/by-partlabel/${root#PARTLABEL=}" - rootok=1 ;; live:/*.[Ii][Ss][Oo]|/*.[Ii][Ss][Oo]) root="${root#live:}" root="liveiso:${root}" diff --git a/modules.d/90dmsquash-live/parse-dmsquash-live.sh b/modules.d/90dmsquash-live/parse-dmsquash-live.sh index 4d46a3600..7b6c7ce25 100755 --- a/modules.d/90dmsquash-live/parse-dmsquash-live.sh +++ b/modules.d/90dmsquash-live/parse-dmsquash-live.sh @@ -18,28 +18,14 @@ fi modprobe -q loop case "$liveroot" in - live:LABEL=*|LABEL=*) \ - root="${root#live:}" - root="${root//\//\\x2f}" - root="live:/dev/disk/by-label/${root#LABEL=}" + live:LABEL=*|LABEL=* | live:UUID=*|UUID=* | live:PARTUUID=*|PARTUUID=* | live:PARTLABEL=*|PARTLABEL=*) + root="live:$(label_uuid_to_dev "${root#live:}")" rootok=1 ;; - live:CDLABEL=*|CDLABEL=*) \ + live:CDLABEL=*|CDLABEL=*) root="${root#live:}" - root="${root//\//\\x2f}" + root="$(echo "$root" | sed 's,/,\\x2f,g;s, ,\\x20,g')" root="live:/dev/disk/by-label/${root#CDLABEL=}" rootok=1 ;; - live:UUID=*|UUID=*) \ - root="${root#live:}" - root="live:/dev/disk/by-uuid/${root#UUID=}" - rootok=1 ;; - live:PARTUUID=*|PARTUUID=*) \ - root="${root#live:}" - root="live:/dev/disk/by-partuuid/${root#PARTUUID=}" - rootok=1 ;; - live:PARTLABEL=*|PARTLABEL=*) \ - root="${root#live:}" - root="live:/dev/disk/by-partlabel/${root#PARTLABEL=}" - rootok=1 ;; live:/*.[Ii][Ss][Oo]|/*.[Ii][Ss][Oo]) root="${root#live:}" root="liveiso:${root}" diff --git a/modules.d/91zipl/parse-zipl.sh b/modules.d/91zipl/parse-zipl.sh index ddab0ea96..a2be9f510 100755 --- a/modules.d/91zipl/parse-zipl.sh +++ b/modules.d/91zipl/parse-zipl.sh @@ -9,12 +9,22 @@ if [ -n "$zipl_arg" ] ; then LABEL=*) \ zipl_env="ENV{ID_FS_LABEL}" zipl_val=${zipl_arg#LABEL=} - zipl_arg="/dev/disk/by-label/${zipl_val}" + zipl_arg="$(label_uuid_to_dev "${zipl_val}")" ;; UUID=*) \ zipl_env="ENV{ID_FS_UUID}" zipl_val=${zipl_arg#UUID=} - zipl_arg="/dev/disk/by-uuid/${zipl_val}" + zipl_arg="$(label_uuid_to_dev "${zipl_val}")" + ;; + PARTLABEL=*) \ + zipl_env="ENV{ID_FS_PARTLABEL}" + zipl_val=${zipl_arg#PARTLABEL=} + zipl_arg="$(label_uuid_to_dev "${zipl_val}")" + ;; + PARTUUID=*) \ + zipl_env="ENV{ID_FS_PARTUUID}" + zipl_val=${zipl_arg#PARTUUID=} + zipl_arg="$(label_uuid_to_dev "${zipl_val}")" ;; /dev/mapper/*) \ zipl_env="ENV{DM_NAME}" diff --git a/modules.d/95resume/parse-resume.sh b/modules.d/95resume/parse-resume.sh index a3beb9553..e525aa291 100755 --- a/modules.d/95resume/parse-resume.sh +++ b/modules.d/95resume/parse-resume.sh @@ -7,17 +7,8 @@ else unset resume fi -case "$resume" in - LABEL=*) \ - resume="$(echo $resume | sed 's,/,\\x2f,g')" - resume="/dev/disk/by-label/${resume#LABEL=}" ;; - UUID=*) \ - resume="/dev/disk/by-uuid/${resume#UUID=}" ;; - PARTUUID=*) \ - resume="/dev/disk/by-partuuid/${resume#PARTUUID=}" ;; - PARTLABEL=*) \ - resume="/dev/disk/by-partlabel/${resume#PARTLABEL=}" ;; -esac + +resume="$(label_uuid_to_dev "$resume")" if splash=$(getarg splash=); then export splash diff --git a/modules.d/95rootfs-block/parse-block.sh b/modules.d/95rootfs-block/parse-block.sh index 2905a1e0b..72c0a9566 100755 --- a/modules.d/95rootfs-block/parse-block.sh +++ b/modules.d/95rootfs-block/parse-block.sh @@ -1,29 +1,11 @@ #!/bin/sh -case "$root" in - block:LABEL=*|LABEL=*) - root="${root#block:}" - root="$(echo $root | sed 's,/,\\x2f,g')" - root="block:/dev/disk/by-label/${root#LABEL=}" - rootok=1 ;; - block:UUID=*|UUID=*) - root="${root#block:}" - root="${root#UUID=}" - root="$(echo $root | tr "[:upper:]" "[:lower:]")" - root="block:/dev/disk/by-uuid/${root#UUID=}" - rootok=1 ;; - block:PARTUUID=*|PARTUUID=*) - root="${root#block:}" - root="${root#PARTUUID=}" - root="$(echo $root | tr "[:upper:]" "[:lower:]")" - root="block:/dev/disk/by-partuuid/${root}" - rootok=1 ;; - block:PARTLABEL=*|PARTLABEL=*) - root="${root#block:}" - root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}" +case "${root#block:}" in + LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*) + root="block:$(label_uuid_to_dev "$root")" rootok=1 ;; /dev/*) - root="block:${root}" + root="block:${root#block:}" rootok=1 ;; esac diff --git a/modules.d/95rootfs-block/rootfallback.sh b/modules.d/95rootfs-block/rootfallback.sh index f3bc7795e..2fa6ba39b 100755 --- a/modules.d/95rootfs-block/rootfallback.sh +++ b/modules.d/95rootfs-block/rootfallback.sh @@ -3,29 +3,7 @@ type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh for root in $(getargs rootfallback=); do - case "$root" in - block:LABEL=*|LABEL=*) - root="${root#block:}" - root="$(echo $root | sed 's,/,\\x2f,g')" - root="/dev/disk/by-label/${root#LABEL=}" - ;; - block:UUID=*|UUID=*) - root="${root#block:}" - root="${root#UUID=}" - root="$(echo $root | tr "[:upper:]" "[:lower:]")" - root="/dev/disk/by-uuid/${root#UUID=}" - ;; - block:PARTUUID=*|PARTUUID=*) - root="${root#block:}" - root="${root#PARTUUID=}" - root="$(echo $root | tr "[:upper:]" "[:lower:]")" - root="/dev/disk/by-partuuid/${root}" - ;; - block:PARTLABEL=*|PARTLABEL=*) - root="${root#block:}" - root="/dev/disk/by-partlabel/${root#PARTLABEL=}" - ;; - esac + root=$(label_uuid_to_dev "$root") if ! [ -b "$root" ]; then warn "Could not find rootfallback $root" diff --git a/modules.d/98dracut-systemd/dracut-cmdline.sh b/modules.d/98dracut-systemd/dracut-cmdline.sh index 934c5ba0c..ac3f26075 100755 --- a/modules.d/98dracut-systemd/dracut-cmdline.sh +++ b/modules.d/98dracut-systemd/dracut-cmdline.sh @@ -49,23 +49,9 @@ source_hook cmdline [ -f /lib/dracut/parse-resume.sh ] && . /lib/dracut/parse-resume.sh -case "${root}${root_unset}" in - block:LABEL=*|LABEL=*) - root="${root#block:}" - root="$(echo $root | sed 's,/,\\x2f,g')" - root="block:/dev/disk/by-label/${root#LABEL=}" - rootok=1 ;; - block:UUID=*|UUID=*) - root="${root#block:}" - root="block:/dev/disk/by-uuid/${root#UUID=}" - rootok=1 ;; - block:PARTUUID=*|PARTUUID=*) - root="${root#block:}" - root="block:/dev/disk/by-partuuid/${root#PARTUUID=}" - rootok=1 ;; - block:PARTLABEL=*|PARTLABEL=*) - root="${root#block:}" - root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}" +case "${root#block:}${root_unset}" in + LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*) + root="block:$(label_uuid_to_dev "$root")" rootok=1 ;; /dev/*) root="block:${root}" diff --git a/modules.d/98dracut-systemd/rootfs-generator.sh b/modules.d/98dracut-systemd/rootfs-generator.sh index bb376c0f6..a9fef9c90 100755 --- a/modules.d/98dracut-systemd/rootfs-generator.sh +++ b/modules.d/98dracut-systemd/rootfs-generator.sh @@ -91,23 +91,9 @@ generator_fsck_after_pre_mount() } root=$(getarg root=) -case "$root" in - block:LABEL=*|LABEL=*) - root="${root#block:}" - root="$(echo $root | sed 's,/,\\x2f,g')" - root="block:/dev/disk/by-label/${root#LABEL=}" - rootok=1 ;; - block:UUID=*|UUID=*) - root="${root#block:}" - root="block:/dev/disk/by-uuid/${root#UUID=}" - rootok=1 ;; - block:PARTUUID=*|PARTUUID=*) - root="${root#block:}" - root="block:/dev/disk/by-partuuid/${root#PARTUUID=}" - rootok=1 ;; - block:PARTLABEL=*|PARTLABEL=*) - root="${root#block:}" - root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}" +case "${root#block:}" in + LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*) + root="block:$(label_uuid_to_dev "$root")" rootok=1 ;; /dev/nfs) # ignore legacy /dev/nfs ;; diff --git a/modules.d/98usrmount/mount-usr.sh b/modules.d/98usrmount/mount-usr.sh index 1699604c2..b8da85bfa 100755 --- a/modules.d/98usrmount/mount-usr.sh +++ b/modules.d/98usrmount/mount-usr.sh @@ -55,16 +55,8 @@ mount_usr() while read _dev _mp _fs _opts _freq _passno || [ -n "$_dev" ]; do [ "${_dev%%#*}" != "$_dev" ] && continue if [ "$_mp" = "/usr" ]; then - case "$_dev" in - LABEL=*) - _dev="$(echo $_dev | sed 's,/,\\x2f,g')" - _dev="/dev/disk/by-label/${_dev#LABEL=}" - ;; - UUID=*) - _dev="${_dev#block:}" - _dev="/dev/disk/by-uuid/${_dev#UUID=}" - ;; - esac + _dev="$(label_uuid_to_dev "$_dev")" + if strstr "$_opts" "subvol=" && \ [ "${root#block:}" -ef $_dev ] && \ [ -n "$rflags" ]; then diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh index c0b3e4aac..b9be2b175 100755 --- a/modules.d/99base/dracut-lib.sh +++ b/modules.d/99base/dracut-lib.sh @@ -551,6 +551,25 @@ udevmatch() { esac } +label_uuid_to_dev() { + local _dev + _dev="${1#block:}" + case "$_dev" in + LABEL=*) + echo "/dev/disk/by-label/$(echo "${_dev#LABEL=}" | sed 's,/,\\x2f,g;s, ,\\x20,g')" + ;; + PARTLABEL=*) + echo "/dev/disk/by-partlabel/$(echo "${_dev#PARTLABEL=}" | sed 's,/,\\x2f,g;s, ,\\x20,g')" + ;; + UUID=*) + echo "/dev/disk/by-uuid/$(echo "${_dev#UUID=}" | tr "[:upper:]" "[:lower:]")" + ;; + PARTUUID=*) + echo "/dev/disk/by-partuuid/$(echo "${_dev#PARTUUID=}" | tr "[:upper:]" "[:lower:]")" + ;; + esac +} + # Prints unique path for potential file inside specified directory. It consists # of specified directory, prefix and number at the end which is incremented # until non-existing file is found.