]> git.proxmox.com Git - mirror_zfs.git/blame - contrib/dracut/90zfs/zfs-generator.sh.in
A collection of dracut fixes
[mirror_zfs.git] / contrib / dracut / 90zfs / zfs-generator.sh.in
CommitLineData
a5a37022
MT
1#!/bin/bash
2
3GENERATOR_DIR="$1"
4[ -z "$GENERATOR_DIR" ] && exit 1
5
6[ -f /lib/dracut-lib.sh ] && dracutlib=/lib/dracut-lib.sh
7[ -f /usr/lib/dracut/modules.d/99base/dracut-lib.sh ] && dracutlib=/usr/lib/dracut/modules.d/99base/dracut-lib.sh
8
9type getarg >/dev/null 2>&1 || . "$dracutlib"
10
11[ -z "$root" ] && root=$(getarg root=)
12[ -z "$rootfstype" ] && rootfstype=$(getarg rootfstype=)
13[ -z "$rootflags" ] && rootflags=$(getarg rootflags=)
14
15[ "${root##zfs:}" = "${root}" -a "${root##ZFS=}" = "${root}" -a "$rootfstype" != "zfs" ] && exit 0
d402c18d
MAR
16# If root is set to zfs:AUTO, then we know sysroot.mount will not be generated
17# so we have no need to enhance it.
18# See https://github.com/zfsonlinux/zfs/pull/4558#discussion_r61118952 for details.
19if [ "${root}" = "zfs:AUTO" ] ; then
20 exit 0
21fi
a5a37022
MT
22
23rootfstype=zfs
d402c18d 24if echo "${rootflags}" | grep -Eq '^zfsutil$|^zfsutil,|,zfsutil$|,zfsutil,' ; then
a5a37022 25 true
d402c18d
MAR
26elif test -n "${rootflags}" ; then
27 rootflags="zfsutil,${rootflags}"
a5a37022
MT
28else
29 rootflags=zfsutil
30fi
31
32root="${root##zfs:}"
33root="${root##ZFS=}"
34
35[ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR"
36[ -d "$GENERATOR_DIR/sysroot.mount.d" ] || mkdir "$GENERATOR_DIR/sysroot.mount.d"
37
38{
39 echo "[Unit]"
40 echo "After=zfs-import-scan.service"
41 echo "After=zfs-import-cache.service"
42 echo ""
43 echo "[Mount]"
44 echo "What=${root}"
45 echo "Type=${rootfstype}"
46 echo "Options=${rootflags}"
47} > "$GENERATOR_DIR/sysroot.mount.d/zfs-enhancement.conf"