Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] dkms: run depmod if necessary in kernel post-install hook
@ 2020-07-04 20:51 ahesford
  2020-07-05  1:19 ` [PR PATCH] [Updated] " ahesford
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ahesford @ 2020-07-04 20:51 UTC (permalink / raw)
  To: ml

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

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

https://github.com/ahesford/void-packages dkms
https://github.com/void-linux/void-packages/pull/23392

dkms: run depmod if necessary in kernel post-install hook
Normally, `dkms install` will run depmod with each installed module to update module dependency lists. When force-reinstalling kernel packages, `dkms install` will not run because modules are already marked installed, but the kernel package will overwrite `modules.dep` and `modules.dep.bin` with packaged versions that do not include any modules installed by dkms. The kernel post-install hook now tracks whether depmod should be run and will do so if necessary.

To demonstrate the original problem:

1. Install `zfs` and enable the dracut zfs module with `add_dracutmodules+=" zfs "` in `dracut.conf` or a `.conf` file in `/etc/dracut.conf.d`.
2. Rerun `dracut`, e.g., with `xbps-reconfigure -f linuxX.Y` for an appropriate kernel package.
3. Confirm that `zfs.ko.gz` is in the newly generated initramfs.
4. Force-reinstall the kernel package: `xbps-install -f linuxX.Y`.
5. Confirm that `zfs.ko.gz` is *missing* from the newly generated initramfs.

With the changes in the hook, the force-installation of `linuxX.Y should display `Generating kernel module dependency lists... done.` after "building" all DKMS modules (note: the modules were already built for the reinstalled kernel, so the `dkms build` run by the hook is basically a no-op). The resulting initramfs will contain `zfs.ko.gz` as expected.

Also, I propagated some return codes from `dkms` through the hook, which I believe was the original intention. (Before the fix, `exit $?` after an `echo` would generally always exit 0 because `echo` is unlikely to fail.)

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

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

From ffb8b4fb170686dc5027498e48c21fe9ac57a769 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Sat, 4 Jul 2020 16:33:31 -0400
Subject: [PATCH] dkms: run depmod if necessary in kernel post-install hook

Normally, `dkms install` will run depmod with each installed module to
update module dependency lists. When force-reinstalling kernel packages,
`dkms install` will not run because modules are already marked
installed, but the kernel package will overwrite `modules.dep` and
`modules.dep.bin` with packaged versions that do not include any modules
installed by dkms. The kernel post-install hook now tracks whether
depmod should be run and will do so if necessary.
---
 srcpkgs/dkms/files/kernel.d/dkms.postinst | 24 ++++++++++++++++++++---
 srcpkgs/dkms/template                     |  2 +-
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/srcpkgs/dkms/files/kernel.d/dkms.postinst b/srcpkgs/dkms/files/kernel.d/dkms.postinst
index bfeaf34fccf..1d05ec88e08 100644
--- a/srcpkgs/dkms/files/kernel.d/dkms.postinst
+++ b/srcpkgs/dkms/files/kernel.d/dkms.postinst
@@ -45,6 +45,9 @@ while [ $# -ne 0 ]; do
 	module="$1"
 	modulever="$2"
 
+	# If adding a module, depmod is necessary unless dkms runs it
+	do_depmod="yes"
+
 	status=$(dkms status -m ${module} -v ${modulever} -k ${VERSION})
 	if [ $(echo "$status"|grep -c ": built") -eq 0 ]; then
 		# Check if the module is still there.
@@ -65,7 +68,7 @@ while [ $# -ne 0 ]; do
 			echo "done."
 		else
 			echo "FAILED!"
-			exit $?
+			exit $rval
 		fi
 		status=$(dkms status -m ${module} -v ${modulever} -k ${VERSION})
 	fi
@@ -75,14 +78,29 @@ while [ $# -ne 0 ]; do
 	   [ $(echo "$status"|grep -c ": installed") -eq 0 ]; then
 		echo -n "Installing DKMS module: ${module}-${modulever}... "
 	        dkms install -q -m ${module} -v ${modulever} -k ${VERSION} -a ${ARCH}
-		if [ $? -eq 0 ]; then
+		rval=$?
+		if [ $rval -eq 0 ]; then
 			echo "done."
+			# dkms runs depmod as part of the installation
+			unset do_depmod
 		else
 			echo "FAILED!"
-			exit $?
+			exit $rval
 		fi
 	fi
 	shift; shift
 done
 
+if [ -n "$do_depmod" ]; then
+	echo -n "Generating kernel module dependency lists... "
+	depmod -a ${VERSION}
+	rval=$?
+	if [ $rval -eq 0 ]; then
+		echo "done."
+	else
+		echo "FAILED!"
+		exit $rval
+	fi
+fi
+
 exit 0
diff --git a/srcpkgs/dkms/template b/srcpkgs/dkms/template
index 521dfde1114..32345b9b421 100644
--- a/srcpkgs/dkms/template
+++ b/srcpkgs/dkms/template
@@ -2,7 +2,7 @@
 pkgname=dkms
 reverts="2.8.2_1"
 version=2.8.1
-revision=3
+revision=4
 conf_files="/etc/dkms/framework.conf"
 depends="bash kmod gcc make coreutils linux-headers"
 short_desc="Dynamic Kernel Modules System"

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

end of thread, other threads:[~2020-07-11  2:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-04 20:51 [PR PATCH] dkms: run depmod if necessary in kernel post-install hook ahesford
2020-07-05  1:19 ` [PR PATCH] [Updated] " ahesford
2020-07-05  1:20 ` ahesford
2020-07-11  1:34 ` [PR PATCH] [Updated] dkms: improvements to post-install hook: run depmod if necessary and better handle DKMS build/install failures ahesford
2020-07-11  1:44 ` [PR REVIEW] " ericonr
2020-07-11  1:50 ` [PR PATCH] [Updated] " ahesford
2020-07-11  2:00 ` ahesford
2020-07-11  2:01 ` [PR REVIEW] " ahesford
2020-07-11  2:18 ` [PR PATCH] [Updated] " ahesford
2020-07-11  2:21 ` [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).