NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.71k stars 13.84k forks source link

nixos-generate-config: Incorrect file system settings when using btrfs subvolumes #53177

Open jeltsch opened 5 years ago

jeltsch commented 5 years ago

I’m trying to install NixOS 18.09 from a rescue system running Debian 9 with the Linux kernel updated to 4.19.4. The rescue system comes with version 4.7.3 of btrfs-progs. I’m following the instructions from Subsubsection 2.5.4 of the NixOS 18.09 manual.

I’ve mounted several subvolumes from a single btrfs partition. The problem is that nixos-generate-config generates incorrect file system settings for the subvolumes:

  1. It sets device to the actual devices (like /dev/sda1) instead of the UUID-based symlinks, making the settings vulnerable to device name changes.

  2. It sets subvol erroneously to the mount points of the subvolumes instead of the subvolumes (the values of the subvol mount option).

No such errors occur when just the full btrfs partition is mounted.

emmanuelrosa commented 5 years ago

Please add:

Feel free to (carefully) anonymize the output of the above. The above commands should illustrate which mount points you have set and what nixos-generate-config is coming up with.

aanderse commented 5 years ago

@jeltsch are you able to provide the requested data?

jeltsch commented 5 years ago

Sorry for not responding earlier. When reading the answer by @emmanuelrosa, I had already changed the partitioning and mounting scheme for another reason. Under the new scheme I don’t mount subvolumes and thus don’t experience the described problems anymore. Given this situation, I cannot easily provide the requested data.

aanderse commented 5 years ago

Definitely sounds like this issue should remain open and hopefully someone will take interest in the future.

Glad to hear you at least found a workaround.

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.
jeltsch commented 4 years ago

I think this issue is still important.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

AkechiShiro commented 2 years ago

@jeltsch Still relevant ?

jeltsch commented 1 year ago

Not for me, but in general it might still be relevant.

dryya commented 1 year ago

I didn't experience the second issue when running nixos-generate-config --root /mnt with BTRFS subvolumes from a NixOS 22.11 live USB. For each subvolume, options was set to [ "subvol=@" ], [ "subvol=@home" ], etc.

I did notice that since I was using a LUKS volume, device was set to "/dev/mapper/name". The configuration worked fine. However, when I ran nixos-generate-config again directly from the installed system, device pointed to the UUID of the partition (within the LUKS volume). This also works fine and doesn't create any errors, but this inconsistency could be related to the first issue in the original report.

However, in general I was unable to reproduce any errors or failures.

Generated from Live USB:

  boot.initrd.luks.devices."nixos".device = "/dev/disk/by-uuid/<my-uuid>";

  fileSystems."/" =
    { device = "/dev/mapper/nixos";
      fsType = "btrfs";
      options = [ "subvol=@" ];
    };

  fileSystems."/home" =
    { device = "/dev/mapper/nixos";
      fsType = "btrfs";
      options = [ "subvol=@home" ];
    };

Generated from running system:

  boot.initrd.luks.devices."nixos".device = "/dev/disk/by-uuid/<myuuid>";

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/<different-uuid>";
      fsType = "btrfs";
      options = [ "subvol=@" ];
    };

  fileSystems."/home" =
    { device = "/dev/disk/by-uuid/<different-uuid>";
      fsType = "btrfs";
      options = [ "subvol=@home" ];
    };

Findmnt output (/dev and such omitted):

TARGET                        SOURCE                         FSTYPE     OPTIONS
/                             /dev/mapper/nixos[/@]          btrfs      rw,ssd,space_cache=v2,subvolid=<num>,subvol=/@
├─/boot                       /dev/nvme0n1p1                 vfat       rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro
├─/home                       /dev/mapper/nixos[/@home]      btrfs      rw,ssd,space_cache=v2,subvolid=<num>,subvol=/@home