From e5ffe7eca6da75d5544f5fecf2a0a0f6f0356cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20F=C3=B6rster?= Date: Thu, 20 Jul 2023 14:42:00 +0200 Subject: [PATCH] [sys-kernel/dracut] sync --- ...cut-059-r2.ebuild => dracut-059-r3.ebuild} | 14 +- sys-kernel/dracut/dracut-9999.ebuild | 10 +- sys-kernel/dracut/files/059-gawk.patch | 35 +++++ .../dracut/files/059-uki-systemd-254.patch | 134 ++++++++++++++++++ 4 files changed, 190 insertions(+), 3 deletions(-) rename sys-kernel/dracut/{dracut-059-r2.ebuild => dracut-059-r3.ebuild} (90%) create mode 100644 sys-kernel/dracut/files/059-gawk.patch create mode 100644 sys-kernel/dracut/files/059-uki-systemd-254.patch diff --git a/sys-kernel/dracut/dracut-059-r2.ebuild b/sys-kernel/dracut/dracut-059-r3.ebuild similarity index 90% rename from sys-kernel/dracut/dracut-059-r2.ebuild rename to sys-kernel/dracut/dracut-059-r3.ebuild index d296809..7e531f0 100644 --- a/sys-kernel/dracut/dracut-059-r2.ebuild +++ b/sys-kernel/dracut/dracut-059-r3.ebuild @@ -66,6 +66,8 @@ PATCHES=( "${FILESDIR}"/gentoo-ldconfig-paths-r1.patch "${FILESDIR}"/gentoo-network-r1.patch "${FILESDIR}"/059-uefi-split-usr.patch + "${FILESDIR}"/059-uki-systemd-254.patch + "${FILESDIR}"/059-gawk.patch ) src_configure() { @@ -158,18 +160,26 @@ pkg_postinst() { optfeature \ "Allows use of dash instead of default bash (on your own risk)" \ app-shells/dash + optfeature \ + "Allows use of busybox instead of default bash (on your own risk)" \ + sys-apps/busybox optfeature "Support iSCSI" sys-block/open-iscsi optfeature "Support Logical Volume Manager" sys-fs/lvm2[lvm] optfeature "Support MD devices, also known as software RAID devices" \ - sys-fs/mdadm + sys-fs/mdadm sys-fs/dmraid optfeature "Support Device Mapper multipathing" sys-fs/multipath-tools optfeature "Plymouth boot splash" '>=sys-boot/plymouth-0.8.5-r5' optfeature "Support network block devices" sys-block/nbd optfeature "Support NFS" net-fs/nfs-utils net-nds/rpcbind optfeature \ "Install ssh and scp along with config files and specified keys" \ - net-misc/openssh + virtual/openssh optfeature "Enable logging with rsyslog" app-admin/rsyslog + optfeature "Support Squashfs" sys-fs/squashfs-tools + optfeature "Support TPM 2.0 TSS" app-crypt/tpm2-tools + optfeature "Support Bluetooth (experimental)" net-wireless/bluez + optfeature "Support BIOS-given device names" sys-apps/biosdevname + optfeature "Support network NVMe" sys-apps/nvme-cli optfeature \ "Enable rngd service to help generating entropy early during boot" \ sys-apps/rng-tools diff --git a/sys-kernel/dracut/dracut-9999.ebuild b/sys-kernel/dracut/dracut-9999.ebuild index 4b0f1c8..d2c35dc 100644 --- a/sys-kernel/dracut/dracut-9999.ebuild +++ b/sys-kernel/dracut/dracut-9999.ebuild @@ -157,10 +157,13 @@ pkg_postinst() { optfeature \ "Allows use of dash instead of default bash (on your own risk)" \ app-shells/dash + optfeature \ + "Allows use of busybox instead of default bash (on your own risk)" \ + sys-apps/busybox optfeature "Support iSCSI" sys-block/open-iscsi optfeature "Support Logical Volume Manager" sys-fs/lvm2[lvm] optfeature "Support MD devices, also known as software RAID devices" \ - sys-fs/mdadm + sys-fs/mdadm sys-fs/dmraid optfeature "Support Device Mapper multipathing" sys-fs/multipath-tools optfeature "Plymouth boot splash" '>=sys-boot/plymouth-0.8.5-r5' optfeature "Support network block devices" sys-block/nbd @@ -169,6 +172,11 @@ pkg_postinst() { "Install ssh and scp along with config files and specified keys" \ virtual/openssh optfeature "Enable logging with rsyslog" app-admin/rsyslog + optfeature "Support Squashfs" sys-fs/squashfs-tools + optfeature "Support TPM 2.0 TSS" app-crypt/tpm2-tools + optfeature "Support Bluetooth (experimental)" net-wireless/bluez + optfeature "Support BIOS-given device names" sys-apps/biosdevname + optfeature "Support network NVMe" sys-apps/nvme-cli app-misc/jq optfeature \ "Enable rngd service to help generating entropy early during boot" \ sys-apps/rng-tools diff --git a/sys-kernel/dracut/files/059-gawk.patch b/sys-kernel/dracut/files/059-gawk.patch new file mode 100644 index 0000000..5f1da79 --- /dev/null +++ b/sys-kernel/dracut/files/059-gawk.patch @@ -0,0 +1,35 @@ +https://github.com/dracutdevs/dracut/pull/2436 + +From 77214c229dadd1441f0d6243221ceed0708cbfcf Mon Sep 17 00:00:00 2001 +From: Sam James +Date: Thu, 20 Jul 2023 04:36:01 +0100 +Subject: [PATCH] fix(dracut.sh): use gawk for strtonum + +strtonum is a gawkism and is not available in all awks, e.g. mawk. Use gawk +to avoid failure. + +Fixes: f32e95bcadbc5158843530407adc1e7b700561b1 +Signed-off-by: Sam James +--- a/dracut-functions.sh ++++ b/dracut-functions.sh +@@ -1047,7 +1047,7 @@ pe_file_format() { + if [[ $# -eq 1 ]]; then + local magic + magic=$(objdump -p "$1" \ +- | awk '{if ($1 == "Magic"){print strtonum("0x"$2)}}') ++ | gawk '{if ($1 == "Magic"){print strtonum("0x"$2)}}') + magic=$(printf "0x%x" "$magic") + # 0x10b (PE32), 0x20b (PE32+) + [[ $magic == 0x20b || $magic == 0x10b ]] && return 0 +--- a/dracut.sh ++++ b/dracut.sh +@@ -2467,7 +2467,7 @@ if [[ $uefi == yes ]]; then + fi + fi + +- offs=$(objdump -h "$uefi_stub" 2> /dev/null | awk 'NF==7 {size=strtonum("0x"$3);\ ++ offs=$(objdump -h "$uefi_stub" 2> /dev/null | gawk 'NF==7 {size=strtonum("0x"$3);\ + offset=strtonum("0x"$4)} END {print size + offset}') + if [[ $offs -eq 0 ]]; then + dfatal "Failed to get the size of $uefi_stub to create UEFI image file" + diff --git a/sys-kernel/dracut/files/059-uki-systemd-254.patch b/sys-kernel/dracut/files/059-uki-systemd-254.patch new file mode 100644 index 0000000..e8b5248 --- /dev/null +++ b/sys-kernel/dracut/files/059-uki-systemd-254.patch @@ -0,0 +1,134 @@ +https://github.com/dracutdevs/dracut/issues/2431 +https://github.com/dracutdevs/dracut/commit/f32e95bcadbc5158843530407adc1e7b700561b1 + +From f32e95bcadbc5158843530407adc1e7b700561b1 Mon Sep 17 00:00:00 2001 +From: Valentin Lefebvre +Date: Mon, 13 Mar 2023 12:06:13 +0100 +Subject: [PATCH] fix(dracut.sh): use dynamically uefi's sections offset + +* Uefi section are creating by `objcopy` with hardcoded sections +offset. This commit allow to have the correct offset between +each part of the efi file, needed to create an UKI. Offsets +are simply calculated so no sections overlap, as recommended +in https://wiki.archlinux.org/title/Unified_kernel_image#Manually +Moreover, efi stub file's header is parsed to apply the correct +offsets according the section alignment factor. +* Remove EFI_SECTION_VMA_INITRD, no need anymore as initrd +section offset dynamically calculated + +Fixes dracutdevs#2275 + +Signed-off-by: Valentin Lefebvre +--- a/dracut-functions.sh ++++ b/dracut-functions.sh +@@ -1023,3 +1023,26 @@ get_dev_module() { + fi + echo "$dev_drivers" + } ++ ++# Check if file is in PE format ++pe_file_format() { ++ if [[ $# -eq 1 ]]; then ++ local magic ++ magic=$(objdump -p "$1" \ ++ | awk '{if ($1 == "Magic"){print strtonum("0x"$2)}}') ++ magic=$(printf "0x%x" "$magic") ++ # 0x10b (PE32), 0x20b (PE32+) ++ [[ $magic == 0x20b || $magic == 0x10b ]] && return 0 ++ fi ++ return 1 ++} ++ ++# Get the sectionAlignment data from the PE header ++pe_get_section_align() { ++ local align_hex ++ [[ $# -ne "1" ]] && return 1 ++ [[ $(pe_file_format "$1") -eq 1 ]] && return 1 ++ align_hex=$(objdump -p "$1" \ ++ | awk '{if ($1 == "SectionAlignment"){print $2}}') ++ echo "$((16#$align_hex))" ++} +--- a/dracut.sh ++++ b/dracut.sh +@@ -1506,7 +1506,6 @@ if [[ ! $print_cmdline ]]; then + exit 1 + fi + unset EFI_MACHINE_TYPE_NAME +- EFI_SECTION_VMA_INITRD=0x3000000 + case "${DRACUT_ARCH:-$(uname -m)}" in + x86_64) + EFI_MACHINE_TYPE_NAME=x64 +@@ -1516,8 +1515,6 @@ if [[ ! $print_cmdline ]]; then + ;; + aarch64) + EFI_MACHINE_TYPE_NAME=aa64 +- # aarch64 kernels are uncompressed and thus larger, so we need a bigger gap between vma sections +- EFI_SECTION_VMA_INITRD=0x4000000 + ;; + *) + dfatal "Architecture '${DRACUT_ARCH:-$(uname -m)}' not supported to create a UEFI executable" +@@ -2467,29 +2464,57 @@ if [[ $uefi == yes ]]; then + fi + fi + ++ offs=$(objdump -h "$uefi_stub" 2> /dev/null | awk 'NF==7 {size=strtonum("0x"$3);\ ++ offset=strtonum("0x"$4)} END {print size + offset}') ++ if [[ $offs -eq 0 ]]; then ++ dfatal "Failed to get the size of $uefi_stub to create UEFI image file" ++ exit 1 ++ fi ++ align=$(pe_get_section_align "$uefi_stub") ++ if [[ $? -eq 1 ]]; then ++ dfatal "Failed to get the sectionAlignment of the stub PE header to create the UEFI image file" ++ exit 1 ++ fi ++ offs=$((offs + "$align" - offs % "$align")) ++ [[ -s $dracutsysrootdir/usr/lib/os-release ]] && uefi_osrelease="$dracutsysrootdir/usr/lib/os-release" ++ [[ -s $dracutsysrootdir/etc/os-release ]] && uefi_osrelease="$dracutsysrootdir/etc/os-release" ++ [[ -s $uefi_osrelease ]] \ ++ && uefi_osrelease_offs=${offs} \ ++ && offs=$((offs + $(stat -Lc%s "$uefi_osrelease"))) \ ++ && offs=$((offs + "$align" - offs % "$align")) ++ + if [[ $kernel_cmdline ]] || [[ $hostonly_cmdline == yes && -e "${uefi_outdir}/cmdline.txt" ]]; then + echo -ne "\x00" >> "$uefi_outdir/cmdline.txt" + dinfo "Using UEFI kernel cmdline:" + dinfo "$(tr -d '\000' < "$uefi_outdir/cmdline.txt")" + uefi_cmdline="${uefi_outdir}/cmdline.txt" ++ uefi_cmdline_offs=${offs} ++ offs=$((offs + $(stat -Lc%s "$uefi_cmdline"))) ++ offs=$((offs + "$align" - offs % "$align")) + else + unset uefi_cmdline + fi + +- [[ -s $dracutsysrootdir/usr/lib/os-release ]] && uefi_osrelease="$dracutsysrootdir/usr/lib/os-release" +- [[ -s $dracutsysrootdir/etc/os-release ]] && uefi_osrelease="$dracutsysrootdir/etc/os-release" + if [[ -s ${dracutsysrootdir}${uefi_splash_image} ]]; then + uefi_splash_image="${dracutsysrootdir}${uefi_splash_image}" ++ uefi_splash_offs=${offs} ++ offs=$((offs + $(stat -Lc%s "$uefi_splash_image"))) ++ offs=$((offs + "$align" - offs % "$align")) + else + unset uefi_splash_image + fi + ++ uefi_linux_offs="${offs}" ++ offs=$((offs + $(stat -Lc%s "$kernel_image"))) ++ offs=$((offs + "$align" - offs % "$align")) ++ uefi_initrd_offs="${offs}" ++ + if objcopy \ +- ${uefi_osrelease:+--add-section .osrel="$uefi_osrelease" --change-section-vma .osrel=0x20000} \ +- ${uefi_cmdline:+--add-section .cmdline="$uefi_cmdline" --change-section-vma .cmdline=0x30000} \ +- ${uefi_splash_image:+--add-section .splash="$uefi_splash_image" --change-section-vma .splash=0x40000} \ +- --add-section .linux="$kernel_image" --change-section-vma .linux=0x2000000 \ +- --add-section .initrd="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd="${EFI_SECTION_VMA_INITRD}" \ ++ ${uefi_osrelease:+--add-section .osrel="$uefi_osrelease" --change-section-vma .osrel=$(printf 0x%x "$uefi_osrelease_offs")} \ ++ ${uefi_cmdline:+--add-section .cmdline="$uefi_cmdline" --change-section-vma .cmdline=$(printf 0x%x "$uefi_cmdline_offs")} \ ++ ${uefi_splash_image:+--add-section .splash="$uefi_splash_image" --change-section-vma .splash=$(printf 0x%x "$uefi_splash_offs")} \ ++ --add-section .linux="$kernel_image" --change-section-vma .linux="$(printf 0x%x "$uefi_linux_offs")" \ ++ --add-section .initrd="${DRACUT_TMPDIR}/initramfs.img" --change-section-vma .initrd="$(printf 0x%x "$uefi_initrd_offs")" \ + "$uefi_stub" "${uefi_outdir}/linux.efi"; then + if [[ -n ${uefi_secureboot_key} && -n ${uefi_secureboot_cert} ]]; then + if sbsign \