Mini-tutorial creating a snapshot in QV
The boot menu in QV, in the initrd, has an item to choose to create a new snapshot. Scroll down this blog post, there is a photo; it is item number 4 in the menu, "Take a snapshot". What it does is take a snapshot of the current default snapshot.
To understand what is going on with this snapshot feature of
btrfs, you can create one manually. This is a bit of a learning
exercise about btrfs and how QV implements it.
The previous blog post, announcing the 250605 version of QV, also
has a brief overview of QV:
- QV version 250605 released — June 05, 2025
...overview needs to be fleshed out a lot more.
You guys who are familiar with Puppy Linux, Puppy-derivatives and Puppy-like distributions, will know about a "frugal" install. QV is a specific type, it is a "full frugal". That is, it looks like a normal Linux installation, with folders /dev, /sys, /proc, /etc, /usr, etc., except in a folder, not at "/". In the case of QV in a USB-drive, it looks like this:
...that path needs explanation...
sdc2 is the btrfs partition, folder 'quantumvis' is the frugal installation of QV. Then there are sub-folders "4/@qv" ... that needs explaining!
Back-tracking, after having written 'qv-250605-amd64.img' file to
the USB-drive, and boot, there are only two folders;
/mnt/sdc2/quantumvis/1 and /mnt/sdc2/quantumvis/2. "1" and "2" are
just folder names. They each hold one snapshot, so the folder
naming 1, 2, etc., is an organizational thing.
Folder "@qv" is also just a folder name, except it has mounted on it a btrfs subvolume. The "@" prefix is just a folder-naming convention, so that we know this folder has a btrfs filesystem on it.
On a subsequent bootup of the USB-drive, I chose to create a new snapshot; that is item-4 "Take a snapshot", and that automatically became number 3. So, looking with ROX-Filer, we see there is now a folder "3":
What would be very good is to create a snapshot manually, so as to understand better how it works. I am also doing it to refresh my memory, having left QV and btrfs back in November 2024.
So, current situation is QV is running, there are three snapshots, and the current one is "1". So, let us create a snapshot of "1", and number it "4":
Firstly, although we know in my case that the working-partition is sdc2 and frugally-installed in folder 'quantumvis', it can also be found like this:
# . /etc/rc.d/PUPSTATE
# echo $WKG_DEV
sdc2
# echo $WKG_DIR
quantumvis/
#
Creating a snapshot is really easy:
# mkdir /mnt/${WKG_DEV}/${WKG_DIR}4
# btrfs subvolume snapshot /mnt/${WKG_DEV}/${WKG_DIR}1/@qv /mnt/${WKG_DEV}/${WKG_DIR}4
Now there is folder "4":
Now look in folder "4":
the btrfs subvolume filesystem "1/@qv" has been "copied" to "4/@qv", except there is no actual file copying involved; the snapshot happens in the blink of an eye. "4" behaves completely different, and is completely independent of "1" ...well, this is the magic of the btrfs copy-on-write filesystem.
Look at the photo at top of this blog post, it shows what is inside 4/@qv
Note: don't be confused by the word "subvolume". It is just a nested btrfs filesystem inside another btrfs filesystem. Normally, we have, say, ext4, with a single filesystem occupying the entire partition. Nesting a filesysystem may take awhile to get your head around, but ultimately you will see it as a simple concept.
To make this into a bonafide new snapshot, the file 'snapshot-record' needs to be edited (see above photo). Append a line, like this, in format number-date-description:
1|250605|Original Snapshot
2|250605|Snapshot of pristine first bootup
3|250605|test snapshot
4|250606|manually created snapshot of 1
Next thing I did was reboot, to see if can change into this new snapshot...
...this is the menu in the initrd. I selected item-6, "Choose a snapshot to boot into". Then got this:
...I chose item-4, clicked on "OK", then got a desktop:
...see the text at top of the screen, letting you know what snapshot is currently running. This is now the default.
We could keep going, making more snapshots. Some users of btrfs have hundreds of them. Interesting discussion on this, one person suggesting keep it no more than about 100:
https://unix.stackexchange.com/questions/140360/practical-limit-on-the-number-of-btrfs-snapshots
...yes, deleting a snapshot that has children-snapshots (grandchildren etc.) can apparently take awhile.
That reminds me, I wrote about deleting snapshots in QV, in 2024:
- QV snapshot deletion — April 15, 2024
...commented on the potential issue with children and grandchildren.
A clarification, if you have btrfs snapshot experience on other Linux distros:
Some other distros may only snapshot some folders, especially the /home folder. QV is different, it snapshots the entire "/" filesystem. With the exception that folder /files is a separate encrypted ext4 filesystem in a sparse file; the same /files appears in all snapshots.
Look at an above photo, there is file '.sparse-ext4' -- that is the ext4 sparse file. It is mounted on folder '.sparse-mnt' -- .sparse-ext4 is loop-mounted on that, then bind-mounted to /files in all snapshots.
This little mini-tutorial is a diversion. I've been rethinking some structure of QV, got kexec to work; so getting back onto that. Well, tomorrow.
If you would like to provide feedback, there is a forum topic to discuss btrfs snapshots here (hint: woofwoof):
https://forum.puppylinux.com/viewtopic.php?t=14548
Tags: quirky