Adding a second drive to a disko config

I am using disko in combination with nixos-anywhere to install a VM on proxmox.
That has worked out nicely so far. Below is my config for that for reference, it is basically an exact copy of the disko example flake.

      disko.devices = {
        disk.disk1 = {
          device = "/dev/vda";
          type = "disk";
          content = {
            type = "gpt";
            partitions = {
              boot = {
                name = "boot";
                size = "1M";
                type = "EF02";
              };
              esp = {
                name = "ESP";
                size = "500M";
                type = "EF00";
                content = {
                  type = "filesystem";
                  format = "vfat";
                  mountpoint = "/boot";
                };
              };
              root = {
                name = "root";
                size = "100%";
                content = {
                  type = "lvm_pv";
                  vg = "pool";
                };
              };
            };
          };
        };
        lvm_vg = {
          pool = {
            type = "lvm_vg";
            lvs = {
              root = {
                size = "100%FREE";
                content = {
                  type = "filesystem";
                  format = "ext4";
                  mountpoint = "/";
                  mountOptions = [ "defaults" ];
                };
              };
            };
          };
        };
      };

I would now like to add a second drive to that VM.
I have already added an empty 1TB Drive through the proxmox webui on device virtio12 and I can see it as /dev/vdm when running lsblk.
I have added the following disko config for it:

      disko.devices.disk.disk2 = {
        device = "/dev/vdm";
        type = "disk";
        content = {
          type = "gpt";
          partitions = {
            main = {
              start = "1MiB";
              size = "100%";
              content = {
                type = "filesystem";
                format = "ext4";
                mountpoint = "/storage";
              };
            };
          };
        };
      };

When I apply that new configuration to my VM, it fails with Failed to start local-fs.target and the system does not finish booting anymore and enters emergency mode after A start job is running for /dev/disk/by-partlabel/disk-disk2-main times out.

Do I simply have an error in my partition setup, or do I have to create the mountpoint manually first? Or does disko not support formatting and mounting new disks on existing systems?

What errors does local-fs.target have in its log? Also, I believe that Disko in a flake will try to mount disks, but not create them; have you run the Disko format,mount commands or created the EXT4 partition yourself?

Unfortunately I am unable to interact with the VM’s terminal once systemd enters emergency mode, but I will try more.

While I am using flakes, I also load the disko module into my nixos config.
Maybe it is time for me to read the code of that module.

Turns out it is currently not possible to update an existing disko setup.
This issue tracks that feature request:

I still want it to work when I recreate the VM for whatever reason, so I formatted the disk manually and created a file system on it. I gave the partition the same label from the systemd error, which worked.
(the default label name is defined here disko/lib/types/gpt.nix at a4cb7bf73f264d40560ba527f9280469f1f081c6 · nix-community/disko · GitHub)

You might be interested in disko-zfs that can execute updates: Disko-zfs: manage your datasets declaratively

2 Likes

disko-zfs only handles ZFS and nothing else. Switching to ZFS might be a bit too much just to get declarative updates…

1 Like