Btrfs: Difference between revisions

imported>Sirphobos
changed/expanded snapshot section
imported>Sirphobos
added short scrubbing section
Line 78: Line 78:
swapDevices = [ { device = "/swap/swapfile"; } ];
swapDevices = [ { device = "/swap/swapfile"; } ];
</syntaxhighlight>
</syntaxhighlight>
=== Scrubbing ===
Btrfs filesystem by default keeps checksums for all files, and this allows to check if contents of the file has not changed due to hardware malfunctions and other external effects.
Scrubbing - is the process of checking file consistency (for this it may use checksums and/or duplicated copies of data, from raid for example). Scrubbing may be done "online", meaning you don't need to unmount a subvolume to scrub it.
You can enable automatic scrubbing with
<syntaxhighlight lang="nix">
services.btrfs.autoScrub.enable = true;
</syntaxhighlight>
Automatic scrubbing by default is performed once a month, but you can change that with
<syntaxhighlight lang="nix">
services.btrfs.autoScrub.interval = "weekly";
</syntaxhighlight>
<code>interval</code> syntax is defined by [https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events systemd.timer's Calendar Events]
By default autoscrub will scrub all detected btrfs mount points, howeven in case of mounted nested subvolumes (like in example above <code>/nix</code> and <code>/home</code> are nested subvolumes under <code>/</code>) you only need to scrub the top-most one. So an example configuration may look like this:
<syntaxhighlight lang="nix">
services.btrfs.autoScrub = {
  enable = true;
  interval = "monthly";
  fileSystems = [ "/" ];
};
</syntaxhighlight>
The result of periodic auto scrub will be save to system journal, however you can also always check the status of the last scrub with
<syntaxhighlight lang="bash">
btrfs scrub status /
</syntaxhighlight>
You can also start a scrubbing in background manually
<syntaxhighlight lang="bash">
btrfs scrub start /
</syntaxhighlight>
You can check the status of the ongoing scrubbing process with the same <code>status</code> command from above


== Usage ==
== Usage ==