-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a contrib script to snapshot the BE prior to boot
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |