Skip to content

Commit

Permalink
Move dataset mountpoint to $BASE/environments/
Browse files Browse the repository at this point in the history
Creating a directory tree for zpools / datasets rooted in $BASE could
potentially lead to a conflict between one of the various files we
create and a pool name. Moving the root of this to $BASE/environments/
means that there can't be a conflict, since imported pool names must be
unique.

Additionally, a helper was added to return a string with the path to a
given filesystem on disk. This avoids manually constructing the path and
having to update those individually should this directory location ever
change.
  • Loading branch information
zdykstra committed Oct 30, 2022
1 parent 7eb7780 commit 3399f4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
30 changes: 25 additions & 5 deletions zfsbootmenu/lib/zfsbootmenu-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ mount_zfs() {
return 1
fi

mnt="${BASE}/${fs}/mnt"
mnt="$( be_location "${fs}" )/mnt"
mkdir -p "${mnt}"

# filesystems are readonly by default, but read-write mounts may be requested
Expand Down Expand Up @@ -782,7 +782,7 @@ find_be_kernels() {
# returns: nothing

select_kernel() {
local zfsbe specific_kernel kexec_args spec_kexec_args
local zfsbe bepath specific_kernel kexec_args spec_kexec_args

zfsbe="${1}"
if [ -z "${zfsbe}" ]; then
Expand All @@ -791,8 +791,10 @@ select_kernel() {
fi
zdebug "zfsbe set to ${zfsbe}"

bepath="$( be_location "${zfsbe}" )"

# By default, select the last kernel entry
kexec_args="$( tail -1 "${BASE}/${zfsbe}/kernels" )"
kexec_args="$( tail -1 "${bepath}/kernels" )"

# If a specific kernel is listed, prefer it when possible
specific_kernel="$( zfs get -H -o value org.zfsbootmenu:kernel "${zfsbe}" )"
Expand All @@ -806,7 +808,7 @@ select_kernel() {
kexec_args="${spec_kexec_args}"
break
fi
done <<<"$( tac "${BASE}/${zfsbe}/kernels" )"
done <<<"$( tac "${bepath}/kernels" )"
fi

zdebug "using kexec args: ${kexec_args}"
Expand Down Expand Up @@ -921,7 +923,7 @@ load_be_cmdline() {
fi
zdebug "fs set to ${fs}"

cache="${BASE}/${fs}/cmdline"
cache="$( be_location "${fs}" )/cmdline"

if [ -r "${BASE}/cmdline" ]; then
# Always prefer a user-entered KCL
Expand Down Expand Up @@ -1743,6 +1745,24 @@ load_key() {
return $?
}

# arg1: ZFS filesystem
# prints: The base path to this filesystem for use by ZFSBootMenu functions, with out a trailing /
# returns: nothing

be_location() {
local fs beloc
fs="${1}"
if [ -z "${fs}" ]; then
zerror "fs is undefined"
return 1
fi
zdebug "fs set to ${fs}"

local beloc="${BASE}/environments/${fs}"
mkdir -p "${beloc}"
echo "${beloc}"
}

# arg1: ZFS filesystem
# prints: nothing
# returns: nothing
Expand Down
2 changes: 1 addition & 1 deletion zfsbootmenu/lib/zfsbootmenu-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ populate_be_list() {
ret=1
for fs in "${candidates[@]}"; do
# Remove any existing cmdline cache
rm -f "${BASE}/${fs}/cmdline"
rm -f "$( be_location "${fs}" )/cmdline"

# Unlock if necessary
load_key "${fs}" || continue
Expand Down

0 comments on commit 3399f4b

Please sign in to comment.