Skip to content

Conversation

@RuTHlessBEat200
Copy link

Fix: Resolve kernel version detection for Debian/Ubuntu meta-packages

Problem

On Debian-based virtualized systems, the agent incorrectly reported kernel version mismatches, causing false-positive reboot requirements. The issue occurred because meta-packages like linux-image-virtual, linux-image-generic, etc., were not being resolved to their actual kernel versions.

Changes

1. Updated getLatestKernelFromBoot()

  • Removed filter that excluded "generic" kernels
  • Now only skips "recovery" kernels
  • Properly detects kernels like 6.8.0-90-generic from /boot directory

2. Rewrote getLatestKernelFromDpkg()

  • Multi-stage detection: first scans for actual kernel packages with full version numbers
  • Identifies meta-packages (virtual, generic, lowlatency, server, cloud, kvm)
  • Falls back to dependency resolution if only meta-packages are found
  • Properly sorts all found kernels to return the latest version

3. Added resolveMetaPackage()

  • New function to resolve meta-packages to actual kernel versions
  • Uses dpkg-query to read package dependencies
  • Parses dependency strings to find correct kernel packages
  • Filters out nested meta-packages

Testing

Tested on Raspberry Pi 5 (Debian 13)

patchmon-agent diagnostics 2>&1 | grep -A 5 -i "reboot"
  time="2025-12-24T03:25:31" level=info msg="Reboot status check completed" installed_kernel=6.12.47+rpt-rpi-v8 needs_reboot=false reason= running_kernel=6.12.47+rpt-rpi-v8

Correctly detects matching kernels with custom suffixes

Tested on Proxmox VE

patchmon-agent diagnostics 2>&1 | grep -A 5 -i "reboot"
  time="2025-12-24T03:25:15" level=info msg="Reboot status check completed" installed_kernel=6.17.4-1-pve needs_reboot=true reason="Reboot flag file exists (/var/run/reboot-required) | Running kernel: 6.17.2-2-pve, Installed kernel: 6.17.4-1-pve" running_kernel=6.17.2-2-pve

Correctly detects actual kernel updates requiring reboot

Tested on Ubuntu 24.04 (Virtualized)

Before fix:

patchmon-agent diagnostics 2>&1 | grep -A 5 -i "reboot"
  time="2025-12-24T03:25:20" level=info msg="Reboot status check completed" installed_kernel=virtual needs_reboot=true reason="Kernel version mismatch | Running kernel: 6.8.0-90-generic, Installed kernel: virtual" running_kernel=6.8.0-90-generic

False positive - meta-package not resolved

After fix:

patchmon-agent diagnostics 2>&1 | grep -A 5 -i "reboot"
  time="2025-12-24T03:19:55" level=info msg="Reboot status check completed" installed_kernel=6.8.0-90-generic needs_reboot=false reason= running_kernel=6.8.0-90-generic

Correctly resolves linux-image-virtual to 6.8.0-90-generic

Impact

  • Eliminates false-positive reboot requirements on virtualized Debian/Ubuntu systems
  • Should maintain backward compatibility with RHEL/Fedora systems
  • Should work across all Linux distributions with proper fallback mechanisms
  • No breaking changes to existing functionality

Notes (important)

Testing required before merge
This fix has been tested on Debian-based systems (Debian 13, Ubuntu 24.04, Raspberry Pi OS). I only had VMs/physical devices with these distributions in my home lab. Before merging, it should be tested on all OS distributions (all those officially supported by the project).

@9technologygroup
Copy link
Collaborator

Hi :)

I will be spending some time testing this throughout the week.

Many thanks for the PR and the work you've put into it for sure.

Thanks
iby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants