]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
rootfs-block: only write root argument for block device
authorĐoàn Trần Công Danh <congdanhqx@gmail.com>
Sat, 3 Oct 2020 07:23:26 +0000 (14:23 +0700)
committerHarald Hoyer <harald@hoyer.xyz>
Mon, 5 Oct 2020 15:17:40 +0000 (17:17 +0200)
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

index 987373b4f34ac5ff8cb4926dc6303b34eaecb223..c3982207d950a3ce0eec2d544d7efd589da8339b 100755 (executable)
@@ -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
 }