NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.6k stars 13.75k forks source link

`nixos-generate-config` multi-device file systems: only one luks device entry generated #44917

Open schmittlauch opened 6 years ago

schmittlauch commented 6 years ago

Issue description

I use a Btrfs multi-device file system as my / fs. While the mount command requires only one of the devices to be mentioned, the other Btrfs devices forming the whole file system are discovered at runtime. If using them on top of LUKS encryption, that means all luks devices need to be unlocked for the mount to succeed. Nevertheless nixos-generate-config only creates a boot.initrd.luks.devices entry for the device mentioned in the mount command, thus causing all other devices not to be unlocked and the mount to fail.

Steps to reproduce

  1. Set up a multi-device Btrfs file system on top of 2 LUKS containers:
    cryptsetup luksFormat /dev/sda1
    cryptsetup luksFormat /dev/sda2
    cryptsetup luksOpen /dev/sda1 crypt1
    cryptsetup luksOpen /dev/sda2 crypt2
    mkfs.btrfs -d single /dev/mapper/crypt{1,2}
    mount /dev/mapper/crypt1 /mnt
  2. run nixos-generate-config --root /mnt
  3. see that there's only a boot.initrd.luks.devices entry for /dev/sda1 but none for /dev/sda2

Technical details

eadwu commented 6 years ago

Same occurs here though sda2 is a swap partition in my case while sda3 is a btrfs partition. Creates a luks.devices for the btrfs partition only.

ghost commented 5 years ago

@schmittlauch Has this been solved or do you have a workaround?

schmittlauch commented 5 years ago

@Spass1966 The issue hasn't been resolved so far. My workaround was adding the missing LUKS device to the config manually and never regenerating the hardware-configuration.nix since then.

Edit: Actually I cannot currently check whether this issue still exists or not, as I have changed away from a setup with 2 LUKS volumes to just one. Sorry, completely forgot about that

ghost commented 5 years ago

@schmittlauch Do you mind posting your config? I am about to do a similar install and I'd like to make sure I don't make any mistakes adding the device.

schmittlauch commented 5 years ago

@Spass1966 my working config back when I still used such a setup (Btrfs as a "single" fs over 2 LUKS volumes):

boot.initrd.luks = 
 { devices =
   { "systemA".device = "/dev/disk/by-uuid/1d57fb8c-301b-4d8c-8652-dcda39910404";
     "systemB".device = "/dev/disk/by-uuid/d68d217b-5443-49ca-af1b-9f2eacb73d8b";
     "cryptswap".device = "/dev/disk/by-uuid/472d5c58-d834-4ff8-82f1-f98d627e9163";
   };
   reusePassphrases = true;
};
fileSystems."/" =
{ device = "/dev/disk/by-uuid/0cd6d909-dba3-4542-a3b3-bffa16f6ce78";
  fsType = "btrfs";
  options = [ "subvol=nixos_root" ];
};

You have to change the "systemA" and "systemB" to the names of your LUKS volumes and also change the device UUIDs.

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
wucke13 commented 3 years ago

This is still an issue.

isaacaggrey commented 6 months ago

I also still see this issue. My use case is a laptop with two SSDs that I wanted to run Btrfs on LUKS with a single logical (encrypted) volume for the root directory across the two drives.

To get something to work,

Related - I also looked into Disko, which is a neat tool for declarative disk management, but it also has an issue with btrfs multi-device volumes: https://github.com/nix-community/disko/issues/261