Package: grub-pc
Version: 2.06-13

Hi,
When ZFS is used for the / or /boot partitions on legacy boot servers (with vdevs using more than one disk/partition), grub-pc's postinst shows this during the configure phase:

    ┌──────────────────┤ Configuring grub-pc ├──────────────────┐
    │ GRUB install devices:                                     │
    │                                                           │
    │  [*] /dev/sda (240057 MB; SAMSUNG_MZ7LM240HMHQ-00005)     │
    │  [*] /dev/sdb (240057 MB; SAMSUNG_MZ7LM240HMHQ-00005)     │
    │  [ ] (??? MB; ???)                                        │
    │  [ ] /dev/md2 (1071 MB; md2)                              │
    │                                                           │
    │                                                           │
    │ <Ok>                             │
    │                                                           │
    └───────────────────────────────────────────────────────────┘

Along with errors:

Unknown device "/dev/": No such device


To reproduce, on a legacy boot server:
* Create a zpool with a mirror vdev using two partitions.
* Create a dataset and use it as /.
* Install Debian Bookworm on the server.
* Run "dpkg-reconfigure grub-pc".

On my test server:
root@localhost:~# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs          tmpfs     1.6G  820K  1.6G   1% /run
zp0/zd0        zfs       216G  1.5G  214G   1% /
tmpfs          tmpfs     7.8G     0  7.8G   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
/dev/md2       ext4      988M   66M  855M   8% /boot
tmpfs          tmpfs     1.6G     0  1.6G   0% /run/user/1000
root@localhost:~# lsblk -f
NAME    FSTYPE            FSVER            LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
sda
├─sda1
├─sda2  linux_raid_member 1.2              md2 371c03a8-59c4-5eb7-7fda-f6f5497ae463 │ └─md2 ext4              1.0              boot 197e5606-e75e-4809-87f9-13fbc42ed36d  854.7M     7% /boot
├─sda3  zfs_member        5000             zp0 8324519610909055574
├─sda4  swap              1                swap-sda4 08d6106d-f50d-4391-8515-5b2b8ffa1d6b                [SWAP]
└─sda5  iso9660           Joliet Extension config-2 2023-06-16-18-40-55-00
sdb
├─sdb1
├─sdb2  linux_raid_member 1.2              md2 371c03a8-59c4-5eb7-7fda-f6f5497ae463 │ └─md2 ext4              1.0              boot 197e5606-e75e-4809-87f9-13fbc42ed36d  854.7M     7% /boot
├─sdb3  zfs_member        5000             zp0 8324519610909055574
└─sdb4  swap              1                swap-sdb4 55b30849-9949-4da0-9738-43e04b40a220                [SWAP]
root@localhost:~# zfs list
NAME      USED  AVAIL     REFER  MOUNTPOINT
zp0      1.42G   214G       24K  none
zp0/zd0  1.42G   214G     1.42G  /
root@localhost:~# zpool list
NAME   SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP DEDUP    HEALTH  ALTROOT zp0    222G  1.42G   221G        -         -     0%     0% 1.00x    ONLINE  -
root@localhost:~# zpool status
  pool: zp0
 state: ONLINE
config:

        NAME        STATE     READ WRITE CKSUM
        zp0         ONLINE       0     0     0
          mirror-0  ONLINE       0     0     0
            sda3    ONLINE       0     0     0
            sdb3    ONLINE       0     0     0

errors: No known data errors
root@localhost:~# cat /etc/fstab
UUID=197e5606-e75e-4809-87f9-13fbc42ed36d    /boot    ext4  defaults    0    0 UUID=08d6106d-f50d-4391-8515-5b2b8ffa1d6b    swap    swap  defaults    0    0 UUID=55b30849-9949-4da0-9738-43e04b40a220    swap    swap  defaults    0    0
root@localhost:~# dpkg-reconfigure grub-pc
# With set -x / set +x added around line 281 of /var/lib/dpkg/info/grub-pc.postinst
+++ grub-probe -t device /
++ partition='/dev/sda3
/dev/sdb3'
++ set +x
+++ grub-probe -t device /boot
++ partition=/dev/md2
++ set +x
+++ grub-probe -t device /boot/grub
++ partition=/dev/md2
++ set +x
Unknown device "/dev/": No such device
Unknown device "/dev/": No such device
Unknown device "/dev/": No such device
Unknown device "/dev/": No such device
grub-pc: Running grub-install ...
Installing for i386-pc platform.

Installation finished. No error reported.
  grub-install success for /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
  grub-install success for /dev/sdb
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.1.0-9-amd64
Found initrd image: /boot/initrd.img-6.1.0-9-amd64
done

My understanding is that the following happens:

* usable_partitions is called: https://salsa.debian.org/grub-team/grub/-/blob/debian/2.06-13/debian/postinst.in#L275 * partition="$(grub-probe -t device "$path" || true)" is called: https://salsa.debian.org/grub-team/grub/-/blob/debian/2.06-13/debian/postinst.in#L281
* It returns this:
  # grub-probe -t device /
  /dev/sda3
  /dev/sdb3
* partition_id="$(device_to_id "$partition" || true)" is called: https://salsa.debian.org/grub-team/grub/-/blob/debian/2.06-13/debian/postinst.in#L285 * device_to_id is called: https://salsa.debian.org/grub-team/grub/-/blob/debian/2.06-13/debian/postinst.in#L95 * readlink -f "$1" is called: https://salsa.debian.org/grub-team/grub/-/blob/debian/2.06-13/debian/postinst.in#L99
* It fails:
  # readlink -f '/dev/sda3
  /dev/sdb3'; echo $?
  1

So, to sum up, when ZFS is used, grub-probe may return two partitions, and "readlink -f 'part1\npart2'" obviously does not work.

Reply via email to