Browse Source

refactor: factor out label_uuid_to_dev

master
Harald Hoyer 4 years ago committed by Harald Hoyer
parent
commit
d3532978de
  1. 14
      modules.d/01fips/fips.sh
  2. 22
      modules.d/90dmsquash-live/dmsquash-generator.sh
  3. 22
      modules.d/90dmsquash-live/parse-dmsquash-live.sh
  4. 14
      modules.d/91zipl/parse-zipl.sh
  5. 13
      modules.d/95resume/parse-resume.sh
  6. 26
      modules.d/95rootfs-block/parse-block.sh
  7. 24
      modules.d/95rootfs-block/rootfallback.sh
  8. 20
      modules.d/98dracut-systemd/dracut-cmdline.sh
  9. 20
      modules.d/98dracut-systemd/rootfs-generator.sh
  10. 12
      modules.d/98usrmount/mount-usr.sh
  11. 19
      modules.d/99base/dracut-lib.sh

14
modules.d/01fips/fips.sh

@ -18,18 +18,8 @@ mount_boot() @@ -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/*)
;;

22
modules.d/90dmsquash-live/dmsquash-generator.sh

@ -16,28 +16,14 @@ fi @@ -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}"

22
modules.d/90dmsquash-live/parse-dmsquash-live.sh

@ -18,28 +18,14 @@ fi @@ -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}"

14
modules.d/91zipl/parse-zipl.sh

@ -9,12 +9,22 @@ if [ -n "$zipl_arg" ] ; then @@ -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}"

13
modules.d/95resume/parse-resume.sh

@ -7,17 +7,8 @@ else @@ -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

26
modules.d/95rootfs-block/parse-block.sh

@ -1,29 +1,11 @@ @@ -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


24
modules.d/95rootfs-block/rootfallback.sh

@ -3,29 +3,7 @@ @@ -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"

20
modules.d/98dracut-systemd/dracut-cmdline.sh

@ -49,23 +49,9 @@ source_hook cmdline @@ -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}"

20
modules.d/98dracut-systemd/rootfs-generator.sh

@ -91,23 +91,9 @@ generator_fsck_after_pre_mount() @@ -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
;;

12
modules.d/98usrmount/mount-usr.sh

@ -55,16 +55,8 @@ mount_usr() @@ -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

19
modules.d/99base/dracut-lib.sh

@ -551,6 +551,25 @@ udevmatch() { @@ -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.

Loading…
Cancel
Save