refactor: factor out label_uuid_to_dev

master
Harald Hoyer 2021-03-08 10:12:54 +01:00 committed by Harald Hoyer
parent 40fc0ad40d
commit d3532978de
11 changed files with 56 additions and 150 deletions

View File

@ -18,18 +18,8 @@ mount_boot()


if [ -n "$boot" ]; then if [ -n "$boot" ]; then
case "$boot" in case "$boot" in
LABEL=*) LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
boot="$(echo $boot | sed 's,/,\\x2f,g')" boot="$(label_uuid_to_dev "$boot")"
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=}"
;; ;;
/dev/*) /dev/*)
;; ;;

View File

@ -16,28 +16,14 @@ fi
[ "${liveroot%%:*}" = "live" ] || exit 0 [ "${liveroot%%:*}" = "live" ] || exit 0


case "$liveroot" in case "$liveroot" in
live:LABEL=*|LABEL=*) \ live:LABEL=*|LABEL=* | live:UUID=*|UUID=* | live:PARTUUID=*|PARTUUID=* | live:PARTLABEL=*|PARTLABEL=*)
root="${root#live:}" root="live:$(label_uuid_to_dev "${root#live:}")"
root="${root//\//\\x2f}"
root="live:/dev/disk/by-label/${root#LABEL=}"
rootok=1 ;; rootok=1 ;;
live:CDLABEL=*|CDLABEL=*) \ live:CDLABEL=*|CDLABEL=*)
root="${root#live:}" root="${root#live:}"
root="${root//\//\\x2f}" root="$(echo "$root" | sed 's,/,\\x2f,g;s, ,\\x20,g')"
root="live:/dev/disk/by-label/${root#CDLABEL=}" root="live:/dev/disk/by-label/${root#CDLABEL=}"
rootok=1 ;; 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]) live:/*.[Ii][Ss][Oo]|/*.[Ii][Ss][Oo])
root="${root#live:}" root="${root#live:}"
root="liveiso:${root}" root="liveiso:${root}"

View File

@ -18,28 +18,14 @@ fi
modprobe -q loop modprobe -q loop


case "$liveroot" in case "$liveroot" in
live:LABEL=*|LABEL=*) \ live:LABEL=*|LABEL=* | live:UUID=*|UUID=* | live:PARTUUID=*|PARTUUID=* | live:PARTLABEL=*|PARTLABEL=*)
root="${root#live:}" root="live:$(label_uuid_to_dev "${root#live:}")"
root="${root//\//\\x2f}"
root="live:/dev/disk/by-label/${root#LABEL=}"
rootok=1 ;; rootok=1 ;;
live:CDLABEL=*|CDLABEL=*) \ live:CDLABEL=*|CDLABEL=*)
root="${root#live:}" root="${root#live:}"
root="${root//\//\\x2f}" root="$(echo "$root" | sed 's,/,\\x2f,g;s, ,\\x20,g')"
root="live:/dev/disk/by-label/${root#CDLABEL=}" root="live:/dev/disk/by-label/${root#CDLABEL=}"
rootok=1 ;; 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]) live:/*.[Ii][Ss][Oo]|/*.[Ii][Ss][Oo])
root="${root#live:}" root="${root#live:}"
root="liveiso:${root}" root="liveiso:${root}"

View File

@ -9,12 +9,22 @@ if [ -n "$zipl_arg" ] ; then
LABEL=*) \ LABEL=*) \
zipl_env="ENV{ID_FS_LABEL}" zipl_env="ENV{ID_FS_LABEL}"
zipl_val=${zipl_arg#LABEL=} zipl_val=${zipl_arg#LABEL=}
zipl_arg="/dev/disk/by-label/${zipl_val}" zipl_arg="$(label_uuid_to_dev "${zipl_val}")"
;; ;;
UUID=*) \ UUID=*) \
zipl_env="ENV{ID_FS_UUID}" zipl_env="ENV{ID_FS_UUID}"
zipl_val=${zipl_arg#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/*) \ /dev/mapper/*) \
zipl_env="ENV{DM_NAME}" zipl_env="ENV{DM_NAME}"

View File

@ -7,17 +7,8 @@ else
unset resume unset resume
fi fi


case "$resume" in
LABEL=*) \ resume="$(label_uuid_to_dev "$resume")"
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


if splash=$(getarg splash=); then if splash=$(getarg splash=); then
export splash export splash

View File

@ -1,29 +1,11 @@
#!/bin/sh #!/bin/sh


case "$root" in case "${root#block:}" in
block:LABEL=*|LABEL=*) LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
root="${root#block:}" root="block:$(label_uuid_to_dev "$root")"
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=}"
rootok=1 ;; rootok=1 ;;
/dev/*) /dev/*)
root="block:${root}" root="block:${root#block:}"
rootok=1 ;; rootok=1 ;;
esac esac



View File

@ -3,29 +3,7 @@
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh


for root in $(getargs rootfallback=); do for root in $(getargs rootfallback=); do
case "$root" in root=$(label_uuid_to_dev "$root")
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


if ! [ -b "$root" ]; then if ! [ -b "$root" ]; then
warn "Could not find rootfallback $root" warn "Could not find rootfallback $root"

View File

@ -49,23 +49,9 @@ source_hook cmdline


[ -f /lib/dracut/parse-resume.sh ] && . /lib/dracut/parse-resume.sh [ -f /lib/dracut/parse-resume.sh ] && . /lib/dracut/parse-resume.sh


case "${root}${root_unset}" in case "${root#block:}${root_unset}" in
block:LABEL=*|LABEL=*) LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
root="${root#block:}" root="block:$(label_uuid_to_dev "$root")"
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=}"
rootok=1 ;; rootok=1 ;;
/dev/*) /dev/*)
root="block:${root}" root="block:${root}"

View File

@ -91,23 +91,9 @@ generator_fsck_after_pre_mount()
} }


root=$(getarg root=) root=$(getarg root=)
case "$root" in case "${root#block:}" in
block:LABEL=*|LABEL=*) LABEL=* | UUID=* | PARTUUID=* | PARTLABEL=*)
root="${root#block:}" root="block:$(label_uuid_to_dev "$root")"
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=}"
rootok=1 ;; rootok=1 ;;
/dev/nfs) # ignore legacy /dev/nfs /dev/nfs) # ignore legacy /dev/nfs
;; ;;

View File

@ -55,16 +55,8 @@ mount_usr()
while read _dev _mp _fs _opts _freq _passno || [ -n "$_dev" ]; do while read _dev _mp _fs _opts _freq _passno || [ -n "$_dev" ]; do
[ "${_dev%%#*}" != "$_dev" ] && continue [ "${_dev%%#*}" != "$_dev" ] && continue
if [ "$_mp" = "/usr" ]; then if [ "$_mp" = "/usr" ]; then
case "$_dev" in _dev="$(label_uuid_to_dev "$_dev")"
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
if strstr "$_opts" "subvol=" && \ if strstr "$_opts" "subvol=" && \
[ "${root#block:}" -ef $_dev ] && \ [ "${root#block:}" -ef $_dev ] && \
[ -n "$rflags" ]; then [ -n "$rflags" ]; then

View File

@ -551,6 +551,25 @@ udevmatch() {
esac 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 # Prints unique path for potential file inside specified directory. It consists
# of specified directory, prefix and number at the end which is incremented # of specified directory, prefix and number at the end which is incremented
# until non-existing file is found. # until non-existing file is found.