site  contact  subhomenews

QV snapshot management

April 01, 2024 — BarryK

Snapshots are a very exciting feature of btrfs. In Puppy Linux, you know that you can copy a "save file", then at bootup choose which save-file you want to use. In brtrfs, a snapshot is like that; however, it is not a copy, nor is it a file.

Brtfs is a COW filesystem, meaning "Copy On Write". This enables a snapshot, similar to creating a Puppy save-file, but it happens almost instantly, with no copying. Quoting from here:

In Btrfs, it uses Copy-On-Write (COW). Every file update is stored in a separate block, and the original file pointer points to this updated data block. So, in a snapshot, there’s no actual copying of files or folders; instead, we freeze the state of the pointers pointing to the data blocks.

For example, if we have 10 GB of data in a sub-volume and create a snapshot, it might seem like a copy-paste, but the total size consumed remains 10 GB. Updating the original sub-volume only takes up space for the newly updated data, not duplicating the entire content.

I have implemented snapshot management in QV. At bootup, there is a menu in the initrd:

img1

I showed this menu in a post about Lockdown, a couple of days ago:

https://bkhome.org/news/202403/qv-lockdown-implemented.html

...at that time, there were snapshot items, but not yet implemented. I have also now added item-7.

Choosing item-3:

img2

Choosing "OK", next window:

img3

After bootup, taking a look at the directory hierarchy:

img4

I have re-organized the directory hierarchy. Folder '1' is the original installation, '2' is the snapshot. '@files' is at the same level, as it will be bind-mounted in all snapshots, as folder /files -- this is for your personal storage, and is not snapshotted. Your photo collection, for example, will be available in all snapshots.

Looking into folder '2':

img6

...'@qv' is the folder that becomes '/', the rootfs, with '@data' bind-mounted as '/data' and '@home' as /home -- these are private to the snapshot. Initially, these three folders are snapshots of the previous current snapshot.

I don't want to explain too much, as just doing it is simple. You bootup and you are in a new snapshot. Only /files has not been snapshotted, as it is common to all snapshots. That is, you download a file into /files, and it is available in all snapshots.

OK, now running in snapshot '2', which is now the default. At a reboot, though, can choose item-4 "Choose snapshot to boot into":

img7

Choose '1':

img8

...back at the original installation!

This snapshot mechanism is really neat. Each snapshot is entirely independent, and they all have the full free space of the partition to play in. You could setup a snapshot just for compiling, another for video editing. Oh, and as Void is a rolling-release if you do a package update in one snapshot, that breaks things, can bootup a different snapshot.

And yes, you can look inside other snapshots. Just click on the "sdc2" desktop icon, and poke around, do whatever you want. It is only in Lockdown mode that you cannot do that.

Haven't yet implemented deleting of snapshots; will do that.  

Tags: quirky