You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Debian系统如何查看最新安装内核?grub-mkconfig识别逻辑是什么?

Hey there! Let's tackle your questions one by one—this is a common scenario when managing kernels on Debian, so I've got you covered.

Viewing the Most Recently Installed Kernel

General & Debian-Specific Commands

First, for Debian-based systems (including Debian itself), there are a few straightforward ways to list your installed kernels and find the newest one:

  • List installed kernel packages sorted by installation time:

    dpkg-query -W -f='${Installed-Time}\t${Package}\n' linux-image-* | sort -n
    

    The last line here will show the most recently installed kernel package, since we're sorting by the timestamp of when it was installed.

  • Quickly get the latest kernel file (by version):
    The actual kernel binaries live in /boot, so you can list and sort them by version number directly:

    ls /boot/vmlinuz-* | sort -V | tail -n 1
    

    The -V flag tells sort to use natural version number sorting, so the newest version will be the last entry.

  • Using APT to list installed kernels:

    apt list --installed | grep linux-image
    

    You can pipe this to sort -V too if you want to order them by version:

    apt list --installed | grep linux-image | sort -V
    

How grub-mkconfig Identifies the Latest Kernel

You're right that grub-mkconfig (and its Debian wrapper update-grub) does a great job of picking up the newest kernel. Here's how it works:

It relies on the scripts in /etc/grub.d/, specifically the 10_linux script. This script:

  1. Scans the /boot directory for files matching vmlinuz-* (kernel images) and initrd.img-* (initial ramdisks).
  2. Extracts the version string from each kernel filename.
  3. Compares these version numbers using a version-aware sorting algorithm (similar to sort -V).
  4. Orders the kernel entries in the generated grub.cfg from newest to oldest, and sets the newest one as the default boot option (unless you've modified the default behavior in /etc/default/grub).

Essentially, it's just automating the same manual check you'd do by looking at /boot files, but in a scripted, reliable way.

Commands to Parse Kernel Version Information

If you need to extract or parse kernel version details specifically:

  • Get the currently running kernel version:

    uname -r
    

    This gives you the version string of the kernel your system is actively using right now.

  • Parse the version from a specific kernel file:
    For a kernel binary like /boot/vmlinuz-6.1.0-12-amd64, you can use:

    strings /boot/vmlinuz-6.1.0-12-amd64 | grep -E 'Linux version' | head -n 1 | awk '{print $3}'
    

    Or a simpler approach with file:

    file /boot/vmlinuz-6.1.0-12-amd64 | grep -oP 'version \K[^ ]+'
    
  • Check details of an installed kernel package:
    To get metadata (like installation time, version, dependencies) for a specific kernel package:

    dpkg --status linux-image-$(uname -r)
    

    Replace $(uname -r) with the version string you're interested in if you want to check a different kernel.

内容的提问来源于stack exchange,提问作者Ben

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:15:56