Btrfs: Difference between revisions

Transfer snapshot: Add --compressed-data trick
Tags: Mobile edit Mobile web edit
Pigs (talk | contribs)
Fleshed out the usage section, discussed top level vs nested subvolumes
Tags: Mobile edit Mobile web edit Advanced mobile edit
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 164: Line 164:
== Subvolumes ==
== Subvolumes ==


Create a subvolume
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 176:
</syntaxhighlight>
</syntaxhighlight>


Remove a subvolume
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 snapshotted, rolled back or destroyed 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>.


== Snapshots ==
== Snapshots ==