Skip to content

Commit

Permalink
Add a contrib script to snapshot the BE prior to boot
Browse files Browse the repository at this point in the history
  • Loading branch information
zdykstra committed Jun 28, 2022
1 parent fb98c59 commit f2d3336
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions contrib/snapshot-teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

## A simple teardown hook to take a clean snapshot of the boot environment
## prior to launching the new kernel. This requires that your pool be read-write
## and will always export it.
##
## To use, put this script somewhere, make sure it is executable, and add the
## path to the `zfsbootmenu_teardown` space-separated list with, e.g.,
##
## zfsbootmenu_teardown+=" <path to script> "
##
## in a dracut.conf(5) file inside the directory specified for the option
## `Global.DracutConfDir` in the ZFSBootMenu `config.yaml`.

# exit early if we're missing our env var
[ -n "${ZBM_SELECTED_BE}" ] || exit

for src in /lib/zfsbootmenu-core.sh /lib/kmsg-log-lib.sh ; do
# shellcheck disable=SC1090
source "${src}" || exit
done

zpool="${ZBM_SELECTED_BE%%/*}"

if ! zpool list -H -o name "${zpool}" >/dev/null 2>&1 ; then
read_write=true import_pool "${zpool}"
else
set_rw_pool "${zpool}"
fi

printf -v snapshot "${ZBM_SELECTED_BE}@preboot-%(%Y-%m-%d-%H%M%S)T"
zfs snapshot "${snapshot}"
export_pool "${zpool}"

0 comments on commit f2d3336

Please sign in to comment.