Some folks might find this video tutorial useful for setting it up with the dnf snapper plugin with fairly minimal changes, i.e. it’s not invasive.
There are some gotchas to be aware of with the current layout and doing rollbacks. It rolls back anything in the root subvolume, which includes /var/lib/libvirt/images (your VM images) and your logs.
If you don’t like that idea you can retrofit the layout, example fstab:
UUID=$btrfsuuid / btrfs compress=zstd:1 0 0
UUID=$btrfsuuid /home btrfs subvol=home 0 0
UUID=$btrfsuuid /var/log btrfs subvol=logs 0 0
UUID=$btrfsuuid /var/lib/libvirt/images btrfs subvol=libvirtimages 0 0
The reason this works is because a snapshot of subvol=root will no longer include /var/log or /var/lib/libvirt/images. This is the case whether using the flat layout described above and in the video, or using the nested layout. Snapshots are not recursive, they stop at subvolume boundaries.
The high level overview of how you do it is:
mount /dev/vda3 /mnt
btrfs sub create log
chcon "system_u:object_r:var_log_t:s0" log
cp -a root/var/log/* log/
btrfs sub create libvirtimages
chcon "system_u:object_r:virt_image_t:s0" libvirtimages
chattr +C libvirtimages
cp -a root/var/lib/libvirt/images/* libvirtimages/
After the reboot you can check
mount that all the new subvolumes are mounted onto their respective mount points as you defined in fstab. Next comes cleanup of the old stuff.
mount /dev/vda3 /mnt
rm -rf /mnt/root/var/lib/libvirt/images/*
rm -rf /mnt/root/var/log/*
Now those are just empty dirs used as mount points for their respective subvolumes.
Note 1: If you’re using swapfiles, use the same concept as for VM images. Create a swaps subvol, chattr +C, mount it at
/var/swap and create the swapfiles per
man 5 btrfs swapfiles section. Instead of copying an existing swapfile, delete it, and create new.
Note 2: The
/ mount point in fstab is special. In effect it’s a “remount” command. It’s not possible to remount and change subvolumes. The default fstab shows
subvol=root but this can only be informational and is something of an artifact of the installer. It doesn’t hurt anything to leave it there, but it might be confusing. Conversely, the
compress mount option can be set with remount. And it’s a file system wide mount option, not per subvolume.