]> git.proxmox.com Git - mirror_zfs-debian.git/blob - contrib/dracut/90zfs/zfs-generator.sh.in
New upstream version 0.7.2
[mirror_zfs-debian.git] / contrib / dracut / 90zfs / zfs-generator.sh.in
1 #!/bin/bash
2
3 echo "zfs-generator: starting" >> /dev/kmsg
4
5 GENERATOR_DIR="$1"
6 [ -n "$GENERATOR_DIR" ] || {
7 echo "zfs-generator: no generator directory specified, exiting" >> /dev/kmsg
8 exit 1
9 }
10
11 [ -f /lib/dracut-lib.sh ] && dracutlib=/lib/dracut-lib.sh
12 [ -f /usr/lib/dracut/modules.d/99base/dracut-lib.sh ] && dracutlib=/usr/lib/dracut/modules.d/99base/dracut-lib.sh
13
14 type getarg >/dev/null 2>&1 || {
15 echo "zfs-generator: loading Dracut library from $dracutlib" >> /dev/kmsg
16 . "$dracutlib"
17 }
18
19 [ -z "$root" ] && root=$(getarg root=)
20 [ -z "$rootfstype" ] && rootfstype=$(getarg rootfstype=)
21 [ -z "$rootflags" ] && rootflags=$(getarg rootflags=)
22
23 # If root is not ZFS= or zfs: or rootfstype is not zfs
24 # then we are not supposed to handle it.
25 [ "${root##zfs:}" = "${root}" -a "${root##ZFS=}" = "${root}" -a "$rootfstype" != "zfs" ] && exit 0
26 # If root is set to zfs:AUTO, then we are also not
27 # supposed to handle it, and it should be handled
28 # by the traditional Dracut mount hook.
29 # See https://github.com/zfsonlinux/zfs/pull/4558#discussion_r61118952
30 if [ "${root}" = "zfs:AUTO" ] ; then
31 exit 0
32 fi
33
34 rootfstype=zfs
35 if echo "${rootflags}" | grep -Eq '^zfsutil$|^zfsutil,|,zfsutil$|,zfsutil,' ; then
36 true
37 elif test -n "${rootflags}" ; then
38 rootflags="zfsutil,${rootflags}"
39 else
40 rootflags=zfsutil
41 fi
42
43 root="${root##zfs:}"
44 root="${root##ZFS=}"
45
46 echo "zfs-generator: writing extension for sysroot.mount to $GENERATOR_DIR"/sysroot.mount.d/zfs-enhancement.conf >> /dev/kmsg
47
48 [ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR"
49 [ -d "$GENERATOR_DIR"/sysroot.mount.d ] || mkdir "$GENERATOR_DIR"/sysroot.mount.d
50
51 {
52 echo "[Unit]"
53 echo "Before=initrd-root-fs.target"
54 echo "After=zfs-import-scan.service"
55 echo "After=zfs-import-cache.service"
56 echo "[Mount]"
57 echo "What=${root}"
58 echo "Type=${rootfstype}"
59 echo "Options=${rootflags}"
60 } > "$GENERATOR_DIR"/sysroot.mount.d/zfs-enhancement.conf
61
62 [ -d "$GENERATOR_DIR"/initrd-root-fs.target.requires ] || mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires
63 ln -s ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount
64
65 echo "zfs-generator: finished" >> /dev/kmsg