From: Harald Hoyer Date: Fri, 11 Aug 2017 09:30:11 +0000 (+0200) Subject: crypt: handle rd.luks.name X-Git-Tag: 046~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65f78f3d74b3467565aa242267e4639cd0ddd7fa;p=thirdparty%2Fdracut.git crypt: handle rd.luks.name systemd supports renaming of dm devices with rd.luks.name. Honor the kernel command line parameter. --- diff --git a/modules.d/90crypt/parse-crypt.sh b/modules.d/90crypt/parse-crypt.sh index 5bda00637..8a0db02b5 100755 --- a/modules.d/90crypt/parse-crypt.sh +++ b/modules.d/90crypt/parse-crypt.sh @@ -2,6 +2,30 @@ type crypttab_contains >/dev/null 2>&1 || . /lib/dracut-crypt-lib.sh + +_cryptgetargsname() { + debug_off + local _o _found _key + unset _o + unset _found + CMDLINE=$(getcmdline) + _key="$1" + set -- + for _o in $CMDLINE; do + if [ "$_o" = "$_key" ]; then + _found=1; + elif [ "${_o%=*}" = "${_key%=}" ]; then + [ -n "${_o%=*}" ] && set -- "$@" "${_o#*=}"; + _found=1; + fi + done + if [ -n "$_found" ]; then + [ $# -gt 0 ] && printf '%s' "$*" + return 0 + fi + return 1; +} + if ! getargbool 1 rd.luks -d -n rd_NO_LUKS; then info "rd.luks=0: removing cryptoluks activation" rm -f -- /etc/udev/rules.d/70-luks.rules @@ -15,8 +39,8 @@ else tout=$(getarg rd.luks.key.tout) if [ -e /etc/crypttab ]; then - while read _mapper _dev _rest ; do - set_systemd_timeout_for_dev $_dev + while read -r _ _dev _ || [ -n "$_dev" ]; do + set_systemd_timeout_for_dev "$_dev" done < /etc/crypttab fi @@ -24,23 +48,29 @@ else for luksid in $LUKS; do luksid=${luksid##luks-} + if luksname=$(_cryptgetargsname "rd.luks.name=$luksid="); then + luksname="${luksname#$luksid=}" + else + luksname="luks-$luksid" + fi if [ -z "$DRACUT_SYSTEMD" ]; then { printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", ' - printf -- 'ENV{ID_FS_UUID}=="*%s*", ' $luksid - printf -- 'RUN+="%s --settled --unique --onetime ' $(command -v initqueue) - printf -- '--name cryptroot-ask-%%k %s ' $(command -v cryptroot-ask) - printf -- '$env{DEVNAME} luks-$env{ID_FS_UUID} %s"\n' $tout + printf -- 'ENV{ID_FS_UUID}=="*%s*", ' "$luksid" + printf -- 'RUN+="%s --settled --unique --onetime ' "$(command -v initqueue)" + printf -- '--name cryptroot-ask-%%k %s ' "$(command -v cryptroot-ask)" + printf -- '$env{DEVNAME} %s %s"\n' "$luksname" "$tout" } >> /etc/udev/rules.d/70-luks.rules.new else + luksname=$(dev_unit_name "$luksname") if ! crypttab_contains "$luksid"; then { printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", ' - printf -- 'ENV{ID_FS_UUID}=="*%s*", ' $luksid - printf -- 'RUN+="%s --settled --unique --onetime ' $(command -v initqueue) - printf -- '--name systemd-cryptsetup-%%k %s start ' $(command -v systemctl) - printf -- 'systemd-cryptsetup@luks$$(dev_unit_name -$env{ID_FS_UUID}).service"\n' + printf -- 'ENV{ID_FS_UUID}=="*%s*", ' "$luksid" + printf -- 'RUN+="%s --settled --unique --onetime ' "$(command -v initqueue)" + printf -- '--name systemd-cryptsetup-%%k %s start ' "$(command -v systemctl)" + printf -- 'systemd-cryptsetup@%s.service"\n' "$luksname" } >> /etc/udev/rules.d/70-luks.rules.new fi fi @@ -48,25 +78,25 @@ else uuid=$luksid while [ "$uuid" != "${uuid#*-}" ]; do uuid=${uuid%%-*}${uuid#*-}; done printf -- '[ -e /dev/disk/by-id/dm-uuid-CRYPT-LUKS?-*%s*-* ] || exit 1\n' $uuid \ - >> $hookdir/initqueue/finished/90-crypt.sh + >> "$hookdir/initqueue/finished/90-crypt.sh" { printf -- '[ -e /dev/disk/by-uuid/*%s* ] || ' $luksid printf -- 'warn "crypto LUKS UUID "%s" not found"\n' $luksid - } >> $hookdir/emergency/90-crypt.sh + } >> "$hookdir/emergency/90-crypt.sh" done elif getargbool 0 rd.auto; then if [ -z "$DRACUT_SYSTEMD" ]; then { - printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", RUN+="%s ' $(command -v initqueue) + printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", RUN+="%s ' "$(command -v initqueue)" printf -- '--unique --settled --onetime --name cryptroot-ask-%%k ' - printf -- '%s $env{DEVNAME} luks-$env{ID_FS_UUID} %s"\n' $(command -v cryptroot-ask) $tout + printf -- '%s $env{DEVNAME} luks-$env{ID_FS_UUID} %s"\n' "$(command -v cryptroot-ask)" "$tout" } >> /etc/udev/rules.d/70-luks.rules.new else { - printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", RUN+="%s ' $(command -v initqueue) + printf -- 'ENV{ID_FS_TYPE}=="crypto_LUKS", RUN+="%s ' "$(command -v initqueue)" printf -- '--unique --settled --onetime --name crypt-run-generator-%%k ' - printf -- '%s $env{DEVNAME} luks-$env{ID_FS_UUID}"\n' $(command -v crypt-run-generator) + printf -- '%s $env{DEVNAME} luks-$env{ID_FS_UUID}"\n' "$(command -v crypt-run-generator)" } >> /etc/udev/rules.d/70-luks.rules.new fi fi