Skip to contentSkip to conversation

zfs: fix root dataset detection on encrypted pools

PATCH In review Christian Schoenebeck via Grub-devel 1 participant 3 messages Feb 9 – Feb 26

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zfs: fix root dataset detection on encrypted pools

grub-probe fails on encrypted zfs pools, causing $rpool variable to be empty. Therefore check variables $rpool and $bootfs to be both non-empty strings before assembling LINUX_ROOT_DEVICE.

If one of the two variables is empty, use "zfs list" as fallback for detecting the zfs root dataset instead.

---
 util/grub.d/10_linux.in | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
util/grub.d/10_linux.in +7 -1
index 07649cd3b..acbd2ab64 100644
@@ -75,7 +75,13 @@ case x"$GRUB_FS" in
     xzfs)
 	rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || zdb -l ${GRUB_DEVICE} | awk -F \' '/ name/ { print $2 }'`
 	bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
-	LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
+	# grub-probe fails on encrypted zfs pools, use zfs list as fallback
+	if [ -n "$rpool" ] && [ -n "$bootfs" ]; then
+	    LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
+	else
+	    root_dataset=`zfs list -Ho mountpoint,name | grep '^/[[:space:]]' | tail -n1 | cut -f 2 2>/dev/null || true`
+	    LINUX_ROOT_DEVICE="ZFS=${root_dataset}"
+	fi
 	;;
 esac
 
Signature · 7 lines
2.47.3


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw
Quoted 11 lines · On Monday, 9 February 2026 19:56:00 CET Christian Schoenebeck wrote:

grub-probe fails on encrypted zfs pools, causing $rpool variable to be empty. Therefore check variables $rpool and $bootfs to be both non-empty strings before assembling LINUX_ROOT_DEVICE.

If one of the two variables is empty, use "zfs list" as fallback for detecting the zfs root dataset instead.

---
 util/grub.d/10_linux.in | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Ping, anyone?

/Christian

Quoted 21 lines
util/grub.d/10_linux.in +7 -1
index 07649cd3b..acbd2ab64 100644
@@ -75,7 +75,13 @@ case x"$GRUB_FS" in
     xzfs)
        rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || zdb -l ${GRUB_DEVICE} | awk -F \' '/ name/ { print $2 }'`
        bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
-       LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
+       # grub-probe fails on encrypted zfs pools, use zfs list as fallback
+       if [ -n "$rpool" ] && [ -n "$bootfs" ]; then
+           LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
+       else
+           root_dataset=`zfs list -Ho mountpoint,name | grep '^/[[:space:]]' | tail -n1 | cut -f 2 2>/dev/null || true`
+           LINUX_ROOT_DEVICE="ZFS=${root_dataset}"
+       fi
        ;;
 esac
 
Signature · 1 line
2.47.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 5 lines · On Wednesday, 18 February 2026 11:28:18 CET Christian Schoenebeck wrote:
Quoted 4 lines · On Monday, 9 February 2026 19:56:00 CET Christian Schoenebeck wrote:

grub-probe fails on encrypted zfs pools, causing $rpool variable to be empty. Therefore check variables $rpool and $bootfs to be both non-empty strings before assembling LINUX_ROOT_DEVICE.

Quoted 8 lines
Quoted 8 lines

If one of the two variables is empty, use "zfs list" as fallback for detecting the zfs root dataset instead.

---

 util/grub.d/10_linux.in | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Ping

Quoted 23 lines

Ping, anyone?

/Christian

Quoted 19 lines
util/grub.d/10_linux.in +7 -1
index 07649cd3b..acbd2ab64 100644
@@ -75,7 +75,13 @@ case x"$GRUB_FS" in
     xzfs)
        rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || zdb -l ${GRUB_DEVICE} | awk -F \' '/ name/ { print $2 }'`
        bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
-       LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
+       # grub-probe fails on encrypted zfs pools, use zfs list as fallback
+       if [ -n "$rpool" ] && [ -n "$bootfs" ]; then
+           LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs%/}"
+       else
+           root_dataset=`zfs list -Ho mountpoint,name | grep '^/[[:space:]]' | tail -n1 | cut -f 2 2>/dev/null || true`
+           LINUX_ROOT_DEVICE="ZFS=${root_dataset}"
+       fi
        ;;
 esac
 
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.47.3

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel