From 80b5d631489c5a61a8060c50fdce62849e81c87d Mon Sep 17 00:00:00 2001 From: Vasiliy Stelmachenok Date: Thu, 2 Jan 2025 22:09:06 +0300 Subject: [PATCH] systemd-boot-manager: Add INITRD_ENTRIES option --- systemd-boot-manager/.SRCINFO | 6 ++--- systemd-boot-manager/PKGBUILD | 7 +++-- systemd-boot-manager/sdboot-manage | 36 +++++++++++++++++-------- systemd-boot-manager/sdboot-manage.conf | 26 +++++++++--------- 4 files changed, 44 insertions(+), 31 deletions(-) diff --git a/systemd-boot-manager/.SRCINFO b/systemd-boot-manager/.SRCINFO index 30ce5fe2..21436d16 100644 --- a/systemd-boot-manager/.SRCINFO +++ b/systemd-boot-manager/.SRCINFO @@ -1,6 +1,6 @@ pkgbase = systemd-boot-manager pkgdesc = A simple tool to maintain systemd-boot & systemd-boot entries for CachyOS - pkgver = 14 + pkgver = 15 pkgrel = 1 url = https://github.com/CachyOS/CachyOS-PKGBUILDS/tree/master/systemd-boot-manager arch = any @@ -15,8 +15,8 @@ pkgbase = systemd-boot-manager source = sdboot-kernel-update.hook source = sdboot-kernel-remove.hook source = sdboot-systemd-update.hook - sha512sums = f5b7caf0e80509489e913854d563531820d164afdfbdf9033d1dbb5f6e77c747a4e4f566c662ded560a4538acc895f20a18c5ce962ad06361123bc07d88b73d6 - sha512sums = fb10ac35973cf38a649d9cda8f2cfa3ec1a8261c7e8f4579188e047a0f2b42c3e512723fe87c2a856a4b469a00fdcae24de4580fad4d65cf0bd41a3ea0fe39b0 + sha512sums = f9371254e129c0027221906beade214c0140f2e7eda750d913d3de27f90fc7c234f54d4e47d6f24d9bf8830ab0fd7d6cf845cbcc0c2777f37ecc8c3a8fab245e + sha512sums = 3c8b079b9cddb2477d5efc2ab90b72705e4f376e7aa1d47e6f23f69c2fe0e73b36d1ea32a08f323ecf5d5e2930943b090fecc3c02e13cce36119082b565e321d sha512sums = 047da99a32b3cf1d9ff52ff347a0a8119f7c02a947d45c913c62d4c960d69aebcc240c1a466780bbcea08903361d8f33096d679e8aaac81d8a1f0c9fdf48f442 sha512sums = a7a6adc9fea62a8884b3bcf78cb9958af361dd5ae21ebef71a095ad96713356cbbf53d141aaccadcb0775c83f3fc8bf7f3a1f48031cf603c2e69f3b38990df30 sha512sums = ebd0c79def6f2d77b9eac63ca41460db5670220dd9ba033bd0c24017abc7f71da2250907f76cac0cc9cf10e219ef518b916aa547fafbba4715be4985cc278c50 diff --git a/systemd-boot-manager/PKGBUILD b/systemd-boot-manager/PKGBUILD index 1c5341d3..1c6bcef8 100644 --- a/systemd-boot-manager/PKGBUILD +++ b/systemd-boot-manager/PKGBUILD @@ -1,5 +1,5 @@ pkgname=systemd-boot-manager -pkgver=14 +pkgver=15 pkgrel=1 pkgdesc='A simple tool to maintain systemd-boot & systemd-boot entries for CachyOS' arch=(any) @@ -20,9 +20,8 @@ source=( sdboot-kernel-remove.hook sdboot-systemd-update.hook ) - -sha512sums=('f5b7caf0e80509489e913854d563531820d164afdfbdf9033d1dbb5f6e77c747a4e4f566c662ded560a4538acc895f20a18c5ce962ad06361123bc07d88b73d6' - 'fb10ac35973cf38a649d9cda8f2cfa3ec1a8261c7e8f4579188e047a0f2b42c3e512723fe87c2a856a4b469a00fdcae24de4580fad4d65cf0bd41a3ea0fe39b0' +sha512sums=('f9371254e129c0027221906beade214c0140f2e7eda750d913d3de27f90fc7c234f54d4e47d6f24d9bf8830ab0fd7d6cf845cbcc0c2777f37ecc8c3a8fab245e' + '3c8b079b9cddb2477d5efc2ab90b72705e4f376e7aa1d47e6f23f69c2fe0e73b36d1ea32a08f323ecf5d5e2930943b090fecc3c02e13cce36119082b565e321d' '047da99a32b3cf1d9ff52ff347a0a8119f7c02a947d45c913c62d4c960d69aebcc240c1a466780bbcea08903361d8f33096d679e8aaac81d8a1f0c9fdf48f442' 'a7a6adc9fea62a8884b3bcf78cb9958af361dd5ae21ebef71a095ad96713356cbbf53d141aaccadcb0775c83f3fc8bf7f3a1f48031cf603c2e69f3b38990df30' 'ebd0c79def6f2d77b9eac63ca41460db5670220dd9ba033bd0c24017abc7f71da2250907f76cac0cc9cf10e219ef518b916aa547fafbba4715be4985cc278c50') diff --git a/systemd-boot-manager/sdboot-manage b/systemd-boot-manager/sdboot-manage index daeb7f8c..6d47ff32 100755 --- a/systemd-boot-manager/sdboot-manage +++ b/systemd-boot-manager/sdboot-manage @@ -62,7 +62,8 @@ export LINUX_OPTIONS \ PRESERVE_FOREIGN \ NO_AUTOGEN \ NO_AUTOUPDATE \ - INITRD_PREFIX=initramfs + INITRD_PREFIX=initramfs \ + INITRD_ENTRIES [ -f "${config}" ] && . "${config}" @@ -101,6 +102,17 @@ setup_sdboot() { generate_entries } +append_initrd_entries() { + local kernel_entry="$1" + local initrd="$2" + + for entry in "${INITRD_ENTRIES[@]}"; do + echo "initrd $entry" >> "$kernel_entry" + done + + echo "initrd ${initrd}" >> "$kernel_entry" +} + generate_entries() { # First, ensure we have a valid config if [ ! -f "${ESP}/loader/loader.conf" ]; then @@ -162,16 +174,17 @@ generate_entries() { if [ "${REMOVE_EXISTING,,}" = "yes" ]; then while read -r entry; do remove_entry "${entry}" - done < <(find "${ESP}/loader/entries" -type f -name "*.conf") + done < <(LC_ALL=C.UTF-8 find "${ESP}/loader/entries" -type f -name "*.conf") fi # create entries for each installed kernel while read -r kernel; do entry="${kernel//vmlinuz-/}" + entry_path="$(get_entry_root "$ESP")${entry}" initramfs="${kernel//vmlinuz/${INITRD_PREFIX}}" # first validate we don't already have an entry for this kernel - [[ "${OVERWRITE_EXISTING,,}" != "yes" && -f $(get_entry_root "$ESP")${entry}.conf ]] && continue + [[ "${OVERWRITE_EXISTING,,}" != "yes" && -f "${entry_path}.conf" ]] && continue # generate entry title (WIP) title="$(echo -e "$entry" | sed -e 's/-/ /g' -e 's/\b\(.\)/\u\1/g')" @@ -181,21 +194,22 @@ generate_entries() { # get the kernel location so the initrd can be written to the same location as the kernel [[ $(dirname "$kernel") == "/" ]] && kernelpath="" || kernelpath="$(dirname "$kernel")" - cat <"$(get_entry_root "$ESP")${entry}.conf" + cat <"${entry_path}.conf" title ${title} -linux ${kernel} -initrd ${kernelpath}${initramfs}.img options ${sdoptions} ${LINUX_OPTIONS} +linux ${kernel} EOF + append_initrd_entries "${entry_path}.conf" "${kernelpath}${initramfs}.img" + if [ "${DISABLE_FALLBACK}" != "yes" ]; then - cat <"$(get_entry_root "$ESP")${entry}-fallback.conf" + cat <"${entry_path}-fallback.conf" title ${title} (Fallback) -linux ${kernel} -initrd ${kernelpath}${initramfs}-fallback.img options ${sdoptions} ${LINUX_FALLBACK_OPTIONS} +linux ${kernel} EOF + append_initrd_entries "$entry_path-fallback.conf" "${kernelpath}${initramfs}-fallback.img" fi - done < <(find "${ESP}" -maxdepth 1 -type f -name "${KERNEL_PATTERN}" -printf "/%P\n") + done < <(LC_ALL=C.UTF-8 find "${ESP}" -maxdepth 1 -type f -name "${KERNEL_PATTERN}" -printf "/%P\n") if [ -z "$(ls -A "${ESP}/loader/entries")" ]; then die "Error: There are no boot loader entries after entry generation" @@ -207,7 +221,7 @@ remove_orphan_entries() { [[ "${REMOVE_OBSOLETE,,}" != "yes" ]] && return # find and remove all the entries with unmatched kernels - for kernel in $(comm -13 <(find "${ESP}" -maxdepth 2 -type f -name "${KERNEL_PATTERN}" -printf "/%P\n" \ + for kernel in $(comm -13 <(LC_ALL=C.UTF-8 find "${ESP}" -maxdepth 2 -type f -name "${KERNEL_PATTERN}" -printf "/%P\n" \ | uniq | sort) <(cat "${ESP}"/loader/entries/* | grep -i "^linux" | awk '{print $2}' \ | uniq | sort)); do while read -r entry; do diff --git a/systemd-boot-manager/sdboot-manage.conf b/systemd-boot-manager/sdboot-manage.conf index ddd0905d..6e740e73 100644 --- a/systemd-boot-manager/sdboot-manage.conf +++ b/systemd-boot-manager/sdboot-manage.conf @@ -1,36 +1,36 @@ -# config file for sdboot-manage +# Config file for sdboot-manage -# kernel options to be appended to the "options" line +# Kernel options to be appended to the "options" line LINUX_OPTIONS="zswap.enabled=0 nowatchdog splash" #LINUX_FALLBACK_OPTIONS="" -# when DISABLE_FALLBACK is set to "yes", it will stop creating fallback entries for each kernel. +# When DISABLE_FALLBACK is set to "yes", it will stop creating fallback entries for each kernel. #DISABLE_FALLBACK="no" -# initrd override, seperated by space, if not set the script will attempt to add them automatically -#INITRD_ENTRIES="intel-ucode.cpio i915-firmware.cpio.xz" - # Use this pattern to match kernels which should be considered native OS kernels #KERNEL_PATTERN="vmlinuz-" -# setting REMOVE_EXISTING to "yes" will remove all your existing systemd-boot entries before building new entries +# Setting REMOVE_EXISTING to "yes" will remove all your existing systemd-boot entries before building new entries REMOVE_EXISTING="no" -# unless OVERWRITE_EXISTING is set to "yes" existing entries for currently installed kernels will not be touched +# Unless OVERWRITE_EXISTING is set to "yes" existing entries for currently installed kernels will not be touched # this setting has no meaning if REMOVE_EXISTING is set to "yes" OVERWRITE_EXISTING="yes" -# when REMOVE_OBSOLETE is set to "yes" entries for kernels no longer available on the system will be removed +# When REMOVE_OBSOLETE is set to "yes" entries for kernels no longer available on the system will be removed REMOVE_OBSOLETE="yes" -# if PRESERVE_FOREIGN is set to "yes", do not delete entries starting with $ENTRY_ROOT +# If PRESERVE_FOREIGN is set to "yes", do not delete entries starting with $ENTRY_ROOT #PRESERVE_FOREIGN="no" -# setting NO_AUTOUPDATE to "yes" will stop the updates to systemd-boot when systemd is updated - not recommended unless you are seperately updating systemd-boot +# Setting NO_AUTOUPDATE to "yes" will stop the updates to systemd-boot when systemd is updated - not recommended unless you are seperately updating systemd-boot #NO_AUTOUPDATE="no" -# setting NO_AUTOGEN to "yes" will stop the automatic creation of entries when kernels are installed or updated +# Setting NO_AUTOGEN to "yes" will stop the automatic creation of entries when kernels are installed or updated #NO_AUTOGEN="no" -# use this to change the default initramfs prefix (e.g. when using booster) +# Use this to change the default initramfs prefix (e.g. when using booster) #INITRD_PREFIX="initramfs" + +# Additional entities to initrd can be added here, such as microcode if your initramfs does not include it. +#INITRD_ENTRIES=()