NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.31k stars 14.28k forks source link

nixos/stage-1.init.sh: Prevent unsafe remount and correct fstab syntax #358035

Open Princemachiavelli opened 3 days ago

Princemachiavelli commented 3 days ago

Description

The legacy stage-1 generates the /etc/fstab from fsInfo but incorrectly adds a trailing , character to the mount options. While does not appear to have caused any issue yet we should trim the trailing , to be safe.

Generated /etc/fstab during stage-1:

tmpfs /mnt-root tmpfs mode=0755,

stage-1 also currently remounts all fileSystems as a fix for busybox not respecting mount options on bind (and rbind) mount points. This results in a unintended errors during stage-1 if a file system such as NFS is mounted which does allow remounting with all of the original options present (i.e some options can only be set during the initial mount).

Error during stage-1 mounting NFS share:

mount: mounting server.example.test:/nix/store on /mnt-root/nix/.ro-store failed: Invalid argument

Things done

Built and ran legacyPackages.x86_64-linux.nixosTests.early-mount-options.

ConnorBaker commented 2 days ago

@ElvishJerricco @tpwrules would either of you have a chance to take a look at this PR?