Well, I finally took the time to learn a little about btrfs. I have used it in a very basic fashion in the past, make file system, copy some files or run dd. I even took a basic btrfs file system and transferred my RPi4 image to it, it worked… sort of. I had a few odd errors and so that lasted about a week before going back to f2fs.
There is quite a bit of information on btrfs as it has been around for quite a few years now and has generated its’ fair share of web content. Some good, some bad, some old and outdated.
This time I decided to go “all-in”, to not just make a file system but to setup a rootfs with subvolumes and snaphots. With snaphots being the most compelling feature to me.
I booted on a SD which was updated against arm-unstable. Then I mounted two USB SSDs. One was the SSD of my daily driver image, also on arm-unstable, and the second being a new 60GB SSD.
On the new SSD, I created /boot, swap, and btrfs partitions with the following subvolumes:
$ sudo btrfs subvolume list /
ID 257 gen 316 top level 5 path @ ID 258 gen 317 top level 5 path @home ID 259 gen 311 top level 5 path @snapshots ID 260 gen 20 top level 5 path @srv ID 261 gen 294 top level 5 path @tmp ID 262 gen 257 top level 5 path @var_cache_pacman ID 263 gen 314 top level 5 path @var_log
These are the “directories” which I do not want included in the rootfs snapshots. They are mounted like this:
$ cat /etc/fstab
UUID=92DA-BDF9 /boot vfat defaults,nofail,noauto,x-systemd.device-timeout=10s 0 0 UUID=001e31e7-d595-4fc0-9029-d0bbf9f582f2 none swap defaults,nofail 0 0 UUID=2b382e06-d18c-471c-81cf-493b76bca157 / btrfs defaults,ssd,subvol=@ 0 0 UUID=2b382e06-d18c-471c-81cf-493b76bca157 /home btrfs defaults,ssd,subvol=@home 0 0 UUID=2b382e06-d18c-471c-81cf-493b76bca157 /srv btrfs defaults,ssd,subvol=@srv 0 0 UUID=2b382e06-d18c-471c-81cf-493b76bca157 /.snapshots btrfs defaults,ssd,subvol=@snapshots 0 0 UUID=2b382e06-d18c-471c-81cf-493b76bca157 /tmp btrfs defaults,ssd,subvol=@tmp 0 0 UUID=2b382e06-d18c-471c-81cf-493b76bca157 /var/log btrfs defaults,ssd,subvol=@var_log 0 0 UUID=2b382e06-d18c-471c-81cf-493b76bca157 /var/cache/pacman btrfs defaults,ssd,subvol=@var_cache_pacman 0 0
Once mounted, I copied all the files from boot and root partitions from my daily driver to the btrfs file system. Modified the /etc/fstab as above and rebooted.
Finally, I installed snapper and configured it for the rootfs:
$ snapper -c rootfs list
# | Type | Pre # | Date | User | Cleanup | Description | Userdata ---+--------+-------+---------------------------------+------+----------+-------------+--------- 0 | single | | | root | | current | 1 | single | | Sun 17 Jan 2021 02:17:24 PM CST | root | | Initial | 2 | single | | Sun 17 Jan 2021 03:00:04 PM CST | root | timeline | timeline | 3 | single | | Sun 17 Jan 2021 04:00:14 PM CST | root | timeline | timeline | 4 | single | | Sun 17 Jan 2021 05:00:44 PM CST | root | timeline | timeline
Only time will tell if I end up regretting this. No doubt I will refine this more as I become more comfortable with btrfs… or back to f2fs.
Edit: To be able to reliably roll-back, I need the corresponding /boot files. So I copy the files from /dev/sda1 to /boot. They are then included in the snapshot and can be used to recreate the /boot partition.