Skip to content

Commit d344496

Browse files
authored
fix: empty fs_uuid on multi-device Btrfs (#440)
On a multi-device Btrfs filesystem `grub-probe --target=device /` prints one device per line (e.g. /dev/vda3 and /dev/vdb). The whole multi-line result was then passed to `grub-probe --device "${root_device}" --target=fs_uuid`, which cannot handle several devices at once and returns an empty string. The blkid fallback fails for the same reason, so grub-btrfs aborts with "Cannot determine UUID". Pipe the device probe through `head -n1` and keep only the first member device. Every member of a Btrfs pool reports the same pool-wide fs UUID, so the first device is sufficient. For single-device setups `head -n1` is a no-op, so existing configurations are unaffected. The same one-line-per-device behaviour applies to a /boot that lives on a multi-device Btrfs, so the identical guard is added to boot_device. Closes #412 Refs #425
1 parent a136a7c commit d344496

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎41_snapshots-btrfs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ fi
120120
# -----------------------------------------------------------
121121

122122
# ---------- Root partition ----------
123-
root_device="$(${grub_probe} --target=device /)" # e.g. /dev/mapper/enc
123+
# head -n1: on a multi-device Btrfs, grub-probe prints one device per line.
124+
# Passing all of them to --device makes the fs_uuid probe return empty, so
125+
# keep only the first device (any member yields the pool-wide fs UUID).
126+
root_device="$(${grub_probe} --target=device / | head -n1)" # e.g. /dev/mapper/enc
124127
root_uuid="$(${grub_probe} --device "${root_device}" --target=fs_uuid 2>/dev/null)" || true
125128

126129
# Fallback when grub-probe fails (encrypted container, detached header…)
@@ -135,7 +138,7 @@ root_uuid_subvolume="$(btrfs subvolume show / 2>/dev/null | \
135138
[ -z "$root_uuid_subvolume" ] && print_error "UUID of the root subvolume is not available"
136139

137140
# ---------- Boot partition ----------
138-
boot_device="$(${grub_probe} --target=device "${boot_directory}")" # e.g. /dev/sdb1
141+
boot_device="$(${grub_probe} --target=device "${boot_directory}" | head -n1)" # e.g. /dev/sdb1; head -n1: see root_device above (multi-device Btrfs)
139142
boot_uuid="$(${grub_probe} --device "${boot_device}" --target=fs_uuid 2>/dev/null)" || true
140143

141144
# Fallback for boot UUID

0 commit comments

Comments
 (0)