Btrfs: Difference between revisions

Pigs (talk | contribs)
Fleshed out the usage section, discussed top level vs nested subvolumes
Tags: Mobile edit Mobile web edit Advanced mobile edit
Pigeon (talk | contribs)
 
(4 intermediate revisions by 4 users not shown)
Line 142: Line 142:


== Deduplication ==
== Deduplication ==
 
Files with (partially) equal contents can be deduplicated using [https://github.com/Zygo/bees bees] or [https://github.com/markfasheh/duperemove duperemove]. The [https://btrfs.readthedocs.io/en/latest/Deduplication.html upstream wiki entry] on deduplication provides an overview of available features of these programs.
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>:
Line 182: Line 181:
</syntaxhighlight>
</syntaxhighlight>


=== Top level vs nested subvolumes ===
=== Top-level vs nested subvolumes ===


In btrfs, subvolumes can be created either at the top level of the filesystem or within other subvolumes
In btrfs, subvolumes can be created either at the top level of the filesystem or within other subvolumes.


* Top level subvolumes are created directly under the filesystem's root. By default, the root volume id is 5. Top level subvolumes are easier to snapshotted, rolled back or destroyed independently. This is good for things such as <code>/home</code> or <code>/nix</code>.
* Top-level subvolumes are created directly under the filesystem's root. By default, the root volume ID is 5. Top-level subvolumes are easier to snapshot, roll back or destroy independently. This is good for things such as <code>/home</code> or <code>/nix</code>.


* Nested subvolumes are created inside an existing subvolume or directory within the filesystem. All nested subvolumes inherit the mount status of their parent unless mounted seperately. This layout is useful for organizing related subvolumes under a common namespace. For example, a top-level subvolume such as <code>/srv/nfs</code> can contain multiple nested subvolumes like <code>/srv/nfs/export1</code> and <code>/srv/nfs/export2</code>.
* Nested subvolumes are created inside an existing subvolume or directory within the filesystem. All nested subvolumes inherit the mount status of their parent unless mounted separately. This layout is useful for organizing related subvolumes under a common namespace. For example, a top-level subvolume such as <code>/srv/nfs</code> can contain multiple nested subvolumes like <code>/srv/nfs/export1</code> and <code>/srv/nfs/export2</code>.




Line 240: Line 239:


= Tips and tricks =
= Tips and tricks =
== Backup ==
[[Btrbk]] is a tool for creating snapshots and remote backups of btrfs subvolumes.


== Installation with encryption ==
== Installation with encryption ==
Line 322: Line 325:
== Convert Ext3/Ext4 system partition to Btrfs ==
== Convert Ext3/Ext4 system partition to Btrfs ==


<div style="border: 1px solid var(--border-color-error); background: var(--background-color-error-subtle); padding: 30px; border-radius: 5px; margin: 10px 0px; display: flex; align-items: center;">
{{Warning|Note that migrating your existing root filesystem can cause data loss or make your system unbootable. Make sure to backup the partition or your files. Proceed only if you know what you're doing!}}
    <div style="color: var(--border-color-error); font-size: 40px; margin-right: 15px; background: var(--background-color-error-subtle); display: flex; line-height: 0;  align-items: center;">⚠</div>
    <div style="color: var(--border-color-error); font-size: 15px; font-style: normal; font-weight: 400; line-height: normal; text-align: left;">Note that migrating your existing root filesystem can cause data loss or make your system unbootable. Make sure to backup the partition or your files. Proceed only if you know what you're doing!</div>
</div>


To convert the existing filesystem (Ext3/4) to Btrfs, boot into a NixOS live system and run the following commandː<syntaxhighlight lang="sh">
To convert the existing filesystem (Ext3/4) to Btrfs, boot into a NixOS live system and run the following commandː<syntaxhighlight lang="sh">
Line 348: Line 348:
btrfs subvolume delete /btrfs/ext2_saved
btrfs subvolume delete /btrfs/ext2_saved
</syntaxhighlight>
</syntaxhighlight>
=== TRIM support ===
{{main|Filesystems#SSD TRIM support}}
Refer to [https://btrfs.readthedocs.io/en/latest/Trim.html btrfs docs] on how Trim works with btrfs through the <code>discard</code> mount option.
[[Category: Configuration]]
[[Category: Configuration]]
[[Category:Filesystem]]
[[Category:Filesystem]]