nix-community / disko

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

Second zfs zpool have to import manually. #359

Open fud opened 1 year ago

fud commented 1 year ago

I have two pools in my configuration as can been seen in my config. After failing to boot I dropped into a root shell and got info from systemctl for the zfs import service and it said that pool (zstorage in my config) had to be import with a zpool import -f zstorage as it had been created on another machine.

I wasn't expecting to manually have to do that.

Config:

{ disks ? [
  "/dev/disk/by-id/ata-Samsung_SSD_850_EVO_500GB_S21GNXAG805611X"
  "/dev/disk/by-id/ata-Samsung_SSD_860_EVO_500GB_S4BENS0N804509D"
  "/dev/disk/by-id/ata-Samsung_SSD_860_QVO_1TB_S4CZNF0M710674E"
  "/dev/disk/by-id/ata-Samsung_SSD_860_QVO_1TB_S4CZNF0M710685P"
], ... }: {
  disk = {
    main1 = {
      device = builtins.elemAt disks 0;
      type = "disk";
      content = {
        type = "gpt";
        partitions = {
          ESP = {
            size = "512M";
            type = "EF00";
            content = {
              type = "mdraid";
              name = "boot";
            };
          };
          ZFS = {
            end = "-32G";
            content = {
              type = "zfs";
              pool = "zroot";
            };
          };
          swap = {
            size = "100%";
            content = {
              type = "swap";
              randomEncryption = true;
            };
          };
        };
      };
    };
    main2 = {
      type = "disk";
      device = builtins.elemAt disks 1;
      content = {
        type = "gpt";
        partitions = {
          ESP = {
            size = "512M";
            type = "EF00";
            content = {
              type = "mdraid";
              name = "boot";
            };
          };
          ZFS = {
            end = "-32G";
            content = {
              type = "zfs";
              pool = "zroot";
            };
          };
          swap = {
            size = "100%";
            content = {
              type = "swap";
              randomEncryption = true;
            };
          };
        };
      };
    };
    storage1 = {
      device = builtins.elemAt disks 2;
      type = "disk";
      content = {
        type = "gpt";
        partitions = {
          ZFS = {
            size = "100%";
            content = {
              type = "zfs";
              pool = "zstorage";
            };
          };
        };
      };
    };
    storage2 = {
      type = "disk";
      device = builtins.elemAt disks 3;
      content = {
        type = "gpt";
        partitions = {
          ZFS = {
            size = "100%";
            content = {
              type = "zfs";
              pool = "zstorage";
            };
          };
        };
      };
    };
  };
  zpool = {
    zroot = {
      type = "zpool";
      mode = "mirror";
      rootFsOptions = {
        compression = "zstd";
        "com.sun:auto-snapshot" = "false";
      };
      postCreateHook = "zfs snapshot zroot@blank";

      datasets = {
        root = {
          type = "zfs_fs";
          mountpoint = "/";
          options = {
            mountpoint = "legacy";
            "com.sun:auto-snapshot" = "true";
          };
        };
        home = {
          type = "zfs_fs";
          mountpoint = "/home";
           options = {
            mountpoint = "legacy";
            "com.sun:auto-snapshot" = "true";
          };
        };
        var = {
          type = "zfs_fs";
          mountpoint = "/var";
          options = {
            mountpoint = "legacy";
            "com.sun:auto-snapshot" = "true";
          };
          postCreateHook = "mkdir -p /var/data && mkdir -p /var/lib/libvirt";
        };
      };
    };
    zstorage = {
      type = "zpool";
      mode = "mirror";
      rootFsOptions = {
        compression = "zstd";
        canmount = "off";
      };
      postCreateHook = "zfs snapshot zstorage@blank";

      datasets = {
        data = {
          type = "zfs_fs";
          mountpoint = "/var/data";
          options = {
            mountpoint = "legacy";
            "com.sun:auto-snapshot" = "true";
          };
        };
        "virtual/images" = {
          type = "zfs_fs";
          mountpoint = "/var/lib/libvirt/images";
          options = {
            mountpoint = "legacy";
            "com.sun:auto-snapshot" = "true";
          };
        };
        "virtual/snapshots" = {
          type = "zfs_fs";
          mountpoint = "/var/lib/libvirt/snapshots";
          options = {
            mountpoint = "legacy";
            "com.sun:auto-snapshot" = "true";
          };
        };
        "virtual/os" = {
          type = "zfs_fs";
          mountpoint = "/var/lib/libvirt/os";
          options = {
            mountpoint = "legacy";
            "com.sun:auto-snapshot" = "true";
          };
        };
      };
    };
  };

  mdadm = {
    boot = {
      type = "mdadm";
      level = 1;
      metadata = "1.0";
      content = {
        type = "filesystem";
        format = "vfat";
        mountpoint = "/boot";
      };
    };
  };
}
Mic92 commented 1 year ago

Weirdly enough I saw the zpool export in my logs and than had the same issue... Exporting a pool should be enough: https://github.com/openzfs/zfs/blob/4d1b70175cf9bdf927351b1188215604d455f669/cmd/zpool/zpool_main.c#L3121 And we also do a force import for the zfs root fs.