disko icon indicating copy to clipboard operation
disko copied to clipboard

Help requested: VM w/ luks-btrfs-raid example does not build

Open cdata opened this issue 5 months ago • 4 comments

Hello, I've been having some stuttering success with using Disko for the first time. I have a setup where I wish to test the configuration in a VM locally. I got a LUKS+Btrfs setup working great. Then, I tried to adapt it based on the LUKS+Btrfs+RAID1 example and ran into a problem.

When I try to build the VM using the RAID example, it fails during disk creation. The full log is attached here. The critical failure point AFAICT is here:

+ mount /dev/mapper/p2 /tmp/tmp.199fvLzrll -o subvol=/
[   36.047665] BTRFS error (device dm-1): devid 2 uuid 25b46a4d-be57-4e52-b025-c1e603233b60 is missing
[   36.048657] BTRFS error (device dm-1): failed to read the system array: -2
[   36.050159] BTRFS error (device dm-1): open_ctree failed: -2
mount: /tmp/tmp.199fvLzrll: fsconfig() failed: No such file or directory.
       dmesg(1) may have more information after failed mount system call.

I have created a minimal reproduction case that demonstrates the issue I'm running up against here: https://github.com/cdata/disko-luks-btrfs-raid-vm-not-working

In the test case, I build the VM using the command nix build .\#test-vm to reproduce the issue.

I tried running the checks in the Disko repo to make sure it wasn't some kind of environmental issue with my local system. The checks all pass, so I assume there is something I'm missing or that I configured incorrectly that is causing this issue.

I'm new to using Disko and would be grateful for any help or advice you can provide. Thanks in advance!

cdata avatar Sep 23 '25 20:09 cdata

Disko creates volumes sequentially, and by group. p1 is likely not available yet at the time disko attempts to create the p2 raid.

What will likely work is making p2 a lvm pv and then create the raid as a lvm vg, as that happens after all volumes are created (yes it's hacky and you end up with a unwanted lvm pv)

Otherwise, splitting your disko config into two files is possible, see https://github.com/nix-community/disko/issues/962#issuecomment-2781067044 for an example, although it is error prone.

johanjk avatar Sep 23 '25 22:09 johanjk

This has worked for me in the past (using the lvm pv method)

{
  disko.devices = {
    disk = {
      p1 = {
        type = "disk";
        device = "/dev/nvme0n1";
        content = {
          type = "gpt";
          partitions = {
            luks = {
              label = "disk1";
              size = "100%";
              content = {
                type = "luks";
                name = "main_crypted";
                # ...
                content = {
                  type = "lvm_pv";
                  vg = "pool_main";
                };
              };
            };
          };
        };
      };
      p2 = {
        type = "disk";
        device = "/dev/nvme1n1";
        content = {
          type = "gpt";
          partitions = {
            luks = {
              label = "disk2";
              size = "100%";
              content = {
                type = "luks";
                name = "main2_crypted";
                # ...
              };
            };
          };
        };
      };
    };

    lvm_vg = {
      pool_main = {
        type = "lvm_vg";
        lvs = {
          main = {
            size = "100%";
            content = {
              type = "btrfs";
              extraArgs = [
                "-d raid1"
                "/dev/mapper/main2_crypted"
              ];
              subvolumes = {
                # ...
              };
            };
          };
        };
      };
    };
  };
}

johanjk avatar Sep 23 '25 22:09 johanjk

Thanks for the advice @johanjk I'll give it a shot.

The thing that got me thinking that I'm just doing something wrong is that I copied the example verbatim, and the check which tests the example passes. This suggests to me (though I am naive) that I should be able to make the example work for me without significant modification.

cdata avatar Sep 23 '25 22:09 cdata

Friendly bump on this. I'm interested to know if perhaps there is something about the setup in the checks that I can adopt to make this work for me locally. Any pointers would be appreciated.

cdata avatar Oct 07 '25 19:10 cdata