Filesystems: Difference between revisions

From NixOS Wiki
imported>Harärmat
Add new page and describe bind mounts + mount order
 
imported>Harärmat
m Move references to the bottom of the page
Line 13: Line 13:
<ref>[https://en.wikipedia.org/wiki/Mount_(Unix)#Bind_mounting Wikipedia - Bind mount]</ref>
<ref>[https://en.wikipedia.org/wiki/Mount_(Unix)#Bind_mounting Wikipedia - Bind mount]</ref>
</blockquote>
</blockquote>
<references/>


These are used to make files or folders available in other parts of the filesystem hierarchy. In order to do so both source and target filesystems have to be mounted first.
These are used to make files or folders available in other parts of the filesystem hierarchy. In order to do so both source and target filesystems have to be mounted first.
Line 39: Line 38:
};
};
</syntaxhighlight>
</syntaxhighlight>
= References =
<references/>

Revision as of 15:40, 30 December 2022

fileSystems is a NixOS option that allows the user to mount filesystems at specific mount points. The mounted filesystems may also be encrypted.

Mount order

Without any specification, the mount order is up to the implementation (probably alphabetic).

Should the order in which filesystems are mounted is important, users should make use of the fileSystems.<mount>.depends option. This is useful for example in #Bind mounts

Bind mounts

Bind mounting allows a filesystem hierarchy or a file to be mounted at a different mount point. Unlike a symbolic link, a bind mount does not exist on the filesystem itself.[3] In the following example, the path /olddir will be mounted in /newdir [1]

These are used to make files or folders available in other parts of the filesystem hierarchy. In order to do so both source and target filesystems have to be mounted first.

fileSystems."/mnt/datastore".label = "datastore";
fileSystems."/mnt/aggregator".label = "aggregator";

####################
# Bind mounts

# Mount /mnt/datastore/applications/app1 on /mnt/aggregator/app1
# Accessing /mnt/aggregator/app1 will actually access /mnt/datastore/...
fileSystems."/mnt/aggregator/app1" = {
  depends = [
      # The mounts above have to be mounted in this given order
      "/mnt/datastore" 
      "/mnt/aggregator" 
  ];
  device = "/mnt/datastore/applications/app1";
  fsType = "none";
  options = [
    "bind"
    "ro" # The filesystem hierarchy will be read-only when accessed from /mnt/aggregator/app1
  ];
};

References