nix-community / disko

Declarative disk partitioning and formatting using nix [maintainers=@Lassulus @Enzime @iFreilicht]
MIT License
1.88k stars 199 forks source link

ZFS uses incorrect disk in interactive VM when using multiple disks. #885

Open 0x450x6c opened 1 week ago

0x450x6c commented 1 week ago

I'm using following configuration & vmWithDisko:

disko.devices = {
    disk = {
      disk-1 = {
        imageSize = "512110190592";
        type = "disk";
        device = "/dev/disk/by-id/nvme-eui...";
        content = {
          type = "gpt";
          partitions = {
            esp = {
              priority = 1;
              name = "ESP";
              size = "512M";
              type = "EF00";
              content = {
                type = "filesystem";
                format = "vfat";
                mountpoint = "/boot-1";
              };
            };
            special = {
              priority = 2;
              size = "320G";
              content = {
                type = "zfs";
                pool = "zroot";
              };
            };
            swap = {
              priority = 3;
              size = "8G";
              content = {
                type = "swap";
                discardPolicy = "both";
              };
            };
            cache = {
              priority = 4;
              size = "100%";
              content = {
                type = "zfs";
                pool = "zroot";
              };
            };
          };
        };
      };
      disk-2 = {
        imageSize = "512110190592";
        type = "disk";
        device = "/dev/disk/by-id/nvme-eui....";
        content = {
          type = "gpt";
          partitions = {
            esp = {
              priority = 1;
              name = "ESP";
              size = "512M";
              type = "EF00";
              content = {
                type = "filesystem";
                format = "vfat";
                mountpoint = "/boot-2";
              };
            };
            special = {
              priority = 2;
              size = "320G";
              content = {
                type = "zfs";
                pool = "zroot";
              };
            };
            swap = {
              priority = 3;
              size = "8G";
              content = {
                type = "swap";
                discardPolicy = "both";
              };
            };
            cache = {
              priority = 4;
              size = "100%";
              content = {
                type = "zfs";
                pool = "zroot";
              };
            };
          };
        };
      };
      disk-3 = {
        imageSize = "16000900661248";
        type = "disk";
        device = "/dev/disk/by-id/wwn-...";
        content = {
          type = "gpt";
          partitions = {
            esp = {
              priority = 1;
              name = "ESP";
              size = "512M";
              type = "EF00";
              content = {
                type = "filesystem";
                format = "vfat";
                mountpoint = "/boot-3";
              };
            };
            zfs = {
              priority = 2;
              content = {
                type = "zfs";
                pool = "zroot";
              };
            };
          };
        };
      };
      disk-4 = {
        imageSize = "16000900661248";
        type = "disk";
        device = "/dev/disk/by-id/wwn-...";
        content = {
          type = "gpt";
          partitions = {
            esp = {
              priority = 1;
              name = "ESP";
              size = "512M";
              type = "EF00";
              content = {
                type = "filesystem";
                format = "vfat";
                mountpoint = "/boot-4";
              };
            };
            zfs = {
              priority = 2;
              size = "14880G";
              content = {
                type = "zfs";
                pool = "zroot";
              };
            };
          };
        };
      };
    };
    zpool = {
      zroot = {
        options.ashift = "12";
        mode = {
          topology = {
            type = "topology";
            vdev = [
              {
                mode = "mirror";
                members = [
                  "/dev/disk/by-partlabel/disk-disk-3-zfs"
                  "/dev/disk/by-partlabel/disk-disk-4-zfs"
                ];
              }
            ];
            special = {
              mode = "mirror";
              members = [
                "/dev/disk/by-partlabel/disk-disk-1-special"
                "/dev/disk/by-partlabel/disk-disk-2-special"
              ];
            };
            cache = [
              "/dev/disk/by-partlabel/disk-disk-1-cache"
              "/dev/disk/by-partlabel/disk-disk-2-cache"
            ];
          };
        };
      };
    };
  };

Sometimes it works, but mostly hangs on importing ZFS pool.

It seems that is due to this line: https://github.com/nix-community/disko/blob/master/lib/interactive-vm.nix#L65

And can be worked around via:

boot.zfs.devNodes = lib.mkForce "/dev/disk/by-id";
Mic92 commented 1 week ago

Looks like your observation is contracting with this comment?

0x450x6c commented 1 week ago

Yes, /dev/disk/by-id works for me, maybe it will not work in some circumstances, but I did not encounter them.