[SRU][canonical-kernel-snaps][PATCH 1/1] nvidia_hooks: replace uname -r calls

Aaron Jauregui aaron.jauregui at canonical.com
Thu Jun 5 02:55:42 UTC 2025


BugLink: https://bugs.launchpad.net/bugs/2111937

The previous assumption that the currently running kernel corresponds to
the parent kernel snap of the component being installed/refreshed does
not necessarily hold true. Modules were found to be installed in the
previous kernel snap's path in some cases.  Replacing uname -r with the
parent kernel snap's /modules/<kernel_version> fixes this issue.

Signed-off-by: Aaron Jauregui <aaron.jauregui at canonical.com>
---
 hooks/module/install.module            | 7 +++++--
 hooks/module/post-refresh.module       | 7 +++++--
 hooks/module/remove.module             | 6 ++++--
 hooks/nvidia-ko/install.nvidia-ko      | 9 ++++++---
 hooks/nvidia-ko/post-refresh.nvidia-ko | 9 ++++++---
 hooks/nvidia-ko/remove.nvidia-ko       | 5 ++++-
 6 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/hooks/module/install.module b/hooks/module/install.module
index d61ae8b..f1e6490 100755
--- a/hooks/module/install.module
+++ b/hooks/module/install.module
@@ -3,13 +3,16 @@
 
 set -eux
 
+# Get kernel version, parent snap may not be currently running kernel
+kernel_ver=$(basename "$SNAP"/modules/*)
+
 name=$(echo "$SNAP_COMPONENT_NAME" | cut -d+ -f2)
 
 # nouveau needs a special case to override nvidia modules
 if [ "$name" = "nouveau-ko" ] ; then
-	dest="$SNAP_DATA/modules/$(uname -r)/graphics"
+	dest="$SNAP_DATA/modules/$kernel_ver/graphics"
 else
-	dest="$SNAP_DATA/modules/$(uname -r)/$name"
+	dest="$SNAP_DATA/modules/$kernel_ver/$name"
 fi
 
 
diff --git a/hooks/module/post-refresh.module b/hooks/module/post-refresh.module
index d61ae8b..f1e6490 100755
--- a/hooks/module/post-refresh.module
+++ b/hooks/module/post-refresh.module
@@ -3,13 +3,16 @@
 
 set -eux
 
+# Get kernel version, parent snap may not be currently running kernel
+kernel_ver=$(basename "$SNAP"/modules/*)
+
 name=$(echo "$SNAP_COMPONENT_NAME" | cut -d+ -f2)
 
 # nouveau needs a special case to override nvidia modules
 if [ "$name" = "nouveau-ko" ] ; then
-	dest="$SNAP_DATA/modules/$(uname -r)/graphics"
+	dest="$SNAP_DATA/modules/$kernel_ver/graphics"
 else
-	dest="$SNAP_DATA/modules/$(uname -r)/$name"
+	dest="$SNAP_DATA/modules/$kernel_ver/$name"
 fi
 
 
diff --git a/hooks/module/remove.module b/hooks/module/remove.module
index bada5fe..c8a65e1 100755
--- a/hooks/module/remove.module
+++ b/hooks/module/remove.module
@@ -3,11 +3,13 @@
 
 set -eux
 
+# Get kernel version, parent snap may not be currently running kernel
+kernel_ver=$(basename "$SNAP"/modules/*)
 name=$(echo "$SNAP_COMPONENT_NAME" | cut -d+ -f2)
 if [ "$name" = "nouveau-ko" ] ; then
-	dest="$SNAP_DATA/modules/$(uname -r)/graphics"
+	dest="$SNAP_DATA/modules/$kernel_ver/graphics"
 else
-	dest="$SNAP_DATA/modules/$(uname -r)/$name"
+	dest="$SNAP_DATA/modules/$kernel_ver/$name"
 fi
 
 rm -rf "$dest"
diff --git a/hooks/nvidia-ko/install.nvidia-ko b/hooks/nvidia-ko/install.nvidia-ko
index e11d532..04352e3 100755
--- a/hooks/nvidia-ko/install.nvidia-ko
+++ b/hooks/nvidia-ko/install.nvidia-ko
@@ -3,6 +3,9 @@
 
 set -eux
 
+# Get kernel version, parent snap may not be currently running kernel
+kernel_ver=$(basename "$SNAP"/modules/*)
+
 # First setup the kernel modules
 tmp_dir="/tmp/nvidia-ko"
 rm -rf "$tmp_dir"
@@ -17,9 +20,9 @@ sed -i "s|make|$SNAP_COMPONENT/bin/make|" BUILD
 LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP_COMPONENT/lib/$(uname -m)-linux-gnu" sh BUILD
 
 # Clean up directory before copying modules
-rm -rf "$SNAP_DATA/modules/$(uname -r)/graphics"
-mkdir -p "$SNAP_DATA/modules/$(uname -r)/graphics"
+rm -rf "$SNAP_DATA/modules/$kernel_ver/graphics"
+mkdir -p "$SNAP_DATA/modules/$kernel_ver/graphics"
 
-mv ../*.ko "$SNAP_DATA/modules/$(uname -r)/graphics/"
+mv ../*.ko "$SNAP_DATA/modules/$kernel_ver/graphics/"
 
 rm -rf "$tmp_dir"
diff --git a/hooks/nvidia-ko/post-refresh.nvidia-ko b/hooks/nvidia-ko/post-refresh.nvidia-ko
index c4b5285..6d99aec 100755
--- a/hooks/nvidia-ko/post-refresh.nvidia-ko
+++ b/hooks/nvidia-ko/post-refresh.nvidia-ko
@@ -3,6 +3,9 @@
 
 set -eux
 
+# Get kernel version, parent snap may not be currently running kernel
+kernel_ver=$(basename "$SNAP"/modules/*)
+
 # First setup the kernel modules
 tmp_dir="/tmp/nvidia-ko"
 rm -rf $tmp_dir
@@ -17,9 +20,9 @@ sed -i "s|make|$SNAP_COMPONENT/bin/make|" BUILD
 LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP_COMPONENT/lib/$(uname -m)-linux-gnu sh BUILD
 
 # Clean up directory before copying modules
-rm -rf "$SNAP_DATA/modules/$(uname -r)/graphics"
-mkdir -p "$SNAP_DATA/modules/$(uname -r)/graphics"
+rm -rf "$SNAP_DATA/modules/$kernel_ver/graphics"
+mkdir -p "$SNAP_DATA/modules/$kernel_ver/graphics"
 
-mv ../*.ko "$SNAP_DATA/modules/$(uname -r)/graphics/"
+mv ../*.ko "$SNAP_DATA/modules/$kernel_ver/graphics/"
 
 rm -rf $tmp_dir
diff --git a/hooks/nvidia-ko/remove.nvidia-ko b/hooks/nvidia-ko/remove.nvidia-ko
index 5e2831d..b1aab1f 100755
--- a/hooks/nvidia-ko/remove.nvidia-ko
+++ b/hooks/nvidia-ko/remove.nvidia-ko
@@ -3,4 +3,7 @@
 
 set -eux
 
-rm -rf "$SNAP_DATA/modules/$(uname -r)/graphics"
+# Get kernel version, parent snap may not be currently running kernel
+kernel_ver=$(basename "$SNAP"/modules/*)
+
+rm -rf "$SNAP_DATA/modules/$kernel_ver/graphics"
-- 
2.43.0




More information about the kernel-team mailing list