Using btrfs manually

Hello,

I am new to btrfs. I want to use its snapshot/rollback functionality for trying out packages.

Here is what I plan to do as an example:

  1. Take a snapshot
  2. Install something (e.g. gnome-desktop)
  3. Try it out
  4. Rollback (clears out everything since I installed gnome-desktop)
  5. Install something else (e.g. budgie-desktop)
  6. Try it out
  7. Rollback (clears out everything since I installed gnome-desktop)

Now, I’ve looked up some basic btrfs wikis. My EndeavourOS is a fresh install with no desktop environment (so I boot to a text console login). Here is my layout:

$ sudo btrfs subvolume list /
ID 257 gen 354 top level 5 path @
ID 258 gen 345 top level 5 path @home
ID 259 gen 351 top level 5 path @cache
ID 260 gen 355 top level 5 path @log
ID 263 gen 24 top level 257 path var/lib/portables
ID 264 gen 25 top level 257 path var/lib/machines

So I’ve now taken a snapshot of root as follows, but I noticed my home is not in the snapshot:

$ sudo btrfs subvolume snapshot / /root-2021-09-23.0
Create snapshot of '/' in '//root-2021-09-23.0'
$ ls /root-2021-09-23.0/home
$ ls /home
myusername
$

So I assume each of the subvolumes above needs to have a separate snapshot (@, @home, @cache, @log)? Or is there a way to do a recursive snapshot?

Also if I take separate snapshot should I place them inside each other? Like:

$ sudo btrfs subvolume snapshot / /root-2021-09-23.0
$ sudo btrfs subvolume snapshot /home /root-2021-09-23.0/home
...

Thanks for your replies in advance!

Yes, each subvolume needs a separate snapshot but you probably don’t need to snapshot all of them. For example, I can’t think of any reason you would want to snapshot @cache. I don’t usually snapshot @log either but I suppose you could. In your case, I would only worry about snapshots for @ and @home

I don’t believe so.

That is personal preference. I don’t put them inside each other because it makes them harder to delete later.

That is awesome. I just tried this (took snapshot, installed gnome, logged into GUI, then restored snapshot) and it worked!

I have one quirk though. Apparently there were 2 subvolumes inside the old root which I did not realize. Now I see them under the “gnome root”. The way I did this was I booted with “init=/bin/bash” and mounted subvolume id 5 (the real btrfs root). I then moved the snapshot around as follows:

mount -o subvolumeid=5 /dev/sda1 /t
mv @ gnome-root # this is the live root where I installed gnome
mv @home gnome-home # this is the live home where I installed gnome
mv root-2021-09-23.0 @ # restore my root snapshot before gnome
mv home=2021-09-23.0 @home # restore my home snapshot before gnome
reboot

However now after the reboot I see:

$ sudo btrfs subvolume list /
ID 257 gen 603 top level 5 path gnome-root
ID 258 gen 598 top level 5 path gnome-home
ID 259 gen 617 top level 5 path @cache
ID 260 gen 626 top level 5 path @log
ID 257 gen 648 top level 5 path @
ID 258 gen 612 top level 5 path @home
ID 263 gen 24 top level 257 path gnome-root/var/lib/portables
ID 264 gen 25 top level 257 path gnome-root/var/lib/machines

So even though my system was restored to pre-gnome state correctly, it looks like I messed up the last two entries.

First question is, what have I broken? What are those 2 subvolumes (portables and machines) under /lib? I don’t even know.

Second is: how can I fix them to stop being children of gnome-root (I actually want to delete gnome-root).

Thanks!

Probably nothing.

They are created by systemd

Mount the real root of the btrfs volume and mv them back under @

Alternatively, if they are empty, just delete them.

This all works very nicely. Thanks for your help!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.