Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] [RFC] use alternatives to manage initramfs regeneration
@ 2022-09-14 16:00 ahesford
  2022-09-14 16:25 ` CameronNemo
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: ahesford @ 2022-09-14 16:00 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1469 bytes --]

There is a new pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages initramfs
https://github.com/void-linux/void-packages/pull/39284

[RFC] use alternatives to manage initramfs regeneration
Yes, I know that XBPS alternatives have some problems, but this seems to be the most sensible approach on balance. Rather than dealing with a bunch of potentially competing initramfs hooks, we can let all packages install custom hooks in `/usr/libexec` and use the alternatives system to symlink the preferred hooks in `/etc/kernel.d`. At that point, we can use the generic alternative script in the XBPS regenerator trigger and avoid the need for a conf file, although it falls back to legacy behavior if the alternative isn't set.

Another option I considered, but decided against, was creating a centralized `initramfs-kernel-hooks` package that installs a common hook and reads the `/etc/default/initramfs-regenerate` file used in the existing XBPS trigger to determine what to execute. All initramfs generators (currently only dracut and mkinitcpio) would have to depend on the common package. This has the drawback that all of the generation knowledge must be centralized instead of located in the package that adds the functionality.

This is not really tested at this point, but I want to get some early comments.

A patch file from https://github.com/void-linux/void-packages/pull/39284.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-initramfs-39284.patch --]
[-- Type: text/x-diff, Size: 7723 bytes --]

From 53b1783b6bb94f0cce75662349fc09ef4de85256 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:30:28 -0400
Subject: [PATCH 1/3] dracut: use alternatives for kernel hooks

---
 srcpkgs/dracut/template | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/dracut/template b/srcpkgs/dracut/template
index 22ffa7a82c4e..e435de954ccd 100644
--- a/srcpkgs/dracut/template
+++ b/srcpkgs/dracut/template
@@ -1,7 +1,7 @@
 # Template file for 'dracut'
 pkgname=dracut
 version=053
-revision=3
+revision=4
 build_style=configure
 configure_args="--prefix=/usr --sysconfdir=/etc"
 conf_files="/etc/dracut.conf"
@@ -14,6 +14,10 @@ license="GPL-2.0-or-later, LGPL-2.0-or-later"
 homepage="http://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html"
 distfiles="${KERNEL_SITE}/utils/boot/dracut/dracut-${version}.tar.xz"
 checksum=d5a1b47cdb07919d8225d5b5f538e6ae604988f3df0afbde99a8dc775277b726
+alternatives="
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/dracut/kernel-hook-postrm:/etc/kernel.d/post-remove/20-initramfs
+"
 subpackages="dracut-network"
 # Checks require distfiles come from a git repository
 make_check=no
@@ -34,8 +38,8 @@ esac
 
 post_install() {
 	# kernel hooks.
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-dracut
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-dracut
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/dracut
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/dracut
 
 	# We don't need the systemd stuff.
 	rm -rf ${DESTDIR}/usr/lib/dracut/modules.d/*systemd*
@@ -58,10 +62,14 @@ dracut-uefi_package() {
 	depends="binutils gummiboot-efistub ${sourcepkg}>=${version}_${revision}"
 	short_desc+=" - UEFI bundle hook"
 	conf_files="/etc/default/dracut-uefi-hook"
+	alternatives="
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-install:/etc/kernel.d/post-install/20-initramfs
+	 initramfs-hooks:/usr/libexec/dracut/kernel-uefi-post-remove:/etc/kernel.d/post-remove/20-initramfs
+	"
 
 	pkg_install() {
 		vinstall ${FILESDIR}/dracut-uefi-hook.confd 644 etc/default dracut-uefi-hook
-		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 etc/kernel.d/post-install 20-dracut-uefi
-		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 etc/kernel.d/post-remove 20-dracut-uefi
+		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 usr/libexec/dracut
+		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 usr/libexec/dracut
 	}
 }

From cd3e3ad88106f5af4d8cb8027e68a92e8bc44767 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:33:39 -0400
Subject: [PATCH 2/3] mkinitcpio: use alternatives for kernel hooks

---
 srcpkgs/mkinitcpio/files/kernel-hook-postinst |  1 -
 srcpkgs/mkinitcpio/files/kernel-hook-postrm   |  1 -
 srcpkgs/mkinitcpio/template                   | 10 +++++++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postinst b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
index 08bf4c0c9514..e051aefea703 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postinst
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postinst
@@ -13,4 +13,3 @@ fi
 
 umask 0077
 usr/bin/mkinitcpio -g boot/initramfs-${VERSION}.img -k ${VERSION}
-exit $?
diff --git a/srcpkgs/mkinitcpio/files/kernel-hook-postrm b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
index 028fd097b87a..2db7c51954fa 100644
--- a/srcpkgs/mkinitcpio/files/kernel-hook-postrm
+++ b/srcpkgs/mkinitcpio/files/kernel-hook-postrm
@@ -8,4 +8,3 @@ PKGNAME="$1"
 VERSION="$2"
 
 rm -f boot/initramfs-${VERSION}.img
-exit $?
diff --git a/srcpkgs/mkinitcpio/template b/srcpkgs/mkinitcpio/template
index ab00be349a27..b8c700480948 100644
--- a/srcpkgs/mkinitcpio/template
+++ b/srcpkgs/mkinitcpio/template
@@ -1,7 +1,7 @@
 # Template file for 'mkinitcpio'
 pkgname=mkinitcpio
 version=31
-revision=2
+revision=3
 build_style=gnu-makefile
 hostmakedepends="asciidoc"
 depends="busybox-static bsdtar bash"
@@ -13,6 +13,10 @@ homepage="https://git.archlinux.org/mkinitcpio.git"
 distfiles="https://sources.archlinux.org/other/${pkgname}/${pkgname}-${version}.tar.gz"
 checksum=8f2811250b852ab78375bf90e1a7430daa132e57e128b0f6eaadddd9b27bbc63
 conf_files="/etc/mkinitcpio.conf"
+alternatives="
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postinst:/etc/kernel.d/post-install/20-initramfs
+ initramfs-hooks:/usr/libexec/mkinitcpio/kernel-hook-postrm:/etc/kernel.d/post-install/20-initramfs
+"
 replaces="mkinitcpio-udev>=0"
 
 pre_check() {
@@ -38,8 +42,8 @@ post_install() {
 
 	ln -s /usr/bin/busybox.static $DESTDIR/usr/lib/initcpio/busybox
 
-	vinstall ${FILESDIR}/kernel-hook-postinst 755 etc/kernel.d/post-install 20-mkinitcpio
-	vinstall ${FILESDIR}/kernel-hook-postrm 755 etc/kernel.d/post-remove 20-mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/mkinitcpio
+	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/mkinitcpio
 }
 
 mkinitcpio-lvm2_package() {

From a3d20fe2f3abc8052d10709188627e45f2a9ab2e Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 14 Sep 2022 11:51:09 -0400
Subject: [PATCH 3/3] xbps-triggers: use alternatives for kernel hooks

---
 .../xbps-triggers/files/initramfs-regenerate  | 45 +++++++------------
 srcpkgs/xbps-triggers/template                |  2 +-
 2 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/srcpkgs/xbps-triggers/files/initramfs-regenerate b/srcpkgs/xbps-triggers/files/initramfs-regenerate
index 780c3580829f..0ae61958c2b7 100755
--- a/srcpkgs/xbps-triggers/files/initramfs-regenerate
+++ b/srcpkgs/xbps-triggers/files/initramfs-regenerate
@@ -37,36 +37,21 @@ case "$ACTION" in
 		;;
 esac
 
-# Read the configuration, if it exists
-[ -f etc/default/initramfs-regenerate ] && . etc/default/initramfs-regenerate
+# Prefer the new alternatives-based initramfs hooks
+HOOK="etc/kernel.d/post-install/20-initramfs"
+if [ ! -x "${HOOK}" ]; then
+	# Otherwise, use legacy trigger behavior to find a preferred hook
+	[ -f etc/default/initramfs-regenerate ] && etc/default/initramfs-regenerate
+	HOOK="etc/kernel.d/post-install/20-${INITRAMFS_GENERATOR:-dracut}"
+	[ -x "${HOOK}" ] || exit 0
+fi
 
-# dracut explicitly sets umask 0077, other generators may not
-umask 0077
-
-case "${INITRAMFS_GENERATOR:-dracut}" in
-	dracut)
-		if command -v dracut >/dev/null 2>&1; then
-			echo "Regenerating initramfs with dracut"
-			dracut -f -q --regenerate-all
-		fi
-		;;
-	mkinitcpio)
-		if command -v mkinitcpio >dev/null 2>&1; then
-			echo "Regenerating initramfs with mkinitcpio"
-			# Regenerate images for every kernel version with modules
-			for kdir in usr/lib/modules/*; do
-				[ -d "${kdir}/kernel" ] || continue
-				kver="${kdir##*/}"
-				mkinitcpio -g "boot/initramfs-${kver}.img" -k "${kver}"
-			done
-		fi
-		;;
-	none)
-		;;
-	*)
-		echo "unrecognized INITRAMFS_GENERATOR for initramfs-regenerate hook"
-		exit 1
-		;;
-esac
+echo "Regenerating initramfs images using kernel hook ${HOOK##*/}"
 
+# Regenerate images for every kernel version with modules
+for kdir in usr/lib/modules/*; do
+	[ -d "${kdir}/kernel" ] || continue
+	kver="${kdir##*/}"
+	"${HOOK}" "${PKGNAME}" "${kver}"
+done
 exit 0
diff --git a/srcpkgs/xbps-triggers/template b/srcpkgs/xbps-triggers/template
index f0249f6f9964..aa62e0902528 100644
--- a/srcpkgs/xbps-triggers/template
+++ b/srcpkgs/xbps-triggers/template
@@ -1,6 +1,6 @@
 # Template file for 'xbps-triggers'
 pkgname=xbps-triggers
-version=0.123
+version=0.124
 revision=1
 bootstrap=yes
 short_desc="XBPS triggers for Void Linux"

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-09-26 12:17 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14 16:00 [PR PATCH] [RFC] use alternatives to manage initramfs regeneration ahesford
2022-09-14 16:25 ` CameronNemo
2022-09-14 16:38 ` [PR REVIEW] " CameronNemo
2022-09-14 17:05 ` ahesford
2022-09-14 17:07 ` ahesford
2022-09-14 19:15 ` [PR REVIEW] " dmarto
2022-09-15  1:29 ` [PR PATCH] [Updated] " ahesford
2022-09-15  1:29 ` [PR REVIEW] " ahesford
2022-09-15 10:26 ` classabbyamp
2022-09-18 17:55 ` [PR PATCH] [Updated] " ahesford
2022-09-18 18:39 ` ahesford
2022-09-18 18:49 ` ahesford
2022-09-18 18:57 ` ahesford
2022-09-18 18:58 ` ahesford
2022-09-19  8:19 ` thypon
2022-09-19  9:23 ` classabbyamp
2022-09-19 11:04 ` ahesford
2022-09-19 20:33 ` classabbyamp
2022-09-26 12:17 ` [PR PATCH] [Merged]: " ahesford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).