Btrfs: Difference between revisions
Fix section headers, update swap file section to let nixos handle swap file creating |
m Polish text in →Top-level vs nested subvolumes |
||
| (6 intermediate revisions by 5 users not shown) | |||
| Line 3: | Line 3: | ||
{{note| Use [https://github.com/nix-community/disko/ disko] to manage your NixOS storage layout declaratively. The following shows a manual approach as seen in traditional Linux distributions.}} | {{note| Use [https://github.com/nix-community/disko/ disko] to manage your NixOS storage layout declaratively. The following shows a manual approach as seen in traditional Linux distributions.}} | ||
= Installation = | = Installation of NixOS on btrfs = | ||
{{note|The following example is for EFI enabled systems. Adjust commands accordingly for a BIOS installation.}} | {{note|The following example is for EFI enabled systems. Adjust commands accordingly for a BIOS installation.}} | ||
| 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 164: | Line 163: | ||
== Subvolumes == | == Subvolumes == | ||
To display all subvolumes within a mounted btrfs filesystem: | |||
<syntaxhighlight lang="bash"> | |||
btrfs subvolume list -t /mnt | |||
</syntaxhighlight> | |||
To create a new subvolume at a specified location: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
| Line 170: | Line 175: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
To remove an existing subvolume: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
btrfs subvolume delete /mnt/nixos | btrfs subvolume delete /mnt/nixos | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Top-level vs nested 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 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 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>. | |||
== Snapshots == | == Snapshots == | ||
| Line 220: | Line 235: | ||
sudo btrfs send /snapshots/nixos_snapshot_202302 | zstd | ssh root@192.168.178.110 'zstd -d | btrfs receive /mnt/nixos' | sudo btrfs send /snapshots/nixos_snapshot_202302 | zstd | ssh root@192.168.178.110 'zstd -d | btrfs receive /mnt/nixos' | ||
</syntaxhighlight> | </syntaxhighlight> | ||
If both the sender and receiver side have Btrfs with the same compression algorithm and level, you can instead use <code>send --compressed-data</code> to avoid decompressing and recompressing the data. | |||
= 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 304: | Line 325: | ||
== Convert Ext3/Ext4 system partition to Btrfs == | == Convert Ext3/Ext4 system partition to Btrfs == | ||
{{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!}} | |||
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 330: | 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]] | ||