Snapshot the system zpool from within the initramfs
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
zfs-linux (Ubuntu) |
New
|
Wishlist
|
Unassigned |
Bug Description
Idea/enhancement request.
I wrote a small initramfs script to snapshot the zpool when booting off zfs in Ubuntu. As the pool is not actively used at that moment, it is in the perfect consistent state to take snapshots. Perhaps this is functionality more people are interested in?
To use it, you do 2 things:
- put the script in /etc/initramfs-
- add a boot parameter in the form of ZFSSNAP=xx in /etc/default/grub and run update-grub. xx has to be an integer
As I did not want to tamper with the initrd too much, it does not require any additional tools in the initrd image. However it uses the zfs-auto-snapshot syntax using "boot" as identifier instead of hourly/
As mentioned above you trigger the script when adding ZFSSNAP=xx as a grub parameter, where xx is an integer. The script will keep the last xx days that contain valid "boot" snapshots, and delete older ones. The number of snapshots on a single day is irrelevant.
The script goes in /etc/initramfs-
If this kind of functionality would be supported by the systemd import script, other zpools on the system could be snapshotted at import time as well. I considered importing my other zpools in the initramfs stage temporarily just for snapshotting them, but then decided to keep it all simple and refrain from that. Only a zpool that is defined on the kernel command line for the rootfs (root=ZFS=
So basically, if you add ZFSSNAP=4 to grub and put the script in the initrd image, you will end up with snapshots in the form 'dataset@
Disclaimer: I am not a developer so the script might not be a piece of art. It does the job though.
Changed in zfs-linux (Ubuntu): | |
importance: | Undecided → Wishlist |
tags: | added: patch |
For the additional pools one might have, I adapted the script so it snapshots everything else.
To trigger the script I added a new service zfs-import- scan.service, and I adapted the existing zfs-mount.service to include it. This way additional zpools will be snapshotted right after being imported, and before mounting takes place. The script doing the work is called zfs-systemd-snap.
I keep both the initramfs and systemd solution in place on my systems because the rootfs has been pivoted when systemd runs and the whole goal of this is to snapshot zpools without them being written to. I did make sure not to snapshot a zpool twice.
To test the additional systemd stuff: scan.service to /etc/systemd/system and run "systemctl enable zfs-import- scan.service"
- add zfs-systemd-snap to /etc/systemd
- add zfs-import-
- add zfs-mount.service to /etc/systemd/system and run "systemctl enable zfs-mount.service"
That's basically it, it should run based on the same GRUB parameter mentioned before behaving the same way.
Disclaimer: when executing the steps above you are effectively overriding the default zfs-mount.service script provided by the Ubuntu-provided zfs packages. If the unit file gets updated in the future, this will no longer be reflected on your system.