Skip to content

Nix should not mount -o remount,rw #9417

Description

Can anybody explain why this is here?

if (stat.f_flag & ST_RDONLY) {
if (mount(0, realStoreDir.get().c_str(), "none", MS_REMOUNT | MS_BIND, 0) == -1)
throw SysError("remounting %1% writable", realStoreDir);

I traced it back to b9124a5. It looks like the original codepath would check if /nix/store was a --bind mount and act only in that specific situation.

The comment says:

/* To improve purity, users may want to make the Nix store a read-only
bind mount. So make the Nix store writable for this process. */

Note that this codepath gets hit not only for the /nix/store store, but also when you use nix copy --from /mnt/somewhere/nix/store. For example when recovering from a mangled system and trying to copy off whatever can be salvaged. Why would the --from store need to be remounted read-write for that to happen?

Some filesystems, in particular btrfs, will react to serious problems by switching the filesystem to readonly mode, and interpret any subsequent mount -o remount,rw as a "I know what I'm doing" signal by the root user. I don't think it's a good idea for nix-daemon to signal this unilaterally. Remounting read-write without doing an fsck first is usually a bad decision, and bad decisions should be left up to the humans :)

I think this behavior (remount read-write without an fsck) is one of the two reasons why Nixfolk have such strange (and strong!) opinions about btrfs. The other reason is explained in #7126 (comment). I'd hate to see the same thing happen with bcachefs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugstoreIssues and pull requests concerning the Nix store

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions