Skip to content

Commit a70822e

Browse files
committed
[ubuntu] Support non-standard kernel version naming
Skip kernel version mangling when linux-headers package exists for the exact running kernel name. This allows custom/distro kernels to work without modification, while preserving the existing resolution logic as a fallback for standard Ubuntu kernels. The existing regex assumes Ubuntu's major.minor.patch-revision-flavor convention and produces incorrect results for kernels using non-standard naming. When the headers package already matches uname -r exactly, no resolution is needed. Applied to all Ubuntu/Debian variants and vgpu-manager Ubuntu variants. Closes: #601
1 parent acf0357 commit a70822e

8 files changed

Lines changed: 80 additions & 8 deletions

File tree

ubuntu16.04/nvidia-driver

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,21 @@ _cleanup_package_cache() {
2626

2727
# Resolve the kernel version to the form major.minor.patch-revision-flavor where flavor defaults to generic.
2828
_resolve_kernel_version() {
29+
echo "Resolving Linux kernel version..."
30+
31+
# If headers for the exact running kernel exist, use KERNEL_VERSION as-is.
32+
# This supports non-standard kernel naming (e.g. custom/distro kernels)
33+
# where the upstream version regex would fail.
34+
if apt-cache show "linux-headers-${KERNEL_VERSION}" > /dev/null 2>&1; then
35+
echo "Proceeding with Linux kernel version ${KERNEL_VERSION}"
36+
return 0
37+
fi
38+
2939
local version=$(apt-cache show "linux-headers-${KERNEL_VERSION}" 2> /dev/null | \
3040
sed -nE 's/^Version:\s+(([0-9]+\.){2}[0-9]+)[-.]([0-9]+).*/\1-\3/p' | head -1)
3141
local kernel_flavor=$(echo ${KERNEL_VERSION} | sed 's/[^a-z]*//')
3242
kernel_flavor="${kernel_flavor//virtual/generic}"
3343

34-
echo "Resolving Linux kernel version..."
3544
if [ -z "${version}" ]; then
3645
echo "Could not resolve Linux kernel version" >&2
3746
return 1

ubuntu18.04/nvidia-driver

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ _cleanup_package_cache() {
2929

3030
# Resolve the kernel version to the form major.minor.patch-revision-flavor where flavor defaults to generic.
3131
_resolve_kernel_version() {
32+
echo "Resolving Linux kernel version..."
33+
34+
# If headers for the exact running kernel exist, use KERNEL_VERSION as-is.
35+
# This supports non-standard kernel naming (e.g. custom/distro kernels)
36+
# where the upstream version regex would fail.
37+
if apt-cache show "linux-headers-${KERNEL_VERSION}" > /dev/null 2>&1; then
38+
echo "Proceeding with Linux kernel version ${KERNEL_VERSION}"
39+
return 0
40+
fi
41+
3242
local version=$(apt-cache show "linux-headers-${KERNEL_VERSION}" 2> /dev/null | \
3343
sed -nE 's/^Version:\s+(([0-9]+\.){2}[0-9]+)[-.]([0-9]+).*/\1-\3/p' | head -1)
3444
local kernel_flavor=$(echo ${KERNEL_VERSION} | sed 's/[^a-z]*//')
3545
kernel_flavor="${kernel_flavor//virtual/generic}"
3646

37-
echo "Resolving Linux kernel version..."
3847
if [ -z "${version}" ]; then
3948
echo "Could not resolve Linux kernel version" >&2
4049
return 1

ubuntu20.04/nvidia-driver

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,21 @@ _update_ca_certificates() {
4646

4747
# Resolve the kernel version to the form major.minor.patch-revision-flavor where flavor defaults to generic.
4848
_resolve_kernel_version() {
49+
echo "Resolving Linux kernel version..."
50+
51+
# If headers for the exact running kernel exist, use KERNEL_VERSION as-is.
52+
# This supports non-standard kernel naming (e.g. custom/distro kernels)
53+
# where the upstream version regex would fail.
54+
if apt-cache show "linux-headers-${KERNEL_VERSION}" > /dev/null 2>&1; then
55+
echo "Proceeding with Linux kernel version ${KERNEL_VERSION}"
56+
return 0
57+
fi
58+
4959
local version=$(apt-cache show "linux-headers-${KERNEL_VERSION}" 2> /dev/null | \
5060
sed -nE 's/^Version:\s+(([0-9]+\.){2}[0-9]+)[-.]([0-9]+).*/\1-\3/p' | head -1)
5161
local kernel_flavor=$(echo ${KERNEL_VERSION} | sed 's/[^a-z]*//')
5262
kernel_flavor="${kernel_flavor//virtual/generic}"
5363

54-
echo "Resolving Linux kernel version..."
5564
if [ -z "${version}" ]; then
5665
echo "Could not resolve Linux kernel version" >&2
5766
return 1

ubuntu22.04/nvidia-driver

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,21 @@ _update_ca_certificates() {
6262

6363
# Resolve the kernel version to the form major.minor.patch-revision-flavor where flavor defaults to generic.
6464
_resolve_kernel_version() {
65+
echo "Resolving Linux kernel version..."
66+
67+
# If headers for the exact running kernel exist, use KERNEL_VERSION as-is.
68+
# This supports non-standard kernel naming (e.g. custom/distro kernels)
69+
# where the upstream version regex would fail.
70+
if apt-cache show "linux-headers-${KERNEL_VERSION}" > /dev/null 2>&1; then
71+
echo "Proceeding with Linux kernel version ${KERNEL_VERSION}"
72+
return 0
73+
fi
74+
6575
local version=$(apt-cache show "linux-headers-${KERNEL_VERSION}" 2> /dev/null | \
6676
sed -nE 's/^Version:\s+(([0-9]+\.){2}[0-9]+)[-.]([0-9]+).*/\1-\3/p' | head -1)
6777
local kernel_flavor=$(echo ${KERNEL_VERSION} | sed 's/[^a-z]*//')
6878
kernel_flavor="${kernel_flavor//virtual/generic}"
6979

70-
echo "Resolving Linux kernel version..."
7180
if [ -z "${version}" ]; then
7281
echo "Could not resolve Linux kernel version" >&2
7382
return 1

ubuntu24.04/nvidia-driver

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,21 @@ _update_ca_certificates() {
7272

7373
# Resolve the kernel version to the form major.minor.patch-revision-flavor where flavor defaults to generic.
7474
_resolve_kernel_version() {
75+
echo "Resolving Linux kernel version..."
76+
77+
# If headers for the exact running kernel exist, use KERNEL_VERSION as-is.
78+
# This supports non-standard kernel naming (e.g. custom/distro kernels)
79+
# where the upstream version regex would fail.
80+
if apt-cache show "linux-headers-${KERNEL_VERSION}" > /dev/null 2>&1; then
81+
echo "Proceeding with Linux kernel version ${KERNEL_VERSION}"
82+
return 0
83+
fi
84+
7585
local version=$(apt-cache show "linux-headers-${KERNEL_VERSION}" 2> /dev/null | \
7686
sed -nE 's/^Version:\s+(([0-9]+\.){2}[0-9]+)[-.]([0-9]+).*/\1-\3/p' | head -1)
7787
local kernel_flavor=$(echo ${KERNEL_VERSION} | sed 's/[^a-z]*//')
7888
kernel_flavor="${kernel_flavor//virtual/generic}"
7989

80-
echo "Resolving Linux kernel version..."
8190
if [ -z "${version}" ]; then
8291
echo "Could not resolve Linux kernel version" >&2
8392
return 1

vgpu-manager/ubuntu20.04/nvidia-driver

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@ _cleanup_package_cache() {
2727

2828
# Resolve the kernel version to the form major.minor.patch-revision-flavor where flavor defaults to generic.
2929
_resolve_kernel_version() {
30+
echo "Resolving Linux kernel version..."
31+
32+
# If headers for the exact running kernel exist, use KERNEL_VERSION as-is.
33+
# This supports non-standard kernel naming (e.g. custom/distro kernels)
34+
# where the upstream version regex would fail.
35+
if apt-cache show "linux-headers-${KERNEL_VERSION}" > /dev/null 2>&1; then
36+
echo "Proceeding with Linux kernel version ${KERNEL_VERSION}"
37+
return 0
38+
fi
39+
3040
local version=$(apt-cache show "linux-headers-${KERNEL_VERSION}" 2> /dev/null | \
3141
sed -nE 's/^Version:\s+(([0-9]+\.){2}[0-9]+)[-.]([0-9]+).*/\1-\3/p' | head -1)
3242
local kernel_flavor=$(echo ${KERNEL_VERSION} | sed 's/[^a-z]*//')
3343
kernel_flavor="${kernel_flavor//virtual/generic}"
3444

35-
echo "Resolving Linux kernel version..."
3645
if [ -z "${version}" ]; then
3746
echo "Could not resolve Linux kernel version" >&2
3847
return 1

vgpu-manager/ubuntu22.04/nvidia-driver

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ _cleanup_package_cache() {
2929

3030
# Resolve the kernel version to the form major.minor.patch-revision-flavor where flavor defaults to generic.
3131
_resolve_kernel_version() {
32+
echo "Resolving Linux kernel version..."
33+
34+
# If headers for the exact running kernel exist, use KERNEL_VERSION as-is.
35+
# This supports non-standard kernel naming (e.g. custom/distro kernels)
36+
# where the upstream version regex would fail.
37+
if apt-cache show "linux-headers-${KERNEL_VERSION}" > /dev/null 2>&1; then
38+
echo "Proceeding with Linux kernel version ${KERNEL_VERSION}"
39+
return 0
40+
fi
41+
3242
local version=$(apt-cache show "linux-headers-${KERNEL_VERSION}" 2> /dev/null | \
3343
sed -nE 's/^Version:\s+(([0-9]+\.){2}[0-9]+)[-.]([0-9]+).*/\1-\3/p' | head -1)
3444
local kernel_flavor=$(echo ${KERNEL_VERSION} | sed 's/[^a-z]*//')
3545
kernel_flavor="${kernel_flavor//virtual/generic}"
3646

37-
echo "Resolving Linux kernel version..."
3847
if [ -z "${version}" ]; then
3948
echo "Could not resolve Linux kernel version" >&2
4049
return 1

vgpu-manager/ubuntu24.04/nvidia-driver

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ _cleanup_package_cache() {
2929

3030
# Resolve the kernel version to the form major.minor.patch-revision-flavor where flavor defaults to generic.
3131
_resolve_kernel_version() {
32+
echo "Resolving Linux kernel version..."
33+
34+
# If headers for the exact running kernel exist, use KERNEL_VERSION as-is.
35+
# This supports non-standard kernel naming (e.g. custom/distro kernels)
36+
# where the upstream version regex would fail.
37+
if apt-cache show "linux-headers-${KERNEL_VERSION}" > /dev/null 2>&1; then
38+
echo "Proceeding with Linux kernel version ${KERNEL_VERSION}"
39+
return 0
40+
fi
41+
3242
local version=$(apt-cache show "linux-headers-${KERNEL_VERSION}" 2> /dev/null | \
3343
sed -nE 's/^Version:\s+(([0-9]+\.){2}[0-9]+)[-.]([0-9]+).*/\1-\3/p' | head -1)
3444
local kernel_flavor=$(echo ${KERNEL_VERSION} | sed 's/[^a-z]*//')
3545
kernel_flavor="${kernel_flavor//virtual/generic}"
3646

37-
echo "Resolving Linux kernel version..."
3847
if [ -z "${version}" ]; then
3948
echo "Could not resolve Linux kernel version" >&2
4049
return 1

0 commit comments

Comments
 (0)