aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/dracut/90zfs/mount-zfs.sh.in
blob: 43862fa8f68730fc4258f977ea5148b3d0d837cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh

. /lib/dracut-zfs-lib.sh

ZFS_DATASET=""
ZFS_POOL=""

case "${root}" in
	zfs:*) ;;
	*) return ;;
esac

# 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

# 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