User Tools

Site Tools


linux:fedora

Fedora

GRUB Btrfs snapshots

From this comment.

Set-up Snapper & Btrfs-assistant

sudo dnf install btrfs-assistant snapper python3-dnf-plugin-snapper libdnf5-plugin-actions
sudo snapper -c root create-config /
sudo snapper -c home create-config /home

Create /etc/dnf/libdnf5-plugins/actions.d/snapper.actions and add the following lines:

# Get the snapshot description
pre_transaction::::/usr/bin/sh -c echo\ "tmp.cmd=$(ps\ -o\ command\ --no-headers\ -p\ '${pid}')"
# Creates pre snapshots for root and home and stores snapshot numbers in variables
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre_root=$(snapper\ -c\ root\ create\ -t\ pre\ -p\ -d\ '${tmp.cmd}')"
pre_transaction::::/usr/bin/sh -c echo\ "tmp.snapper_pre_home=$(snapper\ -c\ home\ create\ -t\ pre\ -p\ -d\ '${tmp.cmd}')"
# Creates post snapshots for root and home if pre snapshot numbers exist
post_transaction::::/usr/bin/sh -c [\ -n\ "${tmp.snapper_pre_root}"\ ]\ &&\ snapper\ -c\ root\ create\ -t\ post\ --pre-number\ "${tmp.snapper_pre_root}"\ -d\ "${tmp.cmd}"
post_transaction::::/usr/bin/sh -c [\ -n\ "${tmp.snapper_pre_home}"\ ]\ &&\ snapper\ -c\ home\ create\ -t\ post\ --pre-number\ "${tmp.snapper_pre_home}"\ -d\ "${tmp.cmd}"

Setup grub-btrfs

Download the latest release from https://github.com/Antynea/grub-btrfs/releases

Unzip, enter the directory and run:

sudo make install

Uncomment and change the following options in /etc/default/grub-btrfs/config

GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"
GRUB_BTRFS_BOOT_DIRNAME="/boot"
GRUB_BTRFS_MKCONFIG=grub2-mkconfig
GRUB_BTRFS_SCRIPT_CHECK=grub2-script-check
GRUB_BTRFS_MKCONFIG_LIB=/usr/share/grub/grub-mkconfig_lib

I couldn't get the included systemd unit to trigger the grub update but it can be done as follows:

Go back to the /etc/dnf/libdnf5-plugins/actions.d/snapper.actions you created earlier and add the following lines at the bottom:

# Update grub with the new snapshots
post_transaction::::/usr/bin/sh -c /etc/grub.d/41_snapshots-btrfs

this will trigger the grub update after each package install so that the grub snapshot menu is always up to date.

You can also manually update the grub snapshot menu by running:

sudo /etc/grub.d/41_snapshots-btrfs

linux/fedora.txt · Last modified: by khorvath