Skip to content

Commit 57b46a2

Browse files
committed
Extend capabilities of zbm.prefer
Under certain circumstances, it might be preferable to ensure ZFSBootMenu only ever interacts with a specific zpool. Historical/default behavior has every pool being imported each boot, with optional preference being given to one specific pool. A new modifier to `zbm.prefer`, `!!` has been added. When this is appended to the name of a pool, that pool is imported exclusive of all others on the system. If the pool can't be imported, a retry/recovery shell loop is initiated.
1 parent af1c74b commit 57b46a2

File tree

6 files changed

+88
-28
lines changed

6 files changed

+88
-28
lines changed

docs/pod/zfsbootmenu.7.pod

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,25 @@ These options are set on the kernel command line when booting the initramfs or U
1818

1919
When creating an initramfs or UEFI bundle, the I</etc/hostid> from the system is copied into the target. If this image will be used on another system with a different hostid, replace B<E<lt>hostidE<gt>> with the desired hostid, as an eight-digit hexadecimal number, to override the value contained within the image.
2020

21+
=item B<zbm.prefer>
22+
23+
ZFSBootMenu will attempt to import as many pools as possible to identify boot environments and will, by default, look for the I<bootfs> property on the first imported pool (sorted alphabetically) to select the default boot environment. This option controls this behavior.
24+
25+
=over 2
26+
2127
=item B<zbm.prefer=E<lt>poolE<gt>>
2228

23-
ZFSBootMenu will attempt to import as many pools as possible to identify boot environments and will, by default, look for the I<bootfs> property on the first imported pool (sorted alphabetically) to select the default boot environment. If you have multiple pools, replace B<E<lt>poolE<gt>> with the name of your preferred pool to override the default. If B<E<lt>poolE<gt>> is the name of a pool followed by a literal I<!> character, ZFSBootMenu will insist on successfully importing the named pool before attempting to import any others.
29+
The simplest form attempts to import B<E<lt>poolE<gt>> before any other pool. The I<bootfs> value from this pool will control the default boot environment.
30+
31+
=item B<zbm.prefer=E<lt>poolE<gt>I<!>>
32+
33+
If a literal I<!> has been appended to the pool name, ZFSBootMenu will insist on successfully importing the named pool before attempting to import any others.
34+
35+
=item B<zbm.prefer=E<lt>poolE<gt>I<!!>>
36+
37+
If a literal I<!!> has been appended to the pool name, ZFSBootMenu will insist on successfully importing the named pool and no others.
38+
39+
=back
2440

2541
=item B<zbm.import_delay=E<lt>timeE<gt>>
2642

zfsbootmenu/help-files/132/zfsbootmenu.7.pod

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@ general systems to boot without setting any values.
1616
on another system with a different hostid, replace <hostid> with the desired hostid, as an eight-digit hexadecimal number, to
1717
override the value contained within the image.
1818

19-
zbm.prefer=<pool>
19+
zbm.prefer
2020
ZFSBootMenu will attempt to import as many pools as possible to identify boot environments and will, by default, look for the
21-
bootfs property on the first imported pool (sorted alphabetically) to select the default boot environment. If you have multiple
22-
pools, replace <pool> with the name of your preferred pool to override the default. If <pool> is the name of a pool followed by
23-
a literal ! character, ZFSBootMenu will insist on successfully importing the named pool before attempting to import any others.
21+
bootfs property on the first imported pool (sorted alphabetically) to select the default boot environment. This option controls
22+
this behavior.
23+
24+
zbm.prefer=<pool>
25+
The simplest form attempts to import <pool> before any other pool. The bootfs value from this pool will control the default
26+
boot environment.
27+
28+
zbm.prefer=<pool>!
29+
If a literal ! has been appended to the pool name, ZFSBootMenu will insist on successfully importing the named pool before
30+
attempting to import any others.
31+
32+
zbm.prefer=<pool>!!
33+
If a literal !! has been appended to the pool name, ZFSBootMenu will insist on successfully importing the named pool and no
34+
others.
2435

2536
zbm.import_delay=<time>
2637
Should ZFSBootMenu fail to successfully import any pool, it will repeat import attempts indefinitely until at least one pool can

zfsbootmenu/help-files/52/zfsbootmenu.7.pod

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,30 @@ without setting any values.
2424
hexadecimal number, to override the value
2525
contained within the image.
2626

27-
zbm.prefer=<pool>
27+
zbm.prefer
2828
ZFSBootMenu will attempt to import as many pools
2929
as possible to identify boot environments and
3030
will, by default, look for the bootfs property
3131
on the first imported pool (sorted
3232
alphabetically) to select the default boot
33-
environment. If you have multiple pools, replace
34-
<pool> with the name of your preferred pool to
35-
override the default. If <pool> is the name of a
36-
pool followed by a literal ! character,
37-
ZFSBootMenu will insist on successfully
38-
importing the named pool before attempting to
39-
import any others.
33+
environment. This option controls this behavior.
34+
35+
zbm.prefer=<pool>
36+
The simplest form attempts to import <pool>
37+
before any other pool. The bootfs value from
38+
this pool will control the default boot
39+
environment.
40+
41+
zbm.prefer=<pool>!
42+
If a literal ! has been appended to the pool
43+
name, ZFSBootMenu will insist on successfully
44+
importing the named pool before attempting to
45+
import any others.
46+
47+
zbm.prefer=<pool>!!
48+
If a literal !! has been appended to the pool
49+
name, ZFSBootMenu will insist on successfully
50+
importing the named pool and no others.
4051

4152
zbm.import_delay=<time>
4253
Should ZFSBootMenu fail to successfully import

zfsbootmenu/help-files/92/zfsbootmenu.7.pod

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@ Default options were chosen to allow general systems to boot without setting any
1818
replace <hostid> with the desired hostid, as an eight-digit hexadecimal number, to
1919
override the value contained within the image.
2020

21-
zbm.prefer=<pool>
21+
zbm.prefer
2222
ZFSBootMenu will attempt to import as many pools as possible to identify boot
2323
environments and will, by default, look for the bootfs property on the first imported
24-
pool (sorted alphabetically) to select the default boot environment. If you have
25-
multiple pools, replace <pool> with the name of your preferred pool to override the
26-
default. If <pool> is the name of a pool followed by a literal ! character, ZFSBootMenu
27-
will insist on successfully importing the named pool before attempting to import any
28-
others.
24+
pool (sorted alphabetically) to select the default boot environment. This option
25+
controls this behavior.
26+
27+
zbm.prefer=<pool>
28+
The simplest form attempts to import <pool> before any other pool. The bootfs value
29+
from this pool will control the default boot environment.
30+
31+
zbm.prefer=<pool>!
32+
If a literal ! has been appended to the pool name, ZFSBootMenu will insist on
33+
successfully importing the named pool before attempting to import any others.
34+
35+
zbm.prefer=<pool>!!
36+
If a literal !! has been appended to the pool name, ZFSBootMenu will insist on
37+
successfully importing the named pool and no others.
2938

3039
zbm.import_delay=<time>
3140
Should ZFSBootMenu fail to successfully import any pool, it will repeat import attempts

zfsbootmenu/hook/zfsbootmenu-parse-commandline.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,23 @@ case "${root}" in
231231
;;
232232
esac
233233

234-
# Pool preference ending in ! indicates a hard requirement
235-
bpool="${root%\!}"
236-
if [ "${bpool}" != "${root}" ]; then
237-
# shellcheck disable=SC2034
238-
zbm_require_bpool=1
239-
root="${bpool}"
240-
fi
234+
# pool! : this pool must be imported before all others
235+
# pool!!: this pool, and no others, must be imported
236+
237+
# shellcheck disable=SC2034
238+
case "${root}" in
239+
*!!)
240+
zbm_require_bpool="only"
241+
root="${root%!!}"
242+
;;
243+
*!)
244+
zbm_require_bpool="yes"
245+
root="${root%!}"
246+
;;
247+
*)
248+
zbm_require_bpool=""
249+
;;
250+
esac
241251

242252
# Make sure Dracut is happy that we have a root
243253
if [ ${wait_for_zfs} -eq 1 ]; then

zfsbootmenu/libexec/zfsbootmenu-init

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ while true; do
105105

106106
# shellcheck disable=SC2154
107107
if check_for_pools; then
108-
if [ -n "${try_pool}" ]; then
108+
if [ "${zbm_require_bpool}" = "only" ]; then
109+
zdebug "only importing ${try_pool}"
110+
break
111+
elif [ -n "${try_pool}" ]; then
109112
# If a single pool was requested and imported, try importing others
110113
try_pool=""
111114
continue
@@ -127,7 +130,7 @@ while true; do
127130
# allow another pass to pick up others with the same hostid
128131
try_pool=""
129132
continue
130-
elif [ -n "${try_pool}" ] && [ "${zbm_require_bpool:-0}" -ne 1 ]; then
133+
elif [ -n "${try_pool}" ] && [ -z "${zbm_require_bpool}" ]; then
131134
# If a specific pool was tried unsuccessfully but is not a requirement,
132135
# allow another pass to try any other importable pools
133136
try_pool=""

0 commit comments

Comments
 (0)