summaryrefslogtreecommitdiffstats
path: root/contrib/dracut/90zfs/zfs-generator.sh.in
blob: 59cdadcbeae5e6f68e25b2e6d781b33530c336ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh

echo "zfs-generator: starting" >> /dev/kmsg

GENERATOR_DIR="$1"
[ -n "$GENERATOR_DIR" ] || {
    echo "zfs-generator: no generator directory specified, exiting" >> /dev/kmsg
    exit 1
}

[ -f /lib/dracut-lib.sh ] && dracutlib=/lib/dracut-lib.sh
[ -f /usr/lib/dracut/modules.d/99base/dracut-lib.sh ] && dracutlib=/usr/lib/dracut/modules.d/99base/dracut-lib.sh

command -v getarg >/dev/null 2>&1 || {
    echo "zfs-generator: loading Dracut library from $dracutlib" >> /dev/kmsg
    . "$dracutlib"
}

[ -z "$root" ]       && root=$(getarg root=)
[ -z "$rootfstype" ] && rootfstype=$(getarg rootfstype=)
[ -z "$rootflags" ]  && rootflags=$(getarg rootflags=)

# If root is not ZFS= or zfs: or rootfstype is not zfs
# then we are not supposed to handle it.
[ "${root##zfs:}" = "${root}" ] &&
	[ "${root##ZFS=}" = "${root}" ] &&
	[ "$rootfstype" != "zfs" ] &&
	exit 0

rootfstype=zfs
case ",${rootflags}," in
	*,zfsutil,*) ;;
	,,)	rootflags=zfsutil ;;
	*)	rootflags="zfsutil,${rootflags}" ;;
esac

echo "zfs-generator: writing extension for sysroot.mount to $GENERATOR_DIR"/sysroot.mount.d/zfs-enhancement.conf >> /dev/kmsg

[ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR"
[ -d "$GENERATOR_DIR"/sysroot.mount.d ] || mkdir "$GENERATOR_DIR"/sysroot.mount.d

{
    echo "[Unit]"
    echo "Before=initrd-root-fs.target"
    echo "After=zfs-import.target"
    echo "[Mount]"
    if [ "${root}" = "zfs:AUTO" ] ; then
      echo "PassEnvironment=BOOTFS"
      echo 'What=${BOOTFS}'
    else
      root="${root##zfs:}"
      root="${root##ZFS=}"
      echo "What=${root}"
    fi
    echo "Type=${rootfstype}"
    echo "Options=${rootflags}"
} > "$GENERATOR_DIR"/sysroot.mount.d/zfs-enhancement.conf

[ -d "$GENERATOR_DIR"/initrd-root-fs.target.requires ] || mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires
ln -s ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount

echo "zfs-generator: finished" >> /dev/kmsg