Systemd doesn’t really use runlevels anymore. But dracut has some “hooks” that work very much like the old sysv init runlevels did (they even prefix a two-digit number to order things within the hook).
Here is a simple way that you could write a script and embed it in the pre-pivot stage/hook during system startup.
First, create a /tmp/snapshot.sh file containing only the following line. It is a shell script that will be “sourced” during system startup.
uname -r > /sysroot/snapshot.log
Next, run the following command to embed the script in your current initramfs.
sudo dracut --force --include /tmp/snapshot.sh /usr/lib/dracut/hooks/pre-pivot/snapshot.sh /boot/$(</etc/machine-id)/$(uname -r)/initrd
And that’s it! When you reboot your PC, the script should be sourced during the pre-pivot stage of system startup and it should create a “snapshot.log” file at the root of your filesystem containing the current kernel version. If this works for you, then you should be able to substitute some btrfs commands that will create snapshots of the root filesystem under whatever conditions you decide to test.
Once you’ve developed the snapshot.sh script, the next step would be to write an actual dracut module that would embed the script in the initramfs and then package that as an RPM.
HTH,
gb