Skip to content

Commit 640af57

Browse files
committed
Refactor user runtime hooks installation and processing
- Add new hook points: load-key.d and boot-sel.d - All hooks are installed in hook-point-specific subdirectories of /libexec/hooks instead of in the top-level /libexec - User hooks are recognized in level-specific subdirectories of a zfsbootmenu_hook_root defined for dracut or mkinitcpio - Deprecate zfsbootmenu_{early_setup,setup,teardown} variables - Take advantage of zfsbootmenu_hook_root to simplify hooks in container builds via zbm-builder.sh - Simplify zbm.hookdir overrides Closes: #477.
1 parent 1206736 commit 640af57

File tree

15 files changed

+720
-456
lines changed

15 files changed

+720
-456
lines changed

docs/guides/general/container-building.rst

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,9 @@ The default behavior of ``zbm-builder.sh`` will:
133133
Custom ZFSBootMenu Hooks
134134
~~~~~~~~~~~~~~~~~~~~~~~~
135135

136-
ZFSBootMenu supports :ref:`custom hooks <zbm-dracut-options>` in three stages:
137-
138-
1. ``early_setup`` hooks run after the ``zfs`` kernel driver has been loaded, but before ZFSBootMenu attempts to import
139-
any pools.
140-
2. ``setup`` hooks run after pools are imported, right before ZFSBootMenu will either boot a default environment or
141-
present a menu.
142-
3. ``teardown`` hooks run immediately before ZFSBootMenu will ``kexec`` the kernel for the selected environment.
143-
144-
When ``zbm-builder.sh`` runs, it will identify custom hooks as executable files in the respective subdirectories of its
145-
build directory:
146-
147-
1. ``hooks.early_setup.d``
148-
2. ``hooks.setup.d``
149-
3. ``hooks.teardown.d``
150-
151-
For each hook directory that contains at least one executable file, ``zbm-builder.sh`` will write custom configuration
152-
snippets for ``dracut`` and ``mkinitcpio`` that will include these files in the output images.
136+
ZFSBootMenu supports :ref:`custom hooks <zbm-dracut-options>` in several stages. When ``zbm-builder.sh`` runs, it will
137+
configure the subdirectory ``hooks`` of the build directory, if it exists, as the value of ``zfsbootmenu_hook_root`` to
138+
allow custom hooks to be included in ZFSBootMenu images.
153139

154140
Fully Customizing Images
155141
~~~~~~~~~~~~~~~~~~~~~~~~

docs/man/dist/man7/zfsbootmenu.7

Lines changed: 87 additions & 39 deletions
Large diffs are not rendered by default.

docs/man/zfsbootmenu.7.rst

Lines changed: 66 additions & 37 deletions
Large diffs are not rendered by default.

dracut/module-setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ installkernel() {
3030

3131
install() {
3232
: "${zfsbootmenu_module_root:=/usr/share/zfsbootmenu}"
33+
: "${zfsbootmenu_hook_root:=/etc/zfsbootmenu/hooks}"
3334

3435
# shellcheck disable=SC1091
3536
if ! source "${zfsbootmenu_module_root}/install-helpers.sh" ; then

etc/zbm-builder/mkinitcpio.conf

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@ HOOKS=(base udev autodetect modconf block filesystems keyboard)
2424
# dracut.conf.d
2525
# mkinitcpio.conf.d
2626
#
27-
# of the build directory for any hook found in the subdirectories
28-
#
29-
# hooks.early_setup.d
30-
# hooks.setup.d
31-
# hooks.teardown.d
32-
#
33-
# of the same build directory. Support for mkinitcpio.conf.d mimics similar
34-
# support for dracut.conf.d built directly into dracut.
27+
# of the build directory for any hooks found in the hooks subdirectory of the
28+
# build directory. Support for mkinitcpio.conf.d mimics similar support for
29+
# dracut.conf.d built directly into dracut.
3530
#
3631
# Note that, inside the container, the build directory will be mounted at
3732
# /build, so reference those paths here.

etc/zfsbootmenu/mkinitcpio.conf

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,8 @@ HOOKS=(base udev autodetect modconf block filesystems keyboard zfsbootmenu)
7575
# tested and may break some (non-essential) ZFSBootMenu features.
7676
#zfsbootmenu_miser="no"
7777

78-
# zfsbootmenu_early_setup, zfsbootmenu_setup, zfsbootmenu_teardown
78+
# zfsbootmenu_hook_root
7979
# ZFSBootMenu supports user-provided hooks that may be run at various points in
80-
# the boot process. Set each of these variables to an array of executable files
81-
# that should be installed as user hooks in the provided image. Files that are
82-
# not executable will be ignored. See the zfsbootmenu(7) manual page for more
83-
# details about these hooks.
84-
#
85-
# 'zfsbootmenu_early_setup' hooks are run after ZFS modules are loaded, but
86-
# before ZFSBootMenu attempts to import any pools. Hooks here, for example, can
87-
# unlock LUKS volumes or otherwise manage devices that must be made available
88-
# before a pool can be recognized.
89-
#
90-
# 'zfsbootmenu_setup' hooks are run after pools are imported and right before
91-
# the menu is presented.
92-
#
93-
# 'zfsbootmenu_teardown' hooks are run immediately before a chosen boot
94-
# environment is about to be launched. Any writable ZFS pools will have been
95-
# exported, but read-only pools will generally still be available.
96-
#
97-
#zfsbootmenu_early_setup=()
98-
#zfsbootmenu_setup=()
99-
#zfsbootmenu_teardown=()
80+
# the boot process. Set zfsbootmenu_hook_root to the path of the hooks tree
81+
# that includes a subdirectory for each hook point.
82+
#zfsbootmenu_hook_root="/etc/zfsbootmenu/hooks"

initcpio/install/zfsbootmenu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ create_zbm_entrypoint() {
114114

115115

116116
build() {
117-
local hooks relative _file
117+
local _file
118118

119119
: "${zfsbootmenu_module_root:=/usr/share/zfsbootmenu}"
120+
: "${zfsbootmenu_hook_root:=/etc/zfsbootmenu/hooks}"
120121

121122
# shellcheck disable=SC1091
122123
source "${zfsbootmenu_module_root}/install-helpers.sh" || exit 1

testing/run.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ if [ -n "${DISPLAY_TYPE}" ]; then
242242
# Add release hooks, supported only under Dracut
243243
if ((DRACUT)); then
244244
cat <<-EOF >> "${TESTDIR}/dracut.conf.d/testing.conf"
245-
zfsbootmenu_early_setup+=" $( realpath -e ../contrib )/10-console-init.sh "
246245
zfsbootmenu_early_setup+=" $( realpath -e ../contrib )/20-console-autosize.sh "
247246
EOF
248247
fi

zbm-builder.sh

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -239,32 +239,17 @@ if ! [ -r "${BUILD_DIRECTORY}"/config.yaml ]; then
239239
fi
240240

241241
# Try to include ZBM hooks in the images by default
242-
for stage in early_setup setup teardown; do
243-
[ -d "${BUILD_DIRECTORY}/hooks.${stage}.d" ] || continue
244-
245-
# Only executable hooks are added to the image
246-
hooks=()
247-
for f in "${BUILD_DIRECTORY}/hooks.${stage}.d"/*; do
248-
[ -x "${f}" ] || continue
249-
hooks+=( "/build/hooks.${stage}.d/${f##*/}" )
250-
done
251-
252-
[ "${#hooks[@]}" -gt 0 ] || continue
253-
254-
hconf="zbm-builder.${stage}.conf"
255-
242+
if [ -d "${BUILD_DIRECTORY}/hooks" ]; then
256243
# Write a dracut configuration snippet
257244
mkdir -p "${BUILD_DIRECTORY}/dracut.conf.d"
258-
echo "zfsbootmenu_${stage}+=\" ${hooks[*]} \"" > "${BUILD_DIRECTORY}/dracut.conf.d/${hconf}"
245+
echo "zfsbootmenu_hook_root=/build/hooks" \
246+
> "${BUILD_DIRECTORY}/dracut.conf.d/user_hooks.conf"
259247

260248
# Write a mkinitcpio configuration snippet
261249
mkdir -p "${BUILD_DIRECTORY}/mkinitcpio.conf.d"
262-
echo "zfsbootmenu_${stage}=(" > "${BUILD_DIRECTORY}/mkinitcpio.conf.d/${hconf}"
263-
for hook in "${hooks[@]}"; do
264-
echo " \"${hook}\"" >> "${BUILD_DIRECTORY}/mkinitcpio.conf.d/${hconf}"
265-
done
266-
echo ")" >> "${BUILD_DIRECTORY}/mkinitcpio.conf.d/${hconf}"
267-
done
250+
echo "zfsbootmenu_hook_root=/build/hooks" \
251+
> "${BUILD_DIRECTORY}/mkinitcpio.conf.d/user_hooks.conf"
252+
fi
268253

269254
# Make `/build` the working directory so relative paths in configs make sense
270255
exec "${PODMAN}" run \

0 commit comments

Comments
 (0)