From 811c814677b83874fb631f6c07576765303b615a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Sat, 3 Oct 2020 14:23:26 +0700
Subject: [PATCH] rootfs-block: only write root argument for block device
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Some filesystem (e.g. ZFS, and btrfs subvolumes) don't use block
devices. Should they be mounted as `/`, `find_root_block_device`
yields nothing, hence dracut will append this problematic argument
to kernel cmdline:
root=/dev/block
On a machine that employ root ZFS on LUKS, which was setup with
an OpenPGP-encrypted key file, this argument renders that machine
unbootable. Remove that `root=/dev/block` manually could boot the
machine.
Let check if that device is a block device before write down `root`
argument. This is consistent with the check for block device in
`find_block_device`.
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
---
modules.d/95rootfs-block/module-setup.sh | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/modules.d/95rootfs-block/module-setup.sh b/modules.d/95rootfs-block/module-setup.sh
index 987373b4..c3982207 100755
--- a/modules.d/95rootfs-block/module-setup.sh
+++ b/modules.d/95rootfs-block/module-setup.sh
@@ -30,7 +30,8 @@ cmdline_journal() {
}
cmdline_rootfs() {
- local _dev=/dev/block/$(find_root_block_device)
+ local _block=$(find_root_block_device)
+ local _dev=/dev/block/$_block
local _fstype _flags _subvol
# "--no-hostonly-default-device" can result in empty root_devs
@@ -38,17 +39,21 @@ cmdline_rootfs() {
return
fi
- if [ -e $_dev ]; then
+ if [ -n "$_block" -a -b $_dev ]; then
printf " root=%s" "$(shorten_persistent_dev "$(get_persistent_dev "$_dev")")"
- _fstype="$(find_mp_fstype /)"
- _flags="$(find_mp_fsopts /)"
+ fi
+ _fstype="$(find_mp_fstype /)"
+ _flags="$(find_mp_fsopts /)"
+ if [ -n "$_fstype" ]; then
printf " rootfstype=%s" "$_fstype"
- if [[ $use_fstab != yes ]] && [[ $_fstype = btrfs ]]; then
- _subvol=$(findmnt -e -v -n -o FSROOT --target /) \
- && _subvol=${_subvol#/}
- _flags="$_flags,${_subvol:+subvol=$_subvol}"
- fi
- printf " rootflags=%s" "${_flags#,}"
+ fi
+ if [[ $use_fstab != yes ]] && [[ $_fstype = btrfs ]]; then
+ _subvol=$(findmnt -e -v -n -o FSROOT --target /) \
+ && _subvol=${_subvol#/}
+ _flags="$_flags${_subvol:+,subvol=$_subvol}"
+ fi
+ if [ -n "$_flags" ]; then
+ printf " rootflags=%s" "$_flags"
fi
}