]>
Commit | Line | Data |
---|---|---|
ae26d046 MAR |
1 | #!/bin/sh |
2 | ||
eda3d4e1 | 3 | . /lib/dracut-zfs-lib.sh |
ae26d046 | 4 | |
eda3d4e1 ST |
5 | ZFS_DATASET="" |
6 | ZFS_POOL="" | |
a4719e54 | 7 | |
eda3d4e1 ST |
8 | case "${root}" in |
9 | zfs:*) ;; | |
10 | *) return ;; | |
11 | esac | |
fde4ce99 | 12 | |
d402c18d MAR |
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 | ||
7b4536c7 GB |
23 | # Delay until all required block devices are present. |
24 | udevadm settle | |
25 | ||
eda3d4e1 ST |
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." | |
edbaf245 | 33 | export_all || export_all "-f" |
eda3d4e1 ST |
34 | |
35 | rootok=0 | |
36 | return 1 | |
1ef5e829 | 37 | fi |
eda3d4e1 ST |
38 | fi |
39 | info "ZFS: Using ${ZFS_DATASET} as root." | |
40 | fi | |
fde4ce99 | 41 | |
eda3d4e1 ST |
42 | ZFS_DATASET="${ZFS_DATASET:-${root#zfs:}}" |
43 | ZFS_POOL="${ZFS_DATASET%%/*}" | |
07a3312f | 44 | |
eda3d4e1 ST |
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 |