Skip to content

Commit ff59562

Browse files
zdykstraZach Dykstraahesford
committed
zfsbootmenu: refactor installation, support system and user runtime hooks
- All core components, docs and runtime hooks are handled by a common install_helper that is aware of both dracut and mkinitcpio methods - Installation now adds "system" runtime hooks in addition to those configured by the user; user hooks with names that conflict with system hooks will "mask" the system version - The hooks `10-console-init.sh` and `xhci-teardown.sh` have been elevated to "system" status and are always installed in ZBM images - The `zfsbootmenu/hook` path has been renamed to `zfsbootmenu/pre-init` to avoid confusion with the new `zfsbootmenu/hooks` directory of system runtime hooks, and the dracut-only `hook` scripts have been moved to the dracut module - A new `zbm.skip_hooks` command-line argument allows a comma-separated list of hooks to skip (matched on basename only) to provide an easy mechanism for skipping default hooks without `zbm.hookroot` - Create the `zfsbootmenu-run-hooks` libexec helper, allowing easy addition of future hook points. Co-authored-by: Zach Dykstra <[email protected]> Co-authored-by: Andrew J. Hesford <[email protected]>
1 parent e5cfb46 commit ff59562

File tree

15 files changed

+230
-140
lines changed

15 files changed

+230
-140
lines changed

docs/man/zfsbootmenu.7.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ These options are set on the kernel command line when booting the initramfs or U
133133
134134
zbm.kcl_override="some alternate set='of arguments'"
135135
136+
**zbm.skip_hooks=<hooklist>**
137+
138+
Skip execution of any early-setup, setup or teardown hooks with file names matching any entry in the comma-separated list *hooklist*. Only base names of hooks (*i.e.*, with any other path component removed) are matched against the *hooklist*.
139+
140+
**NOTE**: The *hooklist* argument **MUST NOT** contain spaces and **MUST NOT** be enclosed in quotes.
141+
136142
Deprecated Command-Line Parameters
137143
==================================
138144

dracut/module-setup.sh

Lines changed: 19 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ install() {
4040
# BUILDROOT is an initcpio-ism
4141
# shellcheck disable=SC2154,2034
4242
BUILDROOT="${initdir}"
43+
4344
# shellcheck disable=SC2034
44-
BUILDSTYLE="dracut"
45+
ZBM_BUILDSTYLE="dracut"
4546

4647
local _rule _exec _ret
4748

@@ -84,90 +85,43 @@ install() {
8485
fi
8586
done <<< "${_libgcc_s}"
8687

87-
# shellcheck disable=SC2154
88-
while read -r doc ; do
89-
relative="${doc//${zfsbootmenu_module_root}\//}"
90-
inst_simple "${doc}" "/usr/share/docs/${relative}"
91-
done <<<"$( find "${zfsbootmenu_module_root}/help-files" -type f )"
92-
9388
compat_dirs=( "/etc/zfs/compatibility.d" "/usr/share/zfs/compatibility.d/" )
9489
for compat_dir in "${compat_dirs[@]}"; do
9590
# shellcheck disable=2164
9691
[ -d "${compat_dir}" ] && tar -cf - "${compat_dir}" | ( cd "${initdir}" ; tar xfp - )
9792
done
98-
_ret=0
9993

100-
# Core ZFSBootMenu functionality
101-
# shellcheck disable=SC2154
102-
for _lib in "${zfsbootmenu_module_root}"/lib/*; do
103-
inst_simple "${_lib}" "/lib/$( basename "${_lib}" )" || _ret=$?
104-
done
94+
_ret=0
10595

106-
# Helper tools not intended for direct human consumption
107-
for _libexec in "${zfsbootmenu_module_root}"/libexec/*; do
108-
inst_simple "${_libexec}" "/libexec/$( basename "${_libexec}" )" || _ret=$?
109-
done
96+
# Install core ZFSBootMenu functionality
97+
install_zbm_core || _ret=$?
11098

111-
# User-facing utilities, useful for running in a recovery shell
112-
for _bin in "${zfsbootmenu_module_root}"/bin/*; do
113-
inst_simple "${_bin}" "/bin/$( basename "${_bin}" )" || _ret=$?
114-
done
99+
# Install runtime hooks
100+
install_zbm_hooks || _ret=$?
115101

116102
# Hooks necessary to initialize ZBM
117-
inst_hook cmdline 95 "${zfsbootmenu_module_root}/hook/zfsbootmenu-parse-commandline.sh" || _ret=$?
118-
inst_hook pre-mount 90 "${zfsbootmenu_module_root}/hook/zfsbootmenu-preinit.sh" || _ret=$?
103+
inst_hook cmdline 95 "${zfsbootmenu_module_root}/pre-init/zfsbootmenu-parse-commandline.sh" || _ret=$?
104+
inst_hook pre-mount 90 "${zfsbootmenu_module_root}/pre-init/zfsbootmenu-preinit.sh" || _ret=$?
119105

120106
# Hooks to force the dracut event loop to fire at least once
121107
# Things like console configuration are done in optional event-loop hooks
122-
inst_hook initqueue/settled 99 "${zfsbootmenu_module_root}/hook/zfsbootmenu-ready-set.sh" || _ret=$?
123-
inst_hook initqueue/finished 99 "${zfsbootmenu_module_root}/hook/zfsbootmenu-ready-chk.sh" || _ret=$?
124-
125-
# optionally enable early Dracut profiling
126-
if [ -n "${dracut_trace_enable}" ]; then
127-
inst_hook cmdline 00 "${zfsbootmenu_module_root}/profiling/profiling-lib.sh"
128-
fi
129-
130-
# Install "early setup" hooks
131108
# shellcheck disable=SC2154
132-
if [ -n "${zfsbootmenu_early_setup}" ]; then
133-
for _exec in ${zfsbootmenu_early_setup}; do
134-
if [ -x "${_exec}" ]; then
135-
inst_simple "${_exec}" "/libexec/early-setup.d/$(basename "${_exec}")" || _ret=$?
136-
else
137-
dwarning "setup script (${_exec}) missing or not executable; cannot install"
138-
fi
139-
done
140-
fi
141-
142-
# Install "setup" hooks
143-
# shellcheck disable=SC2154
144-
if [ -n "${zfsbootmenu_setup}" ]; then
145-
for _exec in ${zfsbootmenu_setup}; do
146-
if [ -x "${_exec}" ]; then
147-
inst_simple "${_exec}" "/libexec/setup.d/$(basename "${_exec}")" || _ret=$?
148-
else
149-
dwarning "setup script (${_exec}) missing or not executable; cannot install"
150-
fi
151-
done
152-
fi
153-
154-
# Install "teardown" hooks
155-
# shellcheck disable=SC2154
156-
if [ -n "${zfsbootmenu_teardown}" ]; then
157-
for _exec in ${zfsbootmenu_teardown}; do
158-
if [ -x "${_exec}" ]; then
159-
inst_simple "${_exec}" "/libexec/teardown.d/$(basename "${_exec}")" || _ret=$?
160-
else
161-
dwarning "teardown script (${_exec}) missing or not executable; cannot install"
162-
fi
163-
done
164-
fi
109+
inst_hook initqueue/settled 99 "${moddir}/zfsbootmenu-ready-set.sh" || _ret=$?
110+
inst_hook initqueue/finished 99 "${moddir}/zfsbootmenu-ready-chk.sh" || _ret=$?
165111

166112
if [ ${_ret} -ne 0 ]; then
167113
dfatal "Unable to install core ZFSBootMenu functions"
168114
exit 1
169115
fi
170116

117+
# Install online documentation if possible
118+
install_zbm_docs
119+
120+
# optionally enable early Dracut profiling
121+
if [ -n "${dracut_trace_enable}" ]; then
122+
inst_hook cmdline 00 "${zfsbootmenu_module_root}/profiling/profiling-lib.sh"
123+
fi
124+
171125
# vdev_id.conf and hostid files are host-specific
172126
# and do not belong in public release images
173127
if [ -z "${release_build}" ]; then

etc/zfsbootmenu/release.conf.d/common.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
zfsbootmenu_teardown+=" /zbm/contrib/xhci-teardown.sh "
2-
zfsbootmenu_early_setup+=" /zbm/contrib/10-console-init.sh /zbm/contrib/20-console-autosize.sh "
1+
zfsbootmenu_early_setup+=" /zbm/contrib/20-console-autosize.sh "
32

43
# zbm-kcl
54
install_optional_items+=" /zbm/bin/zbm-kcl "

initcpio/install/zfsbootmenu

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ build() {
122122
source "${zfsbootmenu_module_root}/install-helpers.sh" || exit 1
123123

124124
# shellcheck disable=SC2034
125-
BUILDSTYLE="initcpio"
125+
ZBM_BUILDSTYLE="mkinitcpio"
126126

127127
# Modules (required and optional) used by ZBM
128128
# shellcheck disable=SC2154
@@ -154,52 +154,32 @@ build() {
154154
fi
155155
done <<< "${_libgcc_s}"
156156

157-
# On-line documentation
158-
while read -r doc; do
159-
relative="${doc#"${zfsbootmenu_module_root}/"}"
160-
[ "${relative}" = "${doc}" ] && continue
161-
add_file "${doc}" "/usr/share/docs/${relative}"
162-
done <<< "$( find "${zfsbootmenu_module_root}/help-files" -type f )"
163-
164157
# Install core ZBM functionality
165-
for _file in "${zfsbootmenu_module_root}"/lib/*; do
166-
add_file "${_file}" "/lib/${_file##*/}"
167-
done
158+
if ! install_zbm_core; then
159+
error "Failed to install ZFSBootMenu core"
160+
exit 1
161+
fi
168162

169-
for _file in "${zfsbootmenu_module_root}"/libexec/*; do
170-
add_file "${_file}" "/libexec/${_file##*/}"
171-
done
163+
# Install runtime hooks
164+
if ! install_zbm_hooks; then
165+
error "Failed to install runtime hooks"
166+
exit 1
167+
fi
172168

173-
for _file in "${zfsbootmenu_module_root}"/bin/*; do
174-
add_file "${_file}" "/bin/${_file##*/}"
175-
done
169+
# Install online documentation if possible
170+
install_zbm_docs
176171

177-
hooks=( zfsbootmenu-{parse-commandline,preinit}.sh )
178-
for _file in "${hooks[@]}"; do
179-
add_file "${zfsbootmenu_module_root}/hook/${_file}" "/lib/${_file}"
172+
# Install pre-init scripts
173+
for _file in "${zfsbootmenu_module_root}"/pre-init/*; do
174+
add_file "${_file}" "/lib/${_file##*/}" && continue;
175+
176+
error "Failed to install ZFSBootMenu component ${_file}"
177+
exit 1
180178
done
181179

182180
# allow mount(8) to "autodetect" ZFS
183181
echo 'zfs' >>"${BUILDROOT}/etc/filesystems"
184182

185-
# shellcheck disable=SC2154
186-
for _file in "${zfsbootmenu_early_setup[@]}"; do
187-
[ -x "${_file}" ] || continue
188-
add_file "${_file}" "/libexec/early-setup.d/${_file##*/}"
189-
done
190-
191-
# shellcheck disable=SC2154
192-
for _file in "${zfsbootmenu_setup[@]}"; do
193-
[ -x "${_file}" ] || continue
194-
add_file "${_file}" "/libexec/setup.d/${_file##*/}"
195-
done
196-
197-
# shellcheck disable=SC2154
198-
for _file in "${zfsbootmenu_teardown[@]}"; do
199-
[ -x "${_file}" ] || continue
200-
add_file "${_file}" "/libexec/teardown.d/${_file##*/}"
201-
done
202-
203183
compat_dirs=( "/etc/zfs/compatibility.d" "/usr/share/zfs/compatibility.d/" )
204184
for compat_dir in "${compat_dirs[@]}"; do
205185
[ -d "${compat_dir}" ] && add_full_dir "${compat_dir}"

zfsbootmenu/bin/zfsbootmenu

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,8 @@ if [ -r "${BASE}/bootfs" ]; then
6868
fi
6969

7070
# Run setup hooks, if they exist
71-
if [ -d /libexec/setup.d ]; then
72-
tput clear
73-
for _hook in /libexec/setup.d/*; do
74-
zinfo "Processing hook: ${_hook}"
75-
[ -x "${_hook}" ] && "${_hook}"
76-
done
77-
unset _hook
78-
fi
71+
tput clear
72+
/libexec/zfsbootmenu-run-hooks "setup.d"
7973

8074
# Clear screen before a possible password prompt
8175
tput clear

contrib/10-console-init.sh renamed to zfsbootmenu/hooks/early-setup.d/10-console-init.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
## which causes the normal dracut initqueue to be thrown out; the ZFSBootMenu
77
## initqueue hooks that force the dracut event loop to run at least once are
88
## purged, so dracut terminates the event loop before console initialization.
9+
##
10+
11+
# There is nothing to do if we're not in dracut
12+
[ "${ZBM_BUILDSTYLE,,}" = "dracut" ] || exit 0
913

1014
# There is nothing to do if the console initializer is not executable
1115
[ -x /lib/udev/console_init ] || exit 0

contrib/xhci-teardown.sh renamed to zfsbootmenu/hooks/teardown.d/90-xhci-unbind.sh

File renamed without changes.

0 commit comments

Comments
 (0)