]> git.proxmox.com Git - mirror_zfs.git/blob - contrib/dracut/90zfs/mount-zfs.sh.in
A collection of dracut fixes
[mirror_zfs.git] / contrib / dracut / 90zfs / mount-zfs.sh.in
1 #!/bin/sh
2
3 . /lib/dracut-zfs-lib.sh
4
5 ZFS_DATASET=""
6 ZFS_POOL=""
7
8 case "${root}" in
9 zfs:*) ;;
10 *) return ;;
11 esac
12
13 # If sysroot.mount exists, the initial RAM disk configured
14 # it to mount ZFS on root. In that case, we bail early.
15 loadstate="$(systemctl --system --show -p LoadState sysroot.mount || true)"
16 if [ "${loadstate}" = "LoadState=not-found" -o "${loadstate}" = "" ] ; then
17 info "ZFS: sysroot.mount absent, mounting root with mount-zfs.sh"
18 else
19 info "ZFS: sysroot.mount present, delegating root mount to it"
20 return
21 fi
22
23 # Delay until all required block devices are present.
24 udevadm settle
25
26 if [ "${root}" = "zfs:AUTO" ] ; then
27 ZFS_DATASET="$(find_bootfs)"
28 if [ $? -ne 0 ] ; then
29 zpool import -N -a ${ZPOOL_IMPORT_OPTS}
30 ZFS_DATASET="$(find_bootfs)"
31 if [ $? -ne 0 ] ; then
32 warn "ZFS: No bootfs attribute found in importable pools."
33 export_all || export_all "-f"
34
35 rootok=0
36 return 1
37 fi
38 fi
39 info "ZFS: Using ${ZFS_DATASET} as root."
40 fi
41
42 ZFS_DATASET="${ZFS_DATASET:-${root#zfs:}}"
43 ZFS_POOL="${ZFS_DATASET%%/*}"
44
45 if import_pool "${ZFS_POOL}" ; then
46 info "ZFS: Mounting dataset ${ZFS_DATASET}..."
47 if mount_dataset "${ZFS_DATASET}" ; then
48 ROOTFS_MOUNTED=yes
49 return 0
50 fi
51 fi
52
53 rootok=0
54 need_shutdown