]>
Commit | Line | Data |
---|---|---|
e10b0808 AX |
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 | ||
cae5b340 AX |
13 | GENERATOR_FILE=/run/systemd/generator/sysroot.mount |
14 | GENERATOR_EXTENSION=/run/systemd/generator/sysroot.mount.d/zfs-enhancement.conf | |
15 | ||
16 | if [ -e "$GENERATOR_FILE" -a -e "$GENERATOR_EXTENSION" ] ; then | |
17 | # If the ZFS sysroot.mount flag exists, the initial RAM disk configured | |
18 | # it to mount ZFS on root. In that case, we bail early. This flag | |
19 | # file gets created by the zfs-generator program upon successful run. | |
20 | info "ZFS: There is a sysroot.mount and zfs-generator has extended it." | |
21 | info "ZFS: Delegating root mount to sysroot.mount." | |
22 | # Let us tell the initrd to run on shutdown. | |
23 | # We have a shutdown hook to run | |
24 | # because we imported the pool. | |
25 | # We now prevent Dracut from running this thing again. | |
26 | for zfsmounthook in "$hookdir"/mount/*zfs* ; do | |
27 | if [ -f "$zfsmounthook" ] ; then | |
28 | rm -f "$zfsmounthook" | |
29 | fi | |
30 | done | |
31 | return | |
32 | fi | |
33 | info "ZFS: No sysroot.mount exists or zfs-generator did not extend it." | |
34 | info "ZFS: Mounting root with the traditional mount-zfs.sh instead." | |
35 | ||
e10b0808 | 36 | # Delay until all required block devices are present. |
42f7b73b | 37 | modprobe zfs 2>/dev/null |
e10b0808 AX |
38 | udevadm settle |
39 | ||
40 | if [ "${root}" = "zfs:AUTO" ] ; then | |
41 | ZFS_DATASET="$(find_bootfs)" | |
42 | if [ $? -ne 0 ] ; then | |
43 | zpool import -N -a ${ZPOOL_IMPORT_OPTS} | |
44 | ZFS_DATASET="$(find_bootfs)" | |
45 | if [ $? -ne 0 ] ; then | |
46 | warn "ZFS: No bootfs attribute found in importable pools." | |
cae5b340 | 47 | export_all -F |
e10b0808 AX |
48 | |
49 | rootok=0 | |
50 | return 1 | |
51 | fi | |
52 | fi | |
53 | info "ZFS: Using ${ZFS_DATASET} as root." | |
54 | fi | |
55 | ||
56 | ZFS_DATASET="${ZFS_DATASET:-${root#zfs:}}" | |
57 | ZFS_POOL="${ZFS_DATASET%%/*}" | |
58 | ||
59 | if import_pool "${ZFS_POOL}" ; then | |
cae5b340 AX |
60 | # Let us tell the initrd to run on shutdown. |
61 | # We have a shutdown hook to run | |
62 | # because we imported the pool. | |
e10b0808 AX |
63 | info "ZFS: Mounting dataset ${ZFS_DATASET}..." |
64 | if mount_dataset "${ZFS_DATASET}" ; then | |
65 | ROOTFS_MOUNTED=yes | |
66 | return 0 | |
67 | fi | |
68 | fi | |
69 | ||
70 | rootok=0 |