It’s quite easy to have systemd monitor the folder and run a command on change.
I first thought about solving the problem this way but then decided against it. The above command (update grub) would be run on every change of the snapshot folder (e. g. adding, deleting snapshots) which is desired behavior BUT the grub update would then be run multiple times. For instance it would be called during a system update and then again because the folder would have changed.
The on-shutdown workaround is called only once before I actually need the grub entries (on next boot) and only adds about two to five seconds to the shutdown.
Very reasonable covering of the potential hole in the process - and better than my first simplistic thought! Too much procedural programming in my past, I suspect…
Excuse my uninformed question (all this is quite new to me and very exciting): couldn’t the “monitor-folder-chnange” be scripted separately and “baked into” the same limit-timeshift-snapshots-update-grub.service. If there is a change then the rest otherwise only shutdown?
Ran those commands and on reboot check the actual snapshots listed and I was wrong only 3 from to day were actually listed. I’m assuming 2 from updates and the 3rd which was a manual. I’m assuming the manual is only showing cause I dis a grub-update after creating that one. the other one made manually made by me today and the one I just made are not showing up. That to me is a bug. The newest snapshots should always show up on the grub snapshot menu in my book without further user intervention than creating the snapshot.
I tried to mount the “subvolume” timeshift-btrfs at /.snapshots by using its subvolid. It does mount and you can browse the content. But the problem is running Timeshift again, it creates a new subvolume. See:
sudo btrfs subvolume list -p /
.
.
ID 271 gen 4601 parent 5 top level 5 path timeshift-btrfs/snapshots/2020-09-19_15-49-33/@
ID 279 gen 4857 parent 5 top level 5 path timeshift-btrfs/snapshots/2020-09-23_23-39-40/@
So the actual subvolume is not timeshift-btrfs but timeshift-btrfs/snapshots/2020-09-19_15-49-33/@
etc…
So how to do the following from the instructions at Github:
Mount your subvolume which contains snapshots to /.snapshots
If I understand correctly, you’re asking for the shutdown service only to run if actually necessary.
On shutdown we’d have to check if the snapshot folder was modified.
The problem here is that for some of the snapshots the grub already has been updated, but not for the manual created snapshots.
So how to reliably check if a grub update is really needed?
The only thing I can think of right now is actually comparing the grub entries with the snapshot folder contents. But this is a bit of a script overkill; I think I’ll stick to my workaround for the time being .
No, I am afraid it isn’t. Otherwise the grub-btrfs.service would be triggered at any modifications in .snapshots and the problem would be solved. .snapshots need to be created by the user if I have understood it correctly.
When I looked at the system partition from “outside”, I could see @, @home and timeshift-btrfs
containing the actual snapshot folders:
I had only one on-demand snapshot ( I deleted the other ones before). But I just made a new one as well, just in case. Here is:
sudo btrfs subvolume list -sa /
ID 271 gen 4601 cgen 2015 top level 5 otime 2020-09-19 15:49:33 path <FS_TREE>/timeshift-btrfs/snapshots/2020-09-19_15-49-33/@
ID 273 gen 4946 cgen 4946 top level 5 otime 2020-09-24 00:53:51 path <FS_TREE>/timeshift-btrfs/snapshots/2020-09-24_00-53-51/@
Rather than giving myself a headache reading through the recent post I’ll simply ask the following. Why can’t a script be written to run in the background that does a grub-update when a manual snapshot is taken.
For grub-btrfs.path, i wrote this: Mount your subvolume which contains snapshots to / .snapshots
which means :
You need to create the .snapshots folder.
and you need to mount or create snapshots in it.
Why Mount your subvolume which contains snapshots ?
Because my layout of btrfs subvolume is :
@racine (my subvolume containing linux root system) @snapshots (my subvolume containing my manuals snapshots)
etc…
Your is :
@ @home
etc…
Timeshift creates its working folder at the root of the btrfs system top level 5.
You can check it like this: mount -o subvolid=5 /dev/sda1 /mnt
This will mount the root of the btrfs filesystem in /mnt.
Remember to modify /dev/sda1 if it isn’t your btrfs system partition, and /mnt if you want to mount it elsewhere.
You can see your subvolumes and timeshift working folder there.
for example:
@ @home
timeshift
etc…
Then timeshift mounts this folder to/run/timeshift...
I don’t use timeshift, but if you want to make grub-btrfs.path work, the easiest way would be to modify the service like this:
[Unit]
Description=Monitors for new snapshots
[Path]
PathModified=/run/timeshift/backup/timeshift-btrfs/snapshots
[Install]
WantedBy=multi-user.target
I recommend that you do not modify the grub-btrfs.path file, because each time the package is updated it will be overwritten.
Instead use: systemctl edit grub-btrfs.path
Write your changes and save.
To erase your changes:
use: systemctl revert grub-btrfs.path