Skip to content

Commit 91b4b3b

Browse files
zdykstraahesford
andcommitted
De-prioritize Dracut as the primary generator
All core ZFSBootMenu libraries / hooks / binaries have been moved to a generic 'zfsbootmenu' directory intended to be installed in /usr/share. The dracut-specific module-setup.sh script has been moved to a 'dracut' directory and it, along with the 'initcpio' hook scripts, have been adapted to use common tooling in 'zfsbootmenu/install-helpers.sh'. Both of these refer to the core components in '/usr/share/zfsbootmenu' when creating a new image. The zbm-kcl utilit looks there by default. The testing tools are now capable of producing images with mkinitcpio. Co-authored-by: Zach Dykstra <[email protected]> Co-authored-by: Andrew J. Hesford <[email protected]>
1 parent af34fa9 commit 91b4b3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+346
-248
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
run: |
1515
ln -s "$(pwd)" /zbm
1616
cp /zbm/etc/zfsbootmenu/release.conf.d/release.conf /zbm/etc/zfsbootmenu/dracut.conf.d/
17+
echo "zfsbootmenu_module_root='/zbm/zfsbootmenu'" >> /zbm/etc/zfsbootmenu/dracut.conf.d/release.conf
1718
/zbm/releng/docker/zbm-build.sh -e '.Global.DracutFlags += ["--no-early-microcode"]' -- --debug
1819
1920
- name: Archive EFI

Makefile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
DESTDIR=
22
PREFIX=/usr
33
CONFDIR=/etc/zfsbootmenu
4-
MODDIR=$(PREFIX)/lib/dracut/modules.d
4+
MODDIR=$(PREFIX)/share
5+
DRACUTDIR=$(PREFIX)/lib/dracut/modules.d
6+
INITCPIODIR=$(PREFIX)/lib/initcpio
57
MANDIR=$(PREFIX)/share/man
68
BINDIR=$(PREFIX)/bin
79
EXAMPLES=$(PREFIX)/share/examples/zfsbootmenu
810

9-
.PHONY: install default
11+
.PHONY: install core dracut initcpio
1012

11-
default:
13+
install: core dracut initcpio
1214

13-
install:
14-
# Recursively install non-executable parts of the Dracut module
15-
find 90zfsbootmenu -type f -not -perm /111 -exec \
16-
install -Dm 0644 "{}" "$(DESTDIR)$(MODDIR)/{}" \;
17-
# Executable parts of the module
18-
find 90zfsbootmenu -type f -perm /111 -exec \
19-
install -Dm 0755 "{}" "$(DESTDIR)$(MODDIR)/{}" \;
15+
core:
16+
./install-tree.sh zfsbootmenu "$(DESTDIR)$(MODDIR)"
2017
install -m 0644 -t "$(DESTDIR)$(CONFDIR)" -D etc/zfsbootmenu/config.yaml
21-
install -m 0644 -t "$(DESTDIR)$(CONFDIR)/dracut.conf.d/" -D etc/zfsbootmenu/dracut.conf.d/*
2218
install -m 0755 -t "$(DESTDIR)$(BINDIR)" -D bin/*
2319
install -m 0644 -t "$(DESTDIR)$(MANDIR)/man5" -D man/*.5
2420
install -m 0644 -t "$(DESTDIR)$(MANDIR)/man7" -D man/*.7
2521
install -m 0644 -t "$(DESTDIR)$(MANDIR)/man8" -D man/*.8
2622
install -m 0755 -t "$(DESTDIR)$(EXAMPLES)" -D contrib/*
23+
24+
dracut:
25+
./install-tree.sh dracut "$(DESTDIR)$(DRACUTDIR)/90zfsbootmenu"
26+
install -m 0644 -t \
27+
"$(DESTDIR)$(CONFDIR)/dracut.conf.d/" \
28+
-D etc/zfsbootmenu/dracut.conf.d/*
29+
30+
initcpio:
31+
./install-tree.sh initcpio "$(DESTDIR)$(INITCPIODIR)"
32+
install -m 0644 -t "$(DESTDIR)$(CONFDIR)" -D etc/zfsbootmenu/mkinitcpio.conf

bin/zbm-kcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
zbm_load_lib() {
55
lib="${1?no library specified for load}"
66

7-
: "${ZBM_MODULEDIR:=/usr/lib/dracut/modules.d/90zfsbootmenu}"
7+
: "${ZBM_MODULEDIR:=/usr/share/zfsbootmenu}"
88

99
if [ -r "${ZBM_MODULEDIR}/lib/${lib}" ]; then
1010
# shellcheck disable=SC1090
Lines changed: 32 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ installkernel() {
4343
}
4444

4545
install() {
46+
: "${zfsbootmenu_module_root:=/usr/share/zfsbootmenu}"
47+
48+
# shellcheck disable=SC1091
49+
if ! source "${zfsbootmenu_module_root}/install-helpers.sh" ; then
50+
dfatal "Unable to source ${zfsbootmenu_module_root}/install-helpers.sh"
51+
exit 1
52+
fi
53+
54+
# BUILDROOT is an initcpio-ism
55+
# shellcheck disable=SC2154,2034
56+
BUILDROOT="${initdir}"
57+
# shellcheck disable=SC2034
58+
BUILDSTYLE="dracut"
59+
4660
local _rule _exec _ret
4761

4862
local udev_rules=(
@@ -58,51 +72,14 @@ install() {
5872
fi
5973
done
6074

61-
local essential_execs=(
62-
"zfs"
63-
"zpool"
64-
"zdb"
65-
"lsblk"
66-
"hostid"
67-
"mount"
68-
"mount.zfs"
69-
"kexec"
70-
"mkdir"
71-
"tput"
72-
"head"
73-
"mktemp"
74-
"sort"
75-
"sed"
76-
"grep"
77-
"tail"
78-
"tr"
79-
"tac"
80-
"blkid"
81-
"awk"
82-
"fold"
83-
"ps"
84-
"env"
85-
"chmod"
86-
"od"
87-
"stty"
88-
"insmod"
89-
"modinfo"
90-
"lsmod"
91-
"depmod"
92-
)
93-
94-
for _exec in "${essential_execs[@]}"; do
75+
# shellcheck disable=SC2154
76+
for _exec in "${zfsbootmenu_essential_binaries[@]}"; do
9577
if ! dracut_install "${_exec}"; then
9678
dfatal "failed to install essential executable '${_exec}'"
9779
exit 1
9880
fi
9981
done
10082

101-
if ! dracut_install fzf; then
102-
dfatal "failed to install fzf"
103-
exit 1
104-
fi
105-
10683
# BE clones will work (silently and less efficiently) without mbuffer
10784
if ! dracut_install mbuffer; then
10885
dwarning "mbuffer not found; ZFSBootMenu cannot show progress during BE clones"
@@ -131,54 +108,40 @@ install() {
131108

132109
# shellcheck disable=SC2154
133110
while read -r doc ; do
134-
relative="${doc//${moddir}\//}"
111+
relative="${doc//${zfsbootmenu_module_root}\//}"
135112
inst_simple "${doc}" "/usr/share/docs/${relative}"
136-
done <<<"$( find "${moddir}/help-files" -type f )"
113+
done <<<"$( find "${zfsbootmenu_module_root}/help-files" -type f )"
137114

138115
_ret=0
139116

140117
# Core ZFSBootMenu functionality
141118
# shellcheck disable=SC2154
142-
for _lib in "${moddir}"/lib/*; do
119+
for _lib in "${zfsbootmenu_module_root}"/lib/*; do
143120
inst_simple "${_lib}" "/lib/$( basename "${_lib}" )" || _ret=$?
144121
done
145122

146123
# Helper tools not intended for direct human consumption
147-
for _libexec in "${moddir}"/libexec/*; do
124+
for _libexec in "${zfsbootmenu_module_root}"/libexec/*; do
148125
inst_simple "${_libexec}" "/libexec/$( basename "${_libexec}" )" || _ret=$?
149126
done
150127

151128
# User-facing utilities, useful for running in a recover shell
152-
for _bin in "${moddir}"/bin/*; do
129+
for _bin in "${zfsbootmenu_module_root}"/bin/*; do
153130
inst_simple "${_bin}" "/bin/$( basename "${_bin}" )" || _ret=$?
154131
done
155132

156133
# Hooks necessary to initialize ZBM
157-
inst_hook cmdline 95 "${moddir}/hook/zfsbootmenu-parse-commandline.sh" || _ret=$?
158-
inst_hook pre-mount 90 "${moddir}/hook/zfsbootmenu-preinit.sh" || _ret=$?
134+
inst_hook cmdline 95 "${zfsbootmenu_module_root}/hook/zfsbootmenu-parse-commandline.sh" || _ret=$?
135+
inst_hook pre-mount 90 "${zfsbootmenu_module_root}/hook/zfsbootmenu-preinit.sh" || _ret=$?
159136

160137
# Hooks to force the dracut event loop to fire at least once
161138
# Things like console configuration are done in optional event-loop hooks
162-
inst_hook initqueue/settled 99 "${moddir}/hook/zfsbootmenu-ready-set.sh" || _ret=$?
163-
inst_hook initqueue/finished 99 "${moddir}/hook/zfsbootmenu-ready-chk.sh" || _ret=$?
164-
165-
# If tracing is enabled, build in the full-weight profiling library
166-
if [ -n "${zfsbootmenu_trace_enable}" ]; then
167-
inst_simple "${moddir}/profiling/profiling-lib.sh" "/lib/profiling-lib.sh"
168-
169-
# shellcheck disable=SC2154
170-
cat << EOF >> "${initdir}/etc/profiling.conf"
171-
export zfsbootmenu_trace_term=${zfsbootmenu_trace_term}
172-
export zfsbootmenu_trace_baud=${zfsbootmenu_trace_baud}
173-
EOF
174-
175-
# optionally enable early Dracut profiling
176-
if [ -n "${dracut_trace_enable}" ]; then
177-
inst_hook cmdline 00 "${moddir}/profiling/profiling-lib.sh"
178-
fi
179-
else
180-
# Install the default profiling library that is a simple `return 0`
181-
echo "return 0" > "${initdir}/lib/profiling-lib.sh"
139+
inst_hook initqueue/settled 99 "${zfsbootmenu_module_root}/hook/zfsbootmenu-ready-set.sh" || _ret=$?
140+
inst_hook initqueue/finished 99 "${zfsbootmenu_module_root}/hook/zfsbootmenu-ready-chk.sh" || _ret=$?
141+
142+
# optionally enable early Dracut profiling
143+
if [ -n "${dracut_trace_enable}" ]; then
144+
inst_hook cmdline 00 "${zfsbootmenu_module_root}/profiling/profiling-lib.sh"
182145
fi
183146

184147
# Install "early setup" hooks
@@ -284,30 +247,6 @@ EOF
284247
mark_hostonly /etc/hostid
285248
fi
286249

287-
# Check if fuzzy finder supports the refresh-preview flag
288-
# Added in fzf 0.22.0
289-
if command -v fzf >/dev/null 2>&1 && \
290-
echo "abc" | fzf -f "abc" --bind "alt-l:refresh-preview" --exit-0 >/dev/null 2>&1
291-
then
292-
has_refresh=1
293-
else
294-
has_refresh=
295-
fi
296-
297-
# shellcheck disable=SC2154
298-
cat << 'EOF' > "${initdir}/etc/zfsbootmenu.conf"
299-
# Include guard
300-
[ -n "${_ETC_ZFSBOOTMENU_CONF}" ] && return
301-
readonly _ETC_ZFSBOOTMENU_CONF=1
302-
EOF
303-
304-
# Collect all of our build-time feature flags
305-
# shellcheck disable=SC2154
306-
cat << EOF >> "${initdir}/etc/zfsbootmenu.conf"
307-
export BYTE_ORDER=${endian:-le}
308-
export HAS_REFRESH=${has_refresh}
309-
EOF
310-
311250
# Embed a kernel command line in the initramfs
312251
# shellcheck disable=SC2154
313252
if [ -n "${embedded_kcl}" ]; then
@@ -320,36 +259,7 @@ EOF
320259
echo "rd.hostonly=0" > "${initdir}/etc/cmdline.d/hostonly.conf"
321260
fi
322261

323-
# Setup a default environment for all login shells
324-
cat << EOF >> "${initdir}/etc/profile"
325-
export PATH=/usr/sbin:/usr/bin:/sbin:/bin
326-
export TERM=linux
327-
export HOME=/root
328-
EOF
329-
330-
# Setup a default environment for bash -i
331-
cat << EOF >> "${initdir}/root/.bashrc"
332-
source /etc/zfsbootmenu.conf >/dev/null 2>&1
333-
source /lib/kmsg-log-lib.sh >/dev/null 2>&1
334-
source /lib/zfsbootmenu-core.sh >/dev/null 2>&1
335-
source /lib/zfsbootmenu-kcl.sh >/dev/null 2>&1
336-
[ -f /etc/profile ] && source /etc/profile
337-
[ -f /lib/zfsbootmenu-completions.sh ] && source /lib/zfsbootmenu-completions.sh
338-
339-
export PS1="\033[0;33mzfsbootmenu\033[0m \w > "
340-
341-
alias clear="tput clear"
342-
alias reset="tput reset"
343-
alias zbm="zfsbootmenu"
344-
alias logs="ztrace"
345-
alias trace="ztrace"
346-
alias debug="ztrace"
347-
alias help="/libexec/zfsbootmenu-help -L recovery-shell"
348-
349-
zdebug "sourced /root/.bashrc" || true
350-
351-
EOF
352-
353-
# symlink to .profile for /bin/sh - launched by dropbear
354-
ln -s "/root/.bashrc" "${initdir}/root/.profile"
262+
create_zbm_conf
263+
create_zbm_profiles
264+
create_zbm_traceconf
355265
}

etc/zfsbootmenu/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Global:
44
DracutConfDir: /etc/zfsbootmenu/dracut.conf.d
55
PreHooksDir: /etc/zfsbootmenu/generate-zbm.pre.d
66
PostHooksDir: /etc/zfsbootmenu/generate-zbm.post.d
7+
InitCPIO: false
8+
InitCPIOConfig: /etc/zfsbootmenu/mkinitcpio.conf
79
Components:
810
ImageDir: /boot/efi/EFI/void
911
Versions: 3

etc/zfsbootmenu/mkinitcpio.conf

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# vim:set ft=sh
2+
# MODULES
3+
# The following modules are loaded before any boot hooks are
4+
# run. Advanced users may wish to specify all system modules
5+
# in this array. For instance:
6+
# MODULES=(piix ide_disk reiserfs)
7+
MODULES=()
8+
9+
# BINARIES
10+
# This setting includes any additional binaries a given user may
11+
# wish into the CPIO image. This is run last, so it may be used to
12+
# override the actual binaries included by a given hook
13+
# BINARIES are dependency parsed, so you may safely ignore libraries
14+
BINARIES=()
15+
16+
# FILES
17+
# This setting is similar to BINARIES above, however, files are added
18+
# as-is and are not parsed in any way. This is useful for config files.
19+
FILES=()
20+
21+
# HOOKS
22+
# This is the most important setting in this file. The HOOKS control the
23+
# modules and scripts added to the image, and what happens at boot time.
24+
# Order is important, and it is recommended that you do not change the
25+
# order in which HOOKS are added. Run 'mkinitcpio -H <hook name>' for
26+
# help on a given hook.
27+
# 'base' is _required_ unless you know precisely what you are doing.
28+
# 'udev' is _required_ in order to automatically load modules
29+
# 'filesystems' is _required_ unless you specify your fs modules in MODULES
30+
# Examples:
31+
## This setup specifies all modules in the MODULES setting above.
32+
## No raid, lvm2, or encrypted root is needed.
33+
# HOOKS=(base)
34+
#
35+
## This setup will autodetect all modules for your system and should
36+
## work as a sane default
37+
# HOOKS=(base udev autodetect block filesystems)
38+
#
39+
## This setup will generate a 'full' image which supports most systems.
40+
## No autodetection is done.
41+
# HOOKS=(base udev block filesystems)
42+
#
43+
## This setup assembles a pata mdadm array with an encrypted root FS.
44+
## Note: See 'mkinitcpio -H mdadm' for more information on raid devices.
45+
# HOOKS=(base udev block mdadm encrypt filesystems)
46+
#
47+
## This setup loads an lvm2 volume group on a usb device.
48+
# HOOKS=(base udev block lvm2 filesystems)
49+
#
50+
## NOTE: If you have /usr on a separate partition, you MUST include the
51+
# usr, fsck and shutdown hooks.
52+
HOOKS=(base udev autodetect modconf block filesystems keyboard zfsbootmenu )
53+
54+
# COMPRESSION
55+
# Use this to compress the initramfs image. By default, gzip compression
56+
# is used. Use 'cat' to create an uncompressed image.
57+
#COMPRESSION="zstd"
58+
#COMPRESSION="gzip"
59+
#COMPRESSION="bzip2"
60+
#COMPRESSION="lzma"
61+
#COMPRESSION="xz"
62+
#COMPRESSION="lzop"
63+
#COMPRESSION="lz4"
64+
65+
# COMPRESSION_OPTIONS
66+
# Additional options for the compressor
67+
#COMPRESSION_OPTIONS=()

0 commit comments

Comments
 (0)