Skip to content

Commit 1ca3cf4

Browse files
committed
Define BE selection variables in teardown hook environment
To allow completely custom overrides of the final boot process, teardown hooks are called with three variables in their environment: - ZBM_SELECTED_BE: filesystem holding the selected boot environment - ZBM_SELECTED_KERNEL: path to the kernel within the selected BE - ZBM_SELECTED_INITRAMFS: path to the corresponding initramfs This is motivated by a desire to allow Xen users to inject a load/kexec into the following stage, effectively making ZBM responsible for selecting dom0 without making ZBM understand Xen at all. Closes #231.
1 parent 6789ee2 commit 1ca3cf4

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

90zfsbootmenu/zfsbootmenu-lib.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,10 @@ kexec_kernel() {
782782
# Run teardown hooks, if they exist
783783
if [ -d /libexec/teardown.d ]; then
784784
for tdhook in /libexec/teardown.d/*; do
785+
[ -x "${tdhook}" ] || continue
785786
zinfo "Processing hook: ${tdhook}"
786-
[ -x "${tdhook}" ] && "${tdhook}"
787+
env "ZBM_SELECTED_INITRAMFS=${initramfs}" \
788+
"ZBM_SELECTED_KERNEL=${kernel}" "ZBM_SELECTED_BE=${fs}" "${tdhook}"
787789
done
788790
unset tdhook
789791
fi

man/zfsbootmenu.7

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
.\" ========================================================================
134134
.\"
135135
.IX Title "zfsbootmenu 7"
136-
.TH zfsbootmenu 7 "2021-10-31" "1.11.0" "ZFSBootMenu"
136+
.TH zfsbootmenu 7 "2021-11-19" "1.11.0" "ZFSBootMenu"
137137
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
138138
.\" way too many mistakes in technical documents.
139139
.if n .ad l
@@ -299,7 +299,30 @@ Any installed hooks are run right before the ZFSBootMenu menu will be presented;
299299
.IX Item "zfsbootmenu_teardown=<executable-list>"
300300
An optional variable specifying a space-separated list of paths to teardown hooks that will be installed in the ZFSBootMenu initramfs. Any path in the list \fB<executable\-list>\fR that exists and is executable will be installed.
301301
.Sp
302-
Some hardware initialized by the kernel used to boot ZFSBootMenu may not be properly reinitialized when a boot environment is launched. Any teardown hooks installed into the ZFSBootMenu initramfs, will be run immediately before \fBkexec\fR is invoked to jump into the selected kernel. This script can be used, for example, to unbind drivers from hardware or remove kernel modules.
302+
Some hardware initialized by the kernel used to boot ZFSBootMenu may not be properly reinitialized when a boot environment is launched. Any teardown hooks installed into the ZFSBootMenu initramfs will be run immediately before \fBkexec\fR is invoked to jump into the selected kernel. This script can be used, for example, to unbind drivers from hardware or remove kernel modules.
303+
.Sp
304+
Teardown hooks have access to three environment variables that describe the boot environment that is about to be launched:
305+
.RS 4
306+
.IP "\fB\s-1ZBM_SELECTED_BE\s0\fR" 4
307+
.IX Item "ZBM_SELECTED_BE"
308+
The \s-1ZFS\s0 filesystem containing the boot environment that is about to be launched.
309+
.IP "\fB\s-1ZBM_SELECTED_KERNEL\s0\fR" 4
310+
.IX Item "ZBM_SELECTED_KERNEL"
311+
The path to the kernel that will be booted, relative to the root of \fB\s-1ZBM_SELECTED_BE\s0\fR.
312+
.IP "\fB\s-1ZBM_SELECTED_INITRAMFS\s0\fR" 4
313+
.IX Item "ZBM_SELECTED_INITRAMFS"
314+
The path to the initramfs corresponding to the selected kernel, again relative to the root of \fB\s-1ZBM_SELECTED_BE\s0\fR.
315+
.RE
316+
.RS 4
317+
.Sp
318+
The hook \fImust not\fR assume that the filesystem \fB\s-1ZBM_SELECTED_BE\s0\fR is currently mounted or that the pool on which it resides is currently imported. However, a teardown hook has the freedom to import a pool (preferably read-only) and mount the boot environment to inject additional processing before boot. To abort a pending boot, invoking
319+
.Sp
320+
.Vb 1
321+
\& kexec \-\-unload
322+
.Ve
323+
.Sp
324+
should be sufficient to return to the main menu. Likewise, the hook may construct and execute its own \fIkexec\fR command to alter boot-time parameters. This may be useful, for example, to allow ZFSBootMenu to select a boot environment and then restructure the boot process to launch a Xen kernel with the selected environment configured as dom0.
325+
.RE
303326
.SH "SEE ALSO"
304327
.IX Header "SEE ALSO"
305328
\&\fBgenerate-zbm\fR(5) \fBgenerate-zbm\fR(8) \fBdracut.conf\fR(5)

pod/zfsbootmenu.7.pod

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,31 @@ Any installed hooks are run right before the ZFSBootMenu menu will be presented;
204204

205205
An optional variable specifying a space-separated list of paths to teardown hooks that will be installed in the ZFSBootMenu initramfs. Any path in the list B<E<lt>executable-listE<gt>> that exists and is executable will be installed.
206206

207-
Some hardware initialized by the kernel used to boot ZFSBootMenu may not be properly reinitialized when a boot environment is launched. Any teardown hooks installed into the ZFSBootMenu initramfs, will be run immediately before B<kexec> is invoked to jump into the selected kernel. This script can be used, for example, to unbind drivers from hardware or remove kernel modules.
207+
Some hardware initialized by the kernel used to boot ZFSBootMenu may not be properly reinitialized when a boot environment is launched. Any teardown hooks installed into the ZFSBootMenu initramfs will be run immediately before B<kexec> is invoked to jump into the selected kernel. This script can be used, for example, to unbind drivers from hardware or remove kernel modules.
208+
209+
Teardown hooks have access to three environment variables that describe the boot environment that is about to be launched:
210+
211+
=over 4
212+
213+
=item B<ZBM_SELECTED_BE>
214+
215+
The ZFS filesystem containing the boot environment that is about to be launched.
216+
217+
=item B<ZBM_SELECTED_KERNEL>
218+
219+
The path to the kernel that will be booted, relative to the root of B<ZBM_SELECTED_BE>.
220+
221+
=item B<ZBM_SELECTED_INITRAMFS>
222+
223+
The path to the initramfs corresponding to the selected kernel, again relative to the root of B<ZBM_SELECTED_BE>.
224+
225+
=back
226+
227+
The hook I<must not> assume that the filesystem B<ZBM_SELECTED_BE> is currently mounted or that the pool on which it resides is currently imported. However, a teardown hook has the freedom to import a pool (preferably read-only) and mount the boot environment to inject additional processing before boot. To abort a pending boot, invoking
228+
229+
kexec --unload
230+
231+
should be sufficient to return to the main menu. Likewise, the hook may construct and execute its own I<kexec> command to alter boot-time parameters. This may be useful, for example, to allow ZFSBootMenu to select a boot environment and then restructure the boot process to launch a Xen kernel with the selected environment configured as dom0.
208232

209233
=back
210234

0 commit comments

Comments
 (0)