Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initramfs: fix import of additional zpools on boot #13543

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ find_zfs_block_devices() {
done < /proc/self/mountinfo
}

find_add_zpool_mps() {
local dev
local mp
local fstype
local _
numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)"
if [ "$numfields" = "10" ] ; then
fields="_ _ _ _ mp _ _ fstype dev _"
else
fields="_ _ _ _ mp _ _ _ fstype dev _"
fi
# shellcheck disable=SC2086
while read -r ${fields?} ; do
[ "$fstype" = "zfs" ] || continue
[ "$dev" = "$1" ] && echo "$mp"
done < /proc/self/mountinfo
}

array_contains () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
Expand All @@ -75,6 +93,14 @@ check() {
# shellcheck disable=SC2154
if [ -n "$hostonly" ]; then

if [ -f @sysconfdir@/default/zfs ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nowhere else in the dracut config do we source @sysconfdir@/default/zfs for environment variables. If we need to be able to specify this we should do it in a way which is consistent the the design described in man/man7/dracut.zfs.7.

. @sysconfdir@/default/zfs
if [ -n "$ZFS_INITRD_ADDITIONAL_DATASETS" ]; then
for add_zpool in $ZFS_INITRD_ADDITIONAL_DATASETS; do
add_mps+=$(find_add_zpool_mps "$add_zpool")
done
fi
fi
for mp in \
"/" \
"/etc" \
Expand All @@ -87,7 +113,8 @@ if [ -n "$hostonly" ]; then
"/usr/sbin" \
"/usr/lib" \
"/usr/lib64" \
"/boot";
"/boot" \
"${add_mps[@]}";
do
mp=$(readlink -f "$mp")
mountpoint "$mp" >/dev/null 2>&1 || continue
Expand Down
3 changes: 2 additions & 1 deletion contrib/dracut/90zfs/module-setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ install() {
# -o ensures there is no error upon absence of these files
inst_multiple -o -H \
"@sysconfdir@/zfs/zpool.cache" \
"@sysconfdir@/zfs/vdev_id.conf"
"@sysconfdir@/zfs/vdev_id.conf" \
"@sysconfdir@/default/zfs"

# Synchronize initramfs and system hostid
if ! inst_simple -H @sysconfdir@/hostid; then
Expand Down
9 changes: 9 additions & 0 deletions contrib/initramfs/scripts/zfs
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,15 @@ mountroot()
ZFS_RPOOL="${pool}"
fi

# We need to import additional zpools which aren't under root zpool, before mount_fs()
for add_zpool in $ZFS_INITRD_ADDITIONAL_DATASETS; do
add_zpool_base="${add_zpool%%/*}"

if [ "$add_zpool_base" != "$ZFS_RPOOL" ]
then
import_pool "${add_zpool_base}"
fi
done

# ----------------------------------------------------------------
# P R E P A R E R O O T F I L E S Y S T E M
Expand Down