From f3dacc013d90bd2c0bbfa04f5f9b167b65298440 Mon Sep 17 00:00:00 2001 From: Jo Zzsi Date: Sat, 4 Jan 2025 18:45:32 -0500 Subject: [PATCH] feat(systemd-sysusers): run systemd-sysusers as part of the build process This PR makes the boot process faster and the generated initrd smaller. It also make the code easier to maintain. The primary goal of this PR is refactoring and removing code, this is why it is not marked as perf() in the commit. That said, with this PR systemd-sysusers no longer needs to be copied into the initrd, so that is about 50KB saving both on when initrd gets saved/compressed and when it gets loaded and uncompressed. This PR also make the debugging slightly easier as one can just inspect /etc/passwd with lsinitrd instead of trying to figure out which users are created runtime. --- modules.d/01systemd-sysusers/module-setup.sh | 31 ------------------- .../01systemd-sysusers/sysusers-dracut.conf | 2 -- modules.d/60systemd-sysusers/module-setup.sh | 19 ++++++++++++ 3 files changed, 19 insertions(+), 33 deletions(-) delete mode 100755 modules.d/01systemd-sysusers/module-setup.sh delete mode 100644 modules.d/01systemd-sysusers/sysusers-dracut.conf create mode 100755 modules.d/60systemd-sysusers/module-setup.sh diff --git a/modules.d/01systemd-sysusers/module-setup.sh b/modules.d/01systemd-sysusers/module-setup.sh deleted file mode 100755 index 4c6b39d70..000000000 --- a/modules.d/01systemd-sysusers/module-setup.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# This file is part of dracut. -# SPDX-License-Identifier: GPL-2.0-or-later - -# Prerequisite check(s) for module. -check() { - # If the binary(s) requirements are not fulfilled the module can't be installed. - require_binaries systemd-sysusers || return 1 - - # Return 255 to only include the module, if another module requires it. - return 255 -} - -# Install the required file(s) and directories for the module in the initramfs. -install() { - inst_simple "$moddir/sysusers-dracut.conf" "$systemdsystemunitdir/systemd-sysusers.service.d/sysusers-dracut.conf" - - inst_sysusers basic.conf - - inst_multiple -o \ - "$systemdsystemunitdir"/systemd-sysusers.service \ - "$systemdsystemunitdir"/sysinit.target.wants/systemd-sysusers.service \ - systemd-sysusers - - # Install the hosts local user configurations if enabled. - if [[ $hostonly ]]; then - inst_multiple -H -o \ - "$systemdsystemconfdir"/systemd-sysusers.service \ - "$systemdsystemconfdir/systemd-sysusers.service.d/*.conf" - fi -} diff --git a/modules.d/01systemd-sysusers/sysusers-dracut.conf b/modules.d/01systemd-sysusers/sysusers-dracut.conf deleted file mode 100644 index 9b13364bc..000000000 --- a/modules.d/01systemd-sysusers/sysusers-dracut.conf +++ /dev/null @@ -1,2 +0,0 @@ -[Unit] -ConditionNeedsUpdate= diff --git a/modules.d/60systemd-sysusers/module-setup.sh b/modules.d/60systemd-sysusers/module-setup.sh new file mode 100755 index 000000000..056805538 --- /dev/null +++ b/modules.d/60systemd-sysusers/module-setup.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# This file is part of dracut. +# SPDX-License-Identifier: GPL-2.0-or-later + +# Prerequisite check(s) for module. +check() { + # If the binary(s) requirements are not fulfilled the module can't be installed. + require_binaries systemd-sysusers || return 1 + + # Return 255 to only include the module, if another module requires it. + return 255 +} + +# Install the required file(s) and directories for the module in the initramfs. +install() { + inst_sysusers basic.conf + + systemd-sysusers --root="$initdir" +} -- 2.47.3