]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/contrib/dracut/90zfs/module-setup.sh.in
MFV 2.0-rc2
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / contrib / dracut / 90zfs / module-setup.sh.in
1 #!/usr/bin/env bash
2
3 check() {
4         # We depend on udev-rules being loaded
5         [ "${1}" = "-d" ] && return 0
6
7         # Verify the zfs tool chain
8         for tool in "@bindir@/zgenhostid" "@sbindir@/zpool" "@sbindir@/zfs" "@mounthelperdir@/mount.zfs" ; do
9                 test -x "$tool" || return 1
10         done
11         # Verify grep exists
12         which grep >/dev/null 2>&1 || return 1
13
14         return 0
15 }
16
17 depends() {
18         echo udev-rules
19         return 0
20 }
21
22 installkernel() {
23         instmods zfs
24         instmods zcommon
25         instmods znvpair
26         instmods zavl
27         instmods zunicode
28         instmods zlua
29         instmods icp
30         instmods spl
31         instmods zlib_deflate
32         instmods zlib_inflate
33 }
34
35 install() {
36         inst_rules @udevruledir@/90-zfs.rules
37         inst_rules @udevruledir@/69-vdev.rules
38         inst_rules @udevruledir@/60-zvol.rules
39         dracut_install hostid
40         dracut_install grep
41         dracut_install @bindir@/zgenhostid
42         dracut_install @sbindir@/zfs
43         dracut_install @sbindir@/zpool
44         # Workaround for zfsonlinux/zfs#4749 by ensuring libgcc_s.so(.1) is included
45         if [[ -n "$(ldd @sbindir@/zpool | grep -F 'libgcc_s.so')" ]]; then
46                 # Dracut will have already tracked and included it
47                 :;
48         elif command -v gcc-config 2>&1 1>/dev/null; then
49                 # On systems with gcc-config (Gentoo, Funtoo, etc.):
50                 # Use the current profile to resolve the appropriate path
51                 dracut_install "/usr/lib/gcc/$(s=$(gcc-config -c); echo ${s%-*}/${s##*-})/libgcc_s.so.1"
52         elif [[ -n "$(ls /usr/lib/libgcc_s.so* 2>/dev/null)" ]]; then
53                 # Try a simple path first
54                 dracut_install /usr/lib/libgcc_s.so*
55         else
56                 # Fallback: Guess the path and include all matches
57                 dracut_install /usr/lib/gcc/*/*/libgcc_s.so*
58         fi
59         dracut_install @mounthelperdir@/mount.zfs
60         dracut_install @udevdir@/vdev_id
61         dracut_install awk
62         dracut_install basename
63         dracut_install cut
64         dracut_install head
65         dracut_install @udevdir@/zvol_id
66         inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
67         if [ -n "$systemdutildir" ] ; then
68                 inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
69         fi
70         inst_hook pre-mount 90 "${moddir}/zfs-load-key.sh"
71         inst_hook mount 98 "${moddir}/mount-zfs.sh"
72         inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh"
73         inst_hook shutdown 20 "${moddir}/export-zfs.sh"
74
75         inst_simple "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
76         if [ -e @sysconfdir@/zfs/zpool.cache ]; then
77                 inst @sysconfdir@/zfs/zpool.cache
78                 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/zpool.cache
79         fi
80
81         if [ -e @sysconfdir@/zfs/vdev_id.conf ]; then
82                 inst @sysconfdir@/zfs/vdev_id.conf
83                 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/vdev_id.conf
84         fi
85
86         # Synchronize initramfs and system hostid
87         zgenhostid -o "${initdir}/etc/hostid" "$(hostid)"
88
89         if dracut_module_included "systemd"; then
90                 mkdir -p "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"
91                 for _item in scan cache ; do
92                         dracut_install @systemdunitdir@/zfs-import-$_item.service
93                         if ! [ -L "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"/zfs-import-$_item.service ]; then
94                                 ln -s ../zfs-import-$_item.service "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"/zfs-import-$_item.service
95                                 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-import-$_item.service
96                         fi
97                 done
98                 inst "${moddir}"/zfs-env-bootfs.service "${systemdsystemunitdir}"/zfs-env-bootfs.service
99                 ln -s ../zfs-env-bootfs.service "${initdir}/${systemdsystemunitdir}/zfs-import.target.wants"/zfs-env-bootfs.service
100                 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-env-bootfs.service
101                 dracut_install systemd-ask-password
102                 dracut_install systemd-tty-ask-password-agent
103                 mkdir -p "${initdir}/$systemdsystemunitdir/initrd.target.wants"
104                 dracut_install @systemdunitdir@/zfs-import.target
105                 if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target ]; then
106                         ln -s ../zfs-import.target "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target
107                         type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-import.target
108                 fi
109                 for _service in zfs-snapshot-bootfs.service zfs-rollback-bootfs.service ; do
110                         inst "${moddir}"/$_service "${systemdsystemunitdir}"/$_service
111                         if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/$_service ]; then
112                                 ln -s ../$_service "${initdir}/$systemdsystemunitdir/initrd.target.wants"/$_service
113                         fi
114                 done
115         fi
116 }