Skip to content

Commit

Permalink
Define all ZBM requirements in install-helpers.sh
Browse files Browse the repository at this point in the history
Required and optional kernel modules, binaries and udev rules are all
provided as arrays in install-helpers.sh to provide a single point for
altering requirements.
  • Loading branch information
ahesford committed Jan 27, 2022
1 parent ba2fa63 commit 65167e6
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 51 deletions.
41 changes: 12 additions & 29 deletions dracut/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,16 @@ depends() {
installkernel() {
local mod

local required_modules=(
"zfs"
"zcommon"
"znvpair"
"zavl"
"zunicode"
"zlua"
"icp"
"spl"
)

for mod in "${required_modules[@]}"; do
# shellcheck disable=SC2154
for mod in "${zfsbootmenu_essential_modules[@]}"; do
if ! instmods -c "${mod}" ; then
dfatal "Required kernel module '${mod}' is missing, aborting image creation!"
exit 1
fi
done

local optional_modules=(
"zlib_deflate"
"zlib_inflate"
)

for mod in "${optional_modules[@]}"; do
# shellcheck disable=SC2154
for mod in "${zfsbootmenu_optional_modules[@]}"; do
instmods "${mod}"
done
}
Expand All @@ -59,13 +45,8 @@ install() {

local _rule _exec _ret

local udev_rules=(
"90-zfs.rules"
"69-vdev.rules"
"60-zvol.rules"
)

for _rule in "${udev_rules[@]}"; do
# shellcheck disable=SC2154
for _rule in "${zfsbootmenu_udev_rules[@]}"; do
if ! inst_rules "${_rule}"; then
dfatal "failed to install udev rule '${_rule}'"
exit 1
Expand All @@ -80,10 +61,12 @@ install() {
fi
done

# BE clones will work (silently and less efficiently) without mbuffer
if ! dracut_install mbuffer; then
dwarning "mbuffer not found; ZFSBootMenu cannot show progress during BE clones"
fi
# shellcheck disable=SC2154
for _exec in "${zfsbootmenu_optional_binaries[@]}"; do
if ! dracut_install "${_exec}"; then
dwarning "optional component '${_exec}' not found, omitting from image"
fi
done

# Workaround for zfsonlinux/zfs#4749 by ensuring libgcc_s.so(.1) is included
_ret=0
Expand Down
53 changes: 31 additions & 22 deletions initcpio/install/zfsbootmenu
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ add_terminfo() {
done
}

add_optional_binary() {
# This has to be inverted to avoid a RETURN trap that triggers failure
if ! command -v "${1}" >/dev/null 2>&1; then
warning "optional component '${1}' not found, will omit"
return 0
fi

add_binary "${1}"
}

add_optional_module() {
# Add a kernel module to the initcpio image only if the module
# actually exists as a loadable file. Otherwise, ignore the module.
Expand All @@ -46,10 +56,7 @@ add_optional_module() {
}

add_zbm_binaries() {
local binaries mustcopy

# Optional mbuffer binary
command -v mbuffer >/dev/null 2>&1 && add_binary mbuffer
local mustcopy maycopy

# Hard requirements
# shellcheck disable=SC2154
Expand All @@ -60,6 +67,7 @@ add_zbm_binaries() {
*)
# Don't be a miser, use system versions
map add_binary "${zfsbootmenu_essential_binaries[@]}"
map add_optional_binary "${zfsbootmenu_optional_binaries[@]}"
return
;;
esac
Expand All @@ -70,8 +78,16 @@ add_zbm_binaries() {
<(printf "%s\n" "${zfsbootmenu_essential_binaries[@]}" | sort) \
<(/usr/lib/initcpio/busybox --list | sort))

# Copy the missing
# Copy the missing required binaries
map add_binary "${mustcopy[@]}"

# Do the say for optional binaries
# shellcheck disable=SC2154
readarray -t maycopy < <(comm -23 \
<(printf "%s\n" "${zfsbootmenu_optional_binaries[@]}" | sort) \
<(/usr/lib/initcpio/busybox --list | sort))

map add_optional_binary "${maycopy[@]}"
}

create_zbm_entrypoint() {
Expand All @@ -97,38 +113,31 @@ create_zbm_entrypoint() {
}


# TODO: confirm proper return code on installation failures
build() {
local hooks relative _file

# TODO: fix dracut-specific path
: "${zfsbootmenu_module_root:=/usr/share/zfsbootmenu}"

# shellcheck disable=SC1091
source "${zfsbootmenu_module_root}/install-helpers.sh" || exit 1

# shellcheck disable=SC2034
BUILDSTYLE="initcpio"

# Modules required for ZBM operation
map add_module zfs zcommon znvpair zavl zunicode zlua icp spl
# Modules (required and optional) used by ZBM
# shellcheck disable=SC2154
map add_module "${zfsbootmenu_essential_modules[@]}"

# shellcheck disable=SC2154
map add_optional_module "${zfsbootmenu_optional_modules[@]}"

# Optional modules
map add_optional_module zlib_deflate zlib_inflate
# Necessary udev rules (also finds required binaries)
# shellcheck disable=SC2154
map add_udev_rule "${zfsbootmenu_udev_rules[@]}"

# Binaries required for ZBM operation
add_zbm_binaries

# Necessary udev rules
map add_file \
/usr/lib/udev/rules.d/60-zvol.rules \
/usr/lib/udev/rules.d/69-vdev.rules \
/usr/lib/udev/rules.d/90-zfs.rules

# This helper tends to be used by the udev rules
[[ -f /usr/lib/udev/vdev_id ]] && add_file /usr/lib/udev/vdev_id

# TODO: figure out if libgcc_s.so.1 is necessary and add it

# On-line documentation
while read -r doc; do
relative="${doc#"${zfsbootmenu_module_root}/"}"
Expand Down
30 changes: 30 additions & 0 deletions zfsbootmenu/install-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ zfsbootmenu_essential_binaries=(
"fzf"
)

# shellcheck disable=SC2034
zfsbootmenu_optional_binaries=(
"mbuffer"
)

# shellcheck disable=SC2034
zfsbootmenu_udev_rules=(
"90-zfs.rules"
"69-vdev.rules"
"60-zvol.rules"
)

# shellcheck disable=SC2034
zfsbootmenu_essential_modules=(
"zfs"
"zcommon"
"znvpair"
"zavl"
"zunicode"
"zlua"
"icp"
"spl"
)

# shellcheck disable=SC2034
zfsbootmenu_optional_modules=(
"zlib_deflate"
"zlib_inflate"
)

create_zbm_conf() {
# Create core ZBM configuration file

Expand Down

0 comments on commit 65167e6

Please sign in to comment.