Skip to content

Conversation

@bketelsen
Copy link
Contributor

When updating the bootloader configuration, the code was using filepath.Glob() to find kernels on the boot partition. This returned files in alphabetical order, which caused the wrong kernel to be selected when multiple versions existed.

For example, with kernels 6.18.2-surface-1 and 6.18.3-surface-2 on the boot partition, the bootloader would point to 6.18.2 (alphabetically first) even though the updated root filesystem contained 6.18.3. This caused boot failures because the kernel modules didn't match the booted kernel.

The fix adds getUpdatedRootKernelVersion() which reads the kernel version from the updated root's /usr/lib/modules directory, ensuring the bootloader always references the kernel that matches the newly extracted container image.

Includes regression tests that verify:

  • Kernel version is detected from updated root, not boot partition
  • Newest kernel is selected when multiple versions exist
  • Various kernel version formats are handled correctly

When updating the bootloader configuration, the code was using
filepath.Glob() to find kernels on the boot partition. This returned
files in alphabetical order, which caused the wrong kernel to be
selected when multiple versions existed.

For example, with kernels 6.18.2-surface-1 and 6.18.3-surface-2 on the
boot partition, the bootloader would point to 6.18.2 (alphabetically
first) even though the updated root filesystem contained 6.18.3. This
caused boot failures because the kernel modules didn't match the
booted kernel.

The fix adds getUpdatedRootKernelVersion() which reads the kernel
version from the updated root's /usr/lib/modules directory, ensuring
the bootloader always references the kernel that matches the newly
extracted container image.

Includes regression tests that verify:
- Kernel version is detected from updated root, not boot partition
- Newest kernel is selected when multiple versions exist
- Various kernel version formats are handled correctly
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug in the update mechanism where the bootloader would select an incorrect kernel version when multiple kernels existed on the boot partition. The issue stemmed from using filepath.Glob() which returns files in alphabetical order, potentially selecting an older kernel (e.g., 6.18.2) instead of the newer one from the updated root (e.g., 6.18.3), causing boot failures due to module mismatches.

Key Changes:

  • Introduced getUpdatedRootKernelVersion() to detect kernel version from the updated root's /usr/lib/modules directory
  • Updated both GRUB2 and systemd-boot update paths to use the new detection method
  • Added comprehensive regression tests covering various kernel version formats and edge cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/update.go Adds getUpdatedRootKernelVersion() function and updates updateGRUBBootloader() and updateSystemdBootBootloader() to use it instead of filepath.Glob() for kernel selection
pkg/update_test.go Adds comprehensive tests for getUpdatedRootKernelVersion() including edge cases (multiple kernels, missing vmlinuz, various version formats) and regression test verifying the fix

When updating the bootloader configuration, the code was using
filepath.Glob() to find kernels on the boot partition. This returned
files in alphabetical order, which caused the wrong kernel to be
selected when multiple versions existed.

For example, with kernels 6.18.2-surface-1 and 6.18.3-surface-2 on the
boot partition, the bootloader would point to 6.18.2 (alphabetically
first) even though the updated root filesystem contained 6.18.3. This
caused boot failures because the kernel modules didn't match the
booted kernel.

The fix adds getUpdatedRootKernelVersion() which reads the kernel
version from the updated root's /usr/lib/modules directory, ensuring
the bootloader always references the kernel that matches the newly
extracted container image.

Includes regression tests that verify:
- Kernel version is detected from updated root, not boot partition
- Newest kernel is selected when multiple versions exist
- Various kernel version formats are handled correctly
Signed-off-by: Brian Ketelsen <bketelsen@gmail.com>
@bketelsen bketelsen merged commit 89ef66d into main Jan 7, 2026
9 checks passed
@bketelsen bketelsen deleted the updatekernel branch January 7, 2026 15:49
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.

3 participants