Skip to content

Consider changing the BTRFS subvolume layout #781

@KhalilSantana

Description

@KhalilSantana

Hello,

I'm very happy to see that v2.3.X includes BTRFS subvolume support as a beta feature! This was a major blocker for me and now it's (mostly) gone.

However, I would like to comment on the current subvolume layout used by Archinstall's guided mode, and why (and how) I think it could be improved.

The Current Layout

For reference this is the current layout used by guided mode as of 2021-12-1 using archinstall v2.3.0:

# btrfs subvol list -t /
ID	gen	top level	path	
--	---	---------	----	
256	21	5		home
258	21	5		var/log
259	17	5		var/cache/pacman/pkg
260	10	5		.snapshots
264	14	5		var/lib/portables
265	15	5		var/lib/machines

How BTRFS handles subvolumes, and snapshots

(this section exists mostly to add context, skip it if you are familiar with BTRFS)

In BTRFS, each subvolume has an ID and a path, relative to the toplevel (a.k.a subvolid=5), these subvolumes can be mounted anywhere, and can be used for many things just like folders, however, the main differentiator between a regular folder and a subvol is that the later has special powers: atomic snapshots, etc.

Snapshots are just a clone of that filesystem root (subvol) at that time, and it shares extents with the snapped subvol, this is one of reasons snaps are so useful: they are fast and small.

However, there are some important quirks/behaviors that BTRFS currently does:

  • Rule 0: You cannot replace the toplevel (subvolid=5, subvol=/) with another subvol.
  • Rule 1: btrfs subvol snap won't recurse into nested subvolumes. So you cannot create atomic snaps of nested subvolumes and their parents at once.
  • Rule 2: As btrfs subvol snap doesn't recurse, the resulting subvolume (the snapshot) won't contain ANY of it's nested subvols.

With this in mind, I hope the next section becomes easy to understand.

What's wrong with the current layout?

The current layout basically prohibits using snapshots as a rollback feature, why?

  • Per Rule 0, you cannot rollback (without lots of jiggling mv's and rm's) the root filesystem as it's been mounted at the toplevel subvol.
  • Per Rule 1 and 2, even if you manually rollback using methods, like using the (often confusing) btrfs sub set-default, your homedir will be empty! You'd need to manually snap RW the old home subvol into the right place.

In short the main issues with the current subvol layout are:

  • The root filesystem using the toplevel subvolume directly.
  • The home dir0 being a nested subvolume.

What would be a better layout?

  • Reserve the toplevel subvolume for managing other subvolumes
  • Utilize a subvolume as the root filesystem
  • Utilize a non-nested subvolume for the home dir.

This is often called the "flat-layout", often used with the ubuntu-style naming scheme (@ as /, @home as /home), and it's documented on the wiki

What other distros are using?

  • Ubuntu's installer uses the flat layout, with @ and @home, mounted at / and /home, respectively
  • Manjaro's installer uses the flat layout, identical to the Ubuntu one.
  • Fedora's Installer uses the flat layout, with a different naming scheme (root and home AFAIK)

My layout suggestion

Follow the flat layout, with the Ubuntu-style naming scheme, but keep the extra subvols (/var/log & /var/cache/pacman/pkg), those extras not nested, of course.

Basically, this:

# btrfs subvolume list -t /
[sudo] senha para khalil: 
ID      gen     top level       path
--      ---     ---------       ----
256     1408526 5               @
257     1408526 5               @home
258     1408526 5               @pkg
259     1408526 5               @log
260     1391176 5               @snapshots

In tree view for clarity's sake:

# exa -TL1 /mnt/toplevel # this is the mount point of subvolid=5 on my system, for maintance purposes)
/mnt/toplevel
├── @
├── @home
├── @pkg
├── @log
└── @snapshots

Why the Ubuntu naming scheme? Why not Fedora's? Or something else entirely?

Mostly because of Timeshift, as it only supports that standard. And while it might seem like a silly reason, I feel like it's reasonable: Timeshift is the one of the few snapshot utilities that has an incredibly easy to use restore button, which makes undoing changes incredibly easy, and also un-breaking a system after a bad upgrade.


Thank you for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixedIssue is fixed in the current or next release.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions