Make better use of dracut functions when building initramfs

Setting up the module involves multiple redundant calls to a bunch of
dracut functions wheich can be combined into one. Additionally, the mass
of code required to load libgcc_s.so* can be replaced with one dracut
function. This has the additional effect of removing errors involving
the non-installation of libgcc_s.so* which are seen on debian bullseye
when using version 2.1.2-1~bpo11+1 from the backports repository.

The systemd binaries are separated out into their own `dracut_install`
function call so they do not get pulled in when dracut does not load the
systemd module.

Reviewed-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Andrew J. Hesford <ajh@sideband.org>
Signed-off-by: Savyasachee Jha <hi@savyasacheejha.com>
Closes #13010
This commit is contained in:
Savyasachee Jha 2022-01-25 03:22:48 +00:00 committed by Brian Behlendorf
parent 05147319b0
commit 0671f72706
1 changed files with 24 additions and 53 deletions

View File

@ -20,59 +20,30 @@ depends() {
installkernel() { installkernel() {
instmods zfs instmods zfs
instmods zcommon
instmods znvpair
instmods zavl
instmods zunicode
instmods zlua
instmods icp
instmods spl
instmods zlib_deflate
instmods zlib_inflate
} }
install() { install() {
inst_rules @udevruledir@/90-zfs.rules inst_rules \
inst_rules @udevruledir@/69-vdev.rules @udevruledir@/90-zfs.rules \
inst_rules @udevruledir@/60-zvol.rules @udevruledir@/69-vdev.rules \
dracut_install hostid @udevruledir@/60-zvol.rules
dracut_install grep
dracut_install @sbindir@/zgenhostid dracut_install \
dracut_install @sbindir@/zfs @sbindir@/zgenhostid \
dracut_install @sbindir@/zpool @sbindir@/zfs \
# Workaround for https://github.com/openzfs/zfs/issues/4749 by @sbindir@/zpool \
# ensuring libgcc_s.so(.1) is included @udevdir@/vdev_id \
if ldd @sbindir@/zpool | grep -qF 'libgcc_s.so'; then @udevdir@/zvol_id \
# Dracut will have already tracked and included it @mounthelperdir@/mount.zfs \
:; hostid \
elif command -v gcc-config >/dev/null 2>&1; then grep \
# On systems with gcc-config (Gentoo, Funtoo, etc.): awk \
# Use the current profile to resolve the appropriate path tr \
s="$(gcc-config -c)" cut \
dracut_install "/usr/lib/gcc/${s%-*}/${s##*-}/libgcc_s.so"* head
elif [ "$(echo /usr/lib/libgcc_s.so*)" != "/usr/lib/libgcc_s.so*" ]; then
# Try a simple path first inst_libdir_file "libgcc_s.so*"
dracut_install /usr/lib/libgcc_s.so*
elif [ "$(echo /lib*/libgcc_s.so*)" != "/lib*/libgcc_s.so*" ]; then
# SUSE
dracut_install /lib*/libgcc_s.so*
else
# Fallback: Guess the path and include all matches
dracut_install /usr/lib*/gcc/**/libgcc_s.so*
fi
# shellcheck disable=SC2050
if [ @LIBFETCH_DYNAMIC@ -gt 0 ]; then
for d in $libdirs; do
[ -e "$d/@LIBFETCH_SONAME@" ] && dracut_install "$d/@LIBFETCH_SONAME@"
done
fi
dracut_install @mounthelperdir@/mount.zfs
dracut_install @udevdir@/vdev_id
dracut_install awk
dracut_install cut
dracut_install tr
dracut_install head
dracut_install @udevdir@/zvol_id
inst_hook cmdline 95 "${moddir}/parse-zfs.sh" inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
if [ -n "$systemdutildir" ] ; then if [ -n "$systemdutildir" ] ; then
inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
@ -103,6 +74,9 @@ install() {
fi fi
if dracut_module_included "systemd"; then if dracut_module_included "systemd"; then
dracut_install systemd-ask-password systemd-tty-ask-password-agent
mkdir -p "${initdir}/$systemdsystemunitdir/zfs-import.target.wants" mkdir -p "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"
for _service in "zfs-import-scan.service" "zfs-import-cache.service" ; do for _service in "zfs-import-scan.service" "zfs-import-cache.service" ; do
dracut_install "@systemdunitdir@/$_service" dracut_install "@systemdunitdir@/$_service"
@ -116,9 +90,6 @@ install() {
ln -s ../zfs-env-bootfs.service "${initdir}/${systemdsystemunitdir}/zfs-import.target.wants"/zfs-env-bootfs.service ln -s ../zfs-env-bootfs.service "${initdir}/${systemdsystemunitdir}/zfs-import.target.wants"/zfs-env-bootfs.service
type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-env-bootfs.service type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-env-bootfs.service
dracut_install systemd-ask-password
dracut_install systemd-tty-ask-password-agent
mkdir -p "${initdir}/$systemdsystemunitdir/initrd.target.wants" mkdir -p "${initdir}/$systemdsystemunitdir/initrd.target.wants"
dracut_install @systemdunitdir@/zfs-import.target dracut_install @systemdunitdir@/zfs-import.target
if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target ]; then if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target ]; then