Skip to content

Commit f616019

Browse files
committed
zfsbootmenu: extend zbm.prefer to set bootfs
1 parent 932d725 commit f616019

4 files changed

Lines changed: 53 additions & 37 deletions

File tree

docs/man/zfsbootmenu.7.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ These options are set on the kernel command line when booting the initramfs or U
2020

2121
**zbm.prefer**
2222

23-
ZFSBootMenu will attempt to import as many pools as possible to identify boot environments and will, by default, look for the *bootfs* property on the first imported pool (sorted alphabetically) to select the default boot environment. This option controls this behavior.
23+
ZFSBootMenu attempts to import all detected pools by default, with the *bootfs* property on the first pool (sorted alphabetically) used to select the default boot environment. Providing a *pool* name for this parameter will override the pool import order. Providing a *dataset* for this parameter will override both the pool import order and the default boot environment.
2424

25-
**zbm.prefer=<pool>**
2625

27-
The simplest form attempts to import **<pool>** before any other pool. The *bootfs* value from this pool will control the default boot environment.
26+
**zbm.prefer=<pool|dataset>**
2827

29-
**zbm.prefer=<pool>!**
28+
The simplest form attempts to import **<pool>** or the pool component of a **<dataset>** before any other pool. If a *dataset* is provided, that will be used as the boot environment if it exists.
29+
30+
**zbm.prefer=<pool|dataset>!**
3031

3132
If a literal *!* has been appended to the pool name, ZFSBootMenu will insist on successfully importing the named pool before attempting to import any others.
3233

33-
**zbm.prefer=<pool>!!**
34+
**zbm.prefer=<pool|dataset>!!**
3435

3536
If a literal *!!* has been appended to the pool name, ZFSBootMenu will insist on successfully importing the named pool and no others.
3637

zfsbootmenu/init.d/50-import-pools

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,25 @@ if [ "${unsupported}" -ne 0 ]; then
105105
fi
106106
unset unsupported
107107

108-
# Attempt to find the bootfs property
109-
# shellcheck disable=SC2086
110-
while read -r _bootfs; do
111-
if [ "${_bootfs}" = "-" ]; then
112-
BOOTFS=
108+
if [ -n "${zbm_prefer_bootfs}" ]; then
109+
if is_zfs_filesystem "${zbm_prefer_bootfs}" ; then
110+
BOOTFS="${zbm_prefer_bootfs}"
113111
else
114-
BOOTFS="${_bootfs}"
115-
break
112+
zerror "bootfs value '${zbm_prefer_bootfs}' not a ZFS dataset"
116113
fi
117-
done <<<"$( zpool list -H -o bootfs "${zbm_prefer_pool:---}" )"
118-
unset _bootfs
114+
else
115+
# Attempt to find the bootfs property
116+
# shellcheck disable=SC2086
117+
while read -r _bootfs; do
118+
if [ "${_bootfs}" = "-" ]; then
119+
BOOTFS=
120+
else
121+
BOOTFS="${_bootfs}"
122+
break
123+
fi
124+
done <<<"$( zpool list -H -o bootfs "${zbm_prefer_pool:---}" )"
125+
unset _bootfs
126+
fi
119127

120128
if [ -n "${BOOTFS}" ]; then
121129
export BOOTFS

zfsbootmenu/pre-init/zfsbootmenu-parse-commandline.sh

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -219,35 +219,41 @@ if kcl_override=$( get_zbm_arg zbm.kcl_override ) ; then
219219
zinfo "overriding all BE KCLs with: '$( kcl_assemble < "${BASE}/cmdline" )'"
220220
fi
221221

222-
zbm_prefer_pool=
223-
if zbm_prefer_pool=$( get_zbm_arg zbm.prefer ) ; then
224-
# shellcheck disable=SC2034
225-
zbm_prefer_pool="${zbm_prefer_pool%%/*}"
226-
zinfo "preferring ${zbm_prefer_pool} for bootfs"
227-
fi
228-
229222
zbm_wait_for_devices=
230223
if zbm_wait_for_devices=$( get_zbm_arg zbm.wait_for ) ; then
231224
zinfo "system will wait for ${zbm_wait_for_devices}"
232225
fi
233226

234-
# pool! : this pool must be imported before all others
235-
# pool!!: this pool, and no others, must be imported
227+
zbm_prefer_bootfs=
228+
zbm_require_pool=
229+
if zbm_prefer=$( get_zbm_arg zbm.prefer ) ; then
236230

237-
# shellcheck disable=SC2034
238-
case "${zbm_prefer_pool}" in
239-
*!!)
240-
zbm_require_pool="only"
241-
zbm_prefer_pool="${zbm_prefer_pool%!!}"
242-
;;
243-
*!)
244-
zbm_require_pool="yes"
245-
zbm_prefer_pool="${zbm_prefer_pool%!}"
246-
;;
247-
*)
248-
zbm_require_pool=""
249-
;;
250-
esac
231+
# strip the modifiers and set zbm_require_pool as needed
232+
# shellcheck disable=SC2034
233+
case "${zbm_prefer}" in
234+
*!!)
235+
zbm_require_pool="only"
236+
zbm_prefer="${zbm_prefer%!!}"
237+
zinfo "will only attempt to import ${zbm_prefer%%/*}"
238+
;;
239+
*!)
240+
zbm_require_pool="yes"
241+
zbm_prefer="${zbm_prefer%!}"
242+
zinfo "requiring pool ${zbm_prefer%%/*}"
243+
;;
244+
*)
245+
zbm_require_pool=
246+
;;
247+
esac
248+
249+
zbm_prefer_pool="${zbm_prefer%%/*}"
250+
251+
# zbm_prefer looks like it could be a dataset, use it as the bootfs value
252+
if [ "${zbm_prefer_pool}" != "${zbm_prefer}" ]; then
253+
# shellcheck disable=SC2034
254+
zbm_prefer_bootfs="${zbm_prefer}"
255+
fi
256+
fi
251257

252258
# Make sure Dracut is happy that we have a root
253259

zfsbootmenu/pre-init/zfsbootmenu-preinit.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export menu_timeout='${menu_timeout}'
2828
export loglevel='${loglevel}'
2929
export zbm_prefer_pool='${zbm_prefer_pool}'
3030
export zbm_require_pool='${zbm_require_pool}'
31+
export zbm_prefer_bootfs='${zbm_prefer_bootfs}'
3132
export default_hostid=00bab10c
3233
export zbm_sort='${zbm_sort}'
3334
export zbm_set_hostid='${zbm_set_hostid}'

0 commit comments

Comments
 (0)