mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-30 10:44:09 +03:00
contrib/dracut: 90: mount essential datasets under root
This partly mirrors what the i-t script does (though that mounts all children, recursively) ‒ /etc, /usr, /lib*, and /bin are all essential, if present, to successfully invoke the real init, which will then mount everything else it might need in the right order The following extreme-case set-up boots w/o issues now: / zoot zfs rw,relatime,xattr,noacl ├─/etc zoot/etc zfs rw,relatime,xattr,noacl ├─/usr zoot/usr zfs rw,relatime,xattr,noacl │ └─/usr/local zoot/usr/local zfs rw,relatime,xattr,noacl ├─/var zoot/var zfs rw,relatime,xattr,noacl │ ├─/var/lib zoot/var/lib zfs rw,relatime,xattr,noacl │ ├─/var/log zoot/var/log zfs rw,relatime,xattr,posixacl │ ├─/var/cache zoot/var/cache zfs rw,relatime,xattr,noacl │ └─/var/tmp zoot/var/tmp zfs rw,relatime,xattr,noacl ├─/home zoot/home zfs rw,relatime,xattr,noacl │ └─/home/nab zoot/home/nab zfs rw,relatime,xattr,noacl ├─/boot zoot/boot zfs rw,relatime,xattr,noacl ├─/root zoot/home/root zfs rw,relatime,xattr,noacl ├─/opt zoot/opt zfs rw,relatime,xattr,noacl └─/srv zoot/srv zfs rw,relatime,xattr,noacl Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #11898
This commit is contained in:
@@ -23,6 +23,7 @@ command -v getargbool >/dev/null || {
|
||||
OLDIFS="${IFS}"
|
||||
NEWLINE="
|
||||
"
|
||||
TAB=" "
|
||||
|
||||
ZPOOL_IMPORT_OPTS=""
|
||||
if getargbool 0 zfs_force -y zfs.force -y zfsforce ; then
|
||||
@@ -58,7 +59,7 @@ find_bootfs() {
|
||||
# import_pool POOL
|
||||
# imports the given zfs pool if it isn't imported already.
|
||||
import_pool() {
|
||||
pool="${1}"
|
||||
pool="${1}"
|
||||
|
||||
if ! zpool list -H "${pool}" > /dev/null 2>&1; then
|
||||
info "ZFS: Importing pool ${pool}..."
|
||||
@@ -71,26 +72,62 @@ import_pool() {
|
||||
return 0
|
||||
}
|
||||
|
||||
_mount_dataset_cb() {
|
||||
mount -o zfsutil -t zfs "${1}" "${NEWROOT}${2}"
|
||||
}
|
||||
|
||||
# mount_dataset DATASET
|
||||
# mounts the given zfs dataset.
|
||||
mount_dataset() {
|
||||
dataset="${1}"
|
||||
dataset="${1}"
|
||||
mountpoint="$(zfs get -H -o value mountpoint "${dataset}")"
|
||||
ret=0
|
||||
|
||||
# We need zfsutil for non-legacy mounts and not for legacy mounts.
|
||||
if [ "${mountpoint}" = "legacy" ] ; then
|
||||
mount -t zfs "${dataset}" "${NEWROOT}"
|
||||
mount -t zfs "${dataset}" "${NEWROOT}" || ret=$?
|
||||
else
|
||||
mount -o zfsutil -t zfs "${dataset}" "${NEWROOT}"
|
||||
mount -o zfsutil -t zfs "${dataset}" "${NEWROOT}" || ret=$?
|
||||
|
||||
if [ "$ret" = "0" ]; then
|
||||
for_relevant_root_children "${dataset}" _mount_dataset_cb || ret=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
return $?
|
||||
return ${ret}
|
||||
}
|
||||
|
||||
# for_relevant_root_children DATASET EXEC
|
||||
# Runs "EXEC dataset mountpoint" for all children of DATASET that are needed for system bringup
|
||||
# Used by zfs-generator.sh and friends, too!
|
||||
for_relevant_root_children() {
|
||||
dataset="${1}"
|
||||
exec="${2}"
|
||||
|
||||
zfs list -t filesystem -Ho name,mountpoint,canmount -r "${dataset}" |
|
||||
(
|
||||
_ret=0
|
||||
while IFS="${TAB}" read -r dataset mountpoint canmount; do
|
||||
[ "$canmount" != "on" ] && continue
|
||||
|
||||
case "$mountpoint" in
|
||||
/etc|/bin|/lib|/lib??|/libx32|/usr)
|
||||
# If these aren't mounted we may not be able to get to the real init at all, or pollute the dataset holding the rootfs
|
||||
"${exec}" "${dataset}" "${mountpoint}" || _ret=$?
|
||||
;;
|
||||
*)
|
||||
# Up to the real init to remount everything else it might need
|
||||
;;
|
||||
esac
|
||||
done
|
||||
exit ${_ret}
|
||||
)
|
||||
}
|
||||
|
||||
# export_all OPTS
|
||||
# exports all imported zfs pools.
|
||||
export_all() {
|
||||
opts="${@}"
|
||||
opts="${@}"
|
||||
ret=0
|
||||
|
||||
IFS="${NEWLINE}"
|
||||
|
||||
Reference in New Issue
Block a user