Files
mirror_zfs/contrib/dracut/90zfs/module-setup.sh.in
T

132 lines
4.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# shellcheck disable=SC2154
2011-07-04 13:25:31 -04:00
check() {
2011-07-24 16:46:16 -04:00
# We depend on udev-rules being loaded
2022-11-12 22:22:49 +10:00
[[ "${1}" = "-d" ]] && return 0
2011-07-04 13:25:31 -04:00
2011-07-24 16:46:16 -04:00
# Verify the zfs tool chain
for tool in "zgenhostid" "zpool" "zfs" "mount.zfs"; do
command -v "${tool}" >/dev/null || return 1
2016-04-24 11:35:44 +00:00
done
2011-07-04 13:25:31 -04:00
}
depends() {
2011-07-24 16:46:16 -04:00
echo udev-rules
2011-07-04 13:25:31 -04:00
}
installkernel() {
instmods -c zfs
2011-07-04 13:25:31 -04:00
}
install() {
inst_rules 90-zfs.rules 69-vdev.rules 60-zvol.rules
inst_multiple \
zgenhostid \
zfs \
zpool \
mount.zfs \
hostid \
grep \
awk \
tr \
cut \
head ||
{ dfatal "Failed to install essential binaries"; exit 1; }
# Adapted from https://github.com/zbm-dev/zfsbootmenu
if ! ldd "$(command -v zpool)" | grep -qF 'libgcc_s.so' && ldconfig -p 2> /dev/null | grep -qF 'libc.so.6' ; then
# On systems with gcc-config (Gentoo, Funtoo, etc.), use it to find libgcc_s
if command -v gcc-config >/dev/null; then
inst_simple "/usr/lib/gcc/$(s=$(gcc-config -c); echo "${s%-*}/${s##*-}")/libgcc_s.so.1" ||
{ dfatal "Unable to install libgcc_s.so"; exit 1; }
# Otherwise, use dracut's library installation function to find the right one
elif ! inst_libdir_file "libgcc_s.so*"; then
# If all else fails, just try looking for some gcc arch directory
inst_simple /usr/lib/gcc/*/*/libgcc_s.so* ||
{ dfatal "Unable to install libgcc_s.so"; exit 1; }
fi
fi
2015-02-15 20:28:42 +01:00
inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
2022-11-12 22:22:49 +10:00
if [[ -n "${systemdutildir}" ]]; then
inst_script "${moddir}/zfs-generator.sh" "${systemdutildir}/system-generators/dracut-zfs-generator"
2016-03-30 18:59:15 -05:00
fi
2018-01-18 18:20:34 +00:00
inst_hook pre-mount 90 "${moddir}/zfs-load-key.sh"
2016-04-24 11:35:44 +00:00
inst_hook mount 98 "${moddir}/mount-zfs.sh"
inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh"
inst_hook shutdown 20 "${moddir}/export-zfs.sh"
2011-09-30 10:33:26 -07:00
inst_script "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
2013-03-20 11:25:50 -07:00
# -H ensures they are marked host-only
# -o ensures there is no error upon absence of these files
inst_multiple -o -H \
"@sysconfdir@/zfs/zpool.cache" \
"@sysconfdir@/zfs/vdev_id.conf"
2015-02-16 04:08:04 +01:00
2011-09-30 10:33:26 -07:00
# Synchronize initramfs and system hostid
if ! inst_simple -H @sysconfdir@/hostid; then
2022-11-12 22:22:49 +10:00
if HOSTID="$(hostid 2>/dev/null)" && [[ "${HOSTID}" != "00000000" ]]; then
zgenhostid -o "${initdir}@sysconfdir@/hostid" "${HOSTID}"
mark_hostonly @sysconfdir@/hostid
fi
fi
2016-03-30 18:59:15 -05:00
if dracut_module_included "systemd"; then
inst_simple "${systemdsystemunitdir}/zfs-import.target"
systemctl -q --root "${initdir}" add-wants initrd.target zfs-import.target
inst_simple "${moddir}/zfs-env-bootfs.service" "${systemdsystemunitdir}/zfs-env-bootfs.service"
systemctl -q --root "${initdir}" add-wants zfs-import.target zfs-env-bootfs.service
inst_simple "${moddir}/zfs-nonroot-necessities.service" "${systemdsystemunitdir}/zfs-nonroot-necessities.service"
systemctl -q --root "${initdir}" add-requires initrd-root-fs.target zfs-nonroot-necessities.service
2022-10-23 11:11:18 +02:00
# Add user-provided unit overrides:
# - /etc/systemd/system/${_service}
# - /etc/systemd/system/${_service}.d/overrides.conf
# -H ensures they are marked host-only
# -o ensures there is no error upon absence of these files
inst_multiple -o -H \
"${systemdsystemconfdir}/zfs-import.target" \
"${systemdsystemconfdir}/zfs-import.target.d/"*.conf
for _service in \
"zfs-import-scan.service" \
"zfs-import-cache.service"; do
inst_simple "${systemdsystemunitdir}/${_service}"
systemctl -q --root "${initdir}" add-wants zfs-import.target "${_service}"
2022-10-23 11:11:18 +02:00
# Add user-provided unit overrides:
# - /etc/systemd/system/${_service}
# - /etc/systemd/system/${_service}.d/overrides.conf
# -H ensures they are marked host-only
# -o ensures there is no error upon absence of these files
inst_multiple -o -H \
"${systemdsystemconfdir}/${_service}" \
"${systemdsystemconfdir}/${_service}.d/"*.conf
done
for _service in \
"zfs-snapshot-bootfs.service" \
"zfs-rollback-bootfs.service"; do
inst_simple "${moddir}/${_service}" "${systemdsystemunitdir}/${_service}"
systemctl -q --root "${initdir}" add-wants initrd.target "${_service}"
# Add user-provided unit overrides:
# - /etc/systemd/system/${_service}
# - /etc/systemd/system/${_service}.d/overrides.conf
# -H ensures they are marked host-only
# -o ensures there is no error upon absence of these files
inst_multiple -o -H \
"${systemdsystemconfdir}/${_service}" \
"${systemdsystemconfdir}/${_service}.d/"*.conf
done
inst_simple "${moddir}/import-opts-generator.sh" "${systemdutildir}/system-environment-generators/zfs-import-opts.sh"
2016-03-30 18:59:15 -05:00
fi
2011-07-04 13:25:31 -04:00
}