Public bug reported:

10_linux_zfs mounts every snapshot of each root dataset to look for
kernels. Snapshot tools such as zrepl, sanoid and zfs-auto-snapshot
create snapshots on a schedule, so a root dataset can have hundreds of
snapshots. Each run of update-grub then mounts and inspects all of them.

This has three effects:

1. update-grub takes longer as the number of snapshots grows.
2. Any failure while the script inspects a snapshot stops update-grub. Bug 
2170880 is one example. More snapshots give more chances to hit such a failure.
3. On the default layout, kernels are on the boot pool (bpool). These tools 
usually snapshot only the root pool, so their snapshots never contain a kernel. 
The scan finds nothing and prints "Warning: didn't find any valid initrd or 
kernel." for each snapshot.

The script also gives a date label only to snapshots named autozsys_*.
Snapshots from other tools show their raw names in the menu.

No configuration option exists to exclude snapshots or to limit how many
the script inspects.

Steps to reproduce

1. Install Ubuntu with the root filesystem on ZFS.
2. Create many snapshots of the root dataset, for example:
   for i in $(seq 1 50); do sudo zfs snapshot rpool/ROOT/ubuntu@test_$i; done
3. Run "sudo update-grub" and count the warnings.
  
Actual result
  
update-grub mounts all 50 snapshots and prints one warning for each.
  
Expected result
  
The administrator can exclude snapshots by name or limit the number 
thatupdate-grub inspects.
     
Proposed change

Add two settings for /etc/default/grub:

- GRUB_ZFS_SNAPSHOT_EXCLUDE: an extended regular expression. Snapshots whose 
full name matches it are not inspected. Example for zrepl:
  GRUB_ZFS_SNAPSHOT_EXCLUDE='@zrepl_[0-9]{8}_[0-9]{6}_[0-9]{3}$'

- GRUB_ZFS_SNAPSHOT_LIMIT: the number of newest snapshots to inspect for
each root dataset, after the exclusion.

In my case, I ran:
sudo tee /etc/default/grub.d/zfs-snapshots.cfg <<'EOF'
export GRUB_ZFS_SNAPSHOT_EXCLUDE='@zrepl_[0-9]{8}_[0-9]{6}_[0-9]{3}$'
export GRUB_ZFS_SNAPSHOT_LIMIT=3
EOF

The attached patch implements both settings in the snapshot loop of
10_linux_zfs. It also sorts the snapshot list by creation time, so the
limit always keeps the newest snapshots. With neither setting present,
the script behaves as before. grub-mkconfig exports only a fixed list of
GRUB_* variables, so the two names also need to be in that list. Until
then, users can write "export" before each setting in /etc/default/grub.

A further option needs no configuration: when /boot is on a separate
boot pool, skip each root snapshot that has no boot pool snapshot with
the same name. Such a snapshot cannot boot, so the scan of it is never
useful. This handles all snapshot tools without knowledge of their
naming.

Versions

zfsutils-linux 2.4.1-1ubuntu5.1
grub2-common: 2.14-2ubuntu2.1

** Affects: grub2 (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: zfs

** Patch added: "Patch against /etc/grub.d/10_linux_zfs"
   
https://bugs.launchpad.net/bugs/2170892/+attachment/6009274/+files/10_linux_zfs-snapshot-filter.patch

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2170892

Title:
  10_linux_zfs scans every snapshot of the root dataset; provide a way
  to exclude or limit snapshots

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/2170892/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to