Btrfs: Difference between revisions

replace manual bees with NixOS module
Ponder (talk | contribs)
m Scrubbing: Copyedit for grammar & missing small words
Line 84: Line 84:
=== Scrubbing ===
=== 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.
Btrfs filesystems by default keep checksums for all files, to monitor if the file has changed due to hardware malfunctions or 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.
Scrubbing is the process of checking file consistency, which 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
You can enable automatic scrubbing withː
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services.btrfs.autoScrub.enable = true;
services.btrfs.autoScrub.enable = true;
</syntaxhighlight>
</syntaxhighlight>


Automatic scrubbing by default is performed once a month, but you can change that with
Automatic scrubbing by default is performed once a month, but you can change that withː
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services.btrfs.autoScrub.interval = "weekly";
services.btrfs.autoScrub.interval = "weekly";
Line 99: Line 99:
<code>interval</code> syntax is defined by [https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events systemd.timer's Calendar Events]
<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. However, 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:
By default, autoscrub will scrub all detected btrfs mount points. However, in case of mounted nested subvolumes (e.g. the example above where <code>/nix</code> and <code>/home</code> are nested subvolumes under <code>/</code>), you only need to scrub the topmost one. So an example configuration may look like this:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services.btrfs.autoScrub = {
services.btrfs.autoScrub = {
Line 108: Line 108:
</syntaxhighlight>
</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
The result of the periodic auto scrub will be saved to the system journal, and you can check the status of the last scrubː
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
btrfs scrub status /
btrfs scrub status /
</syntaxhighlight>
</syntaxhighlight>


You can also start a scrubbing in background manually
You can also start a scrub in the background manuallyː
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
btrfs scrub start /
btrfs scrub start /
</syntaxhighlight>
</syntaxhighlight>
You can check the status of the ongoing scrubbing process with the same <code>status</code> command from above
You can check the status of the ongoing scrubbing process with the same <code>status</code> command as above.


=== Deduplication ===
=== Deduplication ===


Files with (partially) equal contents can be deduplicated using [https://github.com/Zygo/bees bees] or [https://github.com/markfasheh/duperemove duperemove].
Files with (partially) equal contents can be deduplicated using [https://github.com/Zygo/bees bees] or [https://github.com/markfasheh/duperemove duperemove].
bees can be configured in <code>configuration.nix</code>:
bees can be configured in <code>configuration.nix</code>: