mirror_zfs/contrib/dracut/90zfs/mount-zfs.sh.in
Moritz Maxeiner 8516203d53 zfs dracut module should not assume systemd presence
Signed-off-by: Moritz Maxeiner <moritz@ucworks.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #4749
Closes #5058
2016-09-09 10:17:27 -07:00

57 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
. /lib/dracut-zfs-lib.sh
ZFS_DATASET=""
ZFS_POOL=""
case "${root}" in
zfs:*) ;;
*) return ;;
esac
if command -v systemctl >/dev/null; then
# If sysroot.mount exists, the initial RAM disk configured
# it to mount ZFS on root. In that case, we bail early.
loadstate="$(systemctl --system --show -p LoadState sysroot.mount || true)"
if [ "${loadstate}" = "LoadState=not-found" -o "${loadstate}" = "" ] ; then
info "ZFS: sysroot.mount absent, mounting root with mount-zfs.sh"
else
info "ZFS: sysroot.mount present, delegating root mount to it"
return
fi
fi
# Delay until all required block devices are present.
udevadm settle
if [ "${root}" = "zfs:AUTO" ] ; then
ZFS_DATASET="$(find_bootfs)"
if [ $? -ne 0 ] ; then
zpool import -N -a ${ZPOOL_IMPORT_OPTS}
ZFS_DATASET="$(find_bootfs)"
if [ $? -ne 0 ] ; then
warn "ZFS: No bootfs attribute found in importable pools."
export_all || export_all "-f"
rootok=0
return 1
fi
fi
info "ZFS: Using ${ZFS_DATASET} as root."
fi
ZFS_DATASET="${ZFS_DATASET:-${root#zfs:}}"
ZFS_POOL="${ZFS_DATASET%%/*}"
if import_pool "${ZFS_POOL}" ; then
info "ZFS: Mounting dataset ${ZFS_DATASET}..."
if mount_dataset "${ZFS_DATASET}" ; then
ROOTFS_MOUNTED=yes
return 0
fi
fi
rootok=0
need_shutdown