ZFS: Difference between revisions
imported>Makefu No edit summary |
imported>Fadenb Syntax highlighting |
||
Line 20: | Line 20: | ||
Just add the following to your <code>configuration.nix</code> file: | Just add the following to your <code>configuration.nix</code> file: | ||
< | <syntaxhighlight lang="nix"> | ||
boot.supportedFilesystems = [ "zfs" ]; | boot.supportedFilesystems = [ "zfs" ]; | ||
</ | </syntaxhighlight> | ||
To activate the configuration and load the ZFS kernel module, run: | To activate the configuration and load the ZFS kernel module, run: | ||
< | <syntaxhighlight lang="bash"> | ||
nixos-rebuild switch | nixos-rebuild switch | ||
modprobe zfs | modprobe zfs | ||
</ | </syntaxhighlight> | ||
(Note that manually loading the ZFS kernel module is only necessary in the install environment).<ref>Todo: Verify if this is still the case with NixOS >= 17.03 </ref> | (Note that manually loading the ZFS kernel module is only necessary in the install environment).<ref>Todo: Verify if this is still the case with NixOS >= 17.03 </ref> | ||
Line 37: | Line 37: | ||
If you want NixOS to auto-mount your ZFS filesystems during boot, you should set their <code>mountpoint</code> property to <code>legacy</code> and treat it like if it were any other filesystem, i.e.: mount the filesystem manually and regenerate your list of filesystems, as such: | If you want NixOS to auto-mount your ZFS filesystems during boot, you should set their <code>mountpoint</code> property to <code>legacy</code> and treat it like if it were any other filesystem, i.e.: mount the filesystem manually and regenerate your list of filesystems, as such: | ||
< | <syntaxhighlight lang="bash"> | ||
zfs set mountpoint=legacy <pool>/<fs> | zfs set mountpoint=legacy <pool>/<fs> | ||
mount -t zfs <pool>/<fs> <mountpoint> | mount -t zfs <pool>/<fs> <mountpoint> | ||
Line 45: | Line 45: | ||
nixos-rebuild switch | nixos-rebuild switch | ||
</ | </syntaxhighlight> | ||
NixOS will now make sure that your filesystem is always mounted during boot. | NixOS will now make sure that your filesystem is always mounted during boot. | ||
The <code>nixos-generate-config</code> command regenerates your <code>/etc/nixos/hardware-configuration.nix</code> file, which includes the list of filesystems for NixOS to mount during boot, e.g.: | The <code>nixos-generate-config</code> command regenerates your <code>/etc/nixos/hardware-configuration.nix</code> file, which includes the list of filesystems for NixOS to mount during boot, e.g.: | ||
< | <syntaxhighlight lang="nix"> | ||
(...) | (...) | ||
fileSystems."/home" = | fileSystems."/home" = | ||
Line 61: | Line 61: | ||
}; | }; | ||
(...) | (...) | ||
</ | </syntaxhighlight> | ||
== How to use the auto-snapshotting service == | == How to use the auto-snapshotting service == | ||
Line 67: | Line 67: | ||
To auto-snapshot a ZFS filesystem or a ZVol, set its <code>com.sun:auto-snapshot</code> property to <code>true</code>, like this: | To auto-snapshot a ZFS filesystem or a ZVol, set its <code>com.sun:auto-snapshot</code> property to <code>true</code>, like this: | ||
< | <syntaxhighlight lang="bash"> | ||
$ zfs set com.sun:auto-snapshot=true <pool>/<fs> | $ zfs set com.sun:auto-snapshot=true <pool>/<fs> | ||
</ | </syntaxhighlight> | ||
(Note that by default this property will be inherited by all descendent datasets, but you can set their properties to false if you prefer.) | (Note that by default this property will be inherited by all descendent datasets, but you can set their properties to false if you prefer.) | ||
Line 75: | Line 75: | ||
Then, to enable the auto-snapshot service, add this to your <code>configuration.nix</code>: | Then, to enable the auto-snapshot service, add this to your <code>configuration.nix</code>: | ||
< | <syntaxhighlight lang="nix"> | ||
services.zfs.autoSnapshot.enable = true; | services.zfs.autoSnapshot.enable = true; | ||
</ | </syntaxhighlight> | ||
And finally, run <code>nixos-rebuild switch</code> to activate the new configuration! | And finally, run <code>nixos-rebuild switch</code> to activate the new configuration! | ||
Line 84: | Line 84: | ||
You can globally override this configuration by setting the desired number of snapshots in your <code>configuration.nix</code>, like this: | You can globally override this configuration by setting the desired number of snapshots in your <code>configuration.nix</code>, like this: | ||
< | <syntaxhighlight lang="nix"> | ||
services.zfs.autoSnapshot = { | services.zfs.autoSnapshot = { | ||
enable = true; | enable = true; | ||
Line 90: | Line 90: | ||
monthly = 1; # keep only one monthly snapshot (instead of twelve) | monthly = 1; # keep only one monthly snapshot (instead of twelve) | ||
}; | }; | ||
</ | </syntaxhighlight> | ||
You can also disable a given type of snapshots on a per-dataset basis by setting a ZFS property, like this: | You can also disable a given type of snapshots on a per-dataset basis by setting a ZFS property, like this: | ||
< | <syntaxhighlight lang="bash"> | ||
$ zfs set com.sun:auto-snapshot:weekly=false <pool>/<fs> | $ zfs set com.sun:auto-snapshot:weekly=false <pool>/<fs> | ||
</ | </syntaxhighlight> | ||
This would disable only weekly snapshots on the given filesystem. | This would disable only weekly snapshots on the given filesystem. | ||
Line 105: | Line 105: | ||
(thanks to Danny Wilson for the instructions) | (thanks to Danny Wilson for the instructions) | ||
< | <syntaxhighlight lang="bash"> | ||
# Add the zfs filesystem to the install environment: | # Add the zfs filesystem to the install environment: | ||
nano /etc/nixos/configuration.nix | nano /etc/nixos/configuration.nix | ||
Line 186: | Line 186: | ||
# Ready to go! | # Ready to go! | ||
nixos-install | nixos-install | ||
</ | </syntaxhighlight> | ||
== Need more info? == | == Need more info? == |