ZFS: Difference between revisions
imported>2r smbshare to do |
imported>2r stateless root |
||
Line 15: | Line 15: | ||
Root on ZFS guide is now maintained at [https://openzfs.github.io/openzfs-docs/Getting%20Started/NixOS/Root%20on%20ZFS.html OpenZFS Documentation] website. Visit there for details and if an issue arises, submit an issue or pull request. | Root on ZFS guide is now maintained at [https://openzfs.github.io/openzfs-docs/Getting%20Started/NixOS/Root%20on%20ZFS.html OpenZFS Documentation] website. Visit there for details and if an issue arises, submit an issue or pull request. | ||
== Immutable Root on ZFS == | |||
After following the [https://openzfs.github.io/openzfs-docs/Getting%20Started/NixOS/Root%20on%20ZFS.html OpenZFS Documentation], immutable root can be optionally enabled to clean up root filesystem at boot. | |||
This involves mounting the existing root at a different location and bind mount necessary configuration files from the new mount point. We will use <code>/altroot</code> here. | |||
<syntaxhighlight lang="nix"> | |||
## In /etc/nixos/configuration.nix: | |||
systemd.services.zfs-mount.enable = false; | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="nix"> | |||
## In /etc/nixos/hardware-configuration.nix: | |||
## Replace existing entry for / (root) with | |||
fileSystems."/" = { | |||
device = "none"; | |||
fsType = "tmpfs"; | |||
options = [ "defaults" "size=1G" "mode=755" ]; | |||
}; | |||
## Mount old root at /altroot | |||
## noatime option is used for better performance | |||
fileSystems."/altroot" = | |||
{ device = "rpool/nixos/root"; | |||
fsType = "zfs"; options = [ "zfsutil" "noatime" "X-mount.mkdir" ]; | |||
neededForBoot = true; | |||
}; | |||
## /nix/ is needed for the system to boot, so | |||
## bind mount it from old root | |||
fileSystems."/nix" = { | |||
device = "/altroot/nix"; | |||
fsType = "none"; | |||
options = [ "bind" "X-mount.mkdir" ]; | |||
}; | |||
## /etc/nixos/ stores system configuration | |||
fileSystems."/etc/nixos" = { | |||
device = "/altroot/etc/nixos"; | |||
fsType = "none"; | |||
options = [ "bind" "X-mount.mkdir" ]; | |||
}; | |||
</syntaxhighlight> | |||
'''Optional''': stateless home directory. This requires you to keep track of your dot files with a version control system. Git is used here as an example. | |||
== Mount datasets at boot == | == Mount datasets at boot == |