🐧 How to determine the last boot date of a specific Linux kernel version


You should have installed or updated many new kernels on your Linux machine during this time. If you have multiple Linux kernels installed on your system, how do you know when a particular version of the Linux kernel was last booted? Here’s what we’ll find out now. This guide explains how to check when the Linux kernel was last used or booted.

Before we know when a particular Linux kernel boots, let’s check the list of all installed kernels on our Linux system.

By default, all installed Linux kernels and their associated files are stored in the / boot directory. Just check the contents of this directory with the find command to see the list of installed kernels:

$ find /boot/vmli*

Sample output from my Centos

/boot/vmlinuz-0-rescue-40c2a456125e4a498ba218f0beaf3670
/boot/vmlinuz-3.10.0-862.11.6.el7.x86_64
/boot/vmlinuz-3.10.0-862.14.4.el7.x86_64
/boot/vmlinuz-3.10.0-862.el7.x86_64
/boot/vmlinuz-3.10.0-957.1.3.el7.x86_64

🐧 How to determine the last boot date of a specific Linux kernel version

We can easily determine the date of the last kernel boot by looking at the time of the last access to the corresponding kernel image file.

Linux has a stat command line utility that helps us find such details.

The stat command is used to display information about a file and filesystem such as size, permissions, creation and access dates, etc.

To find out when a specific version of the Linux kernel (for example, vmlinuz-5.4.0-64-generic) was last booted, run:

$ stat -c %x /boot/vmlinuz-5.4.0-64-generic 

Where:

  • -c flag is used to specify FORMAT
  • % x is used to display the last access time in human readable format.

Output example:

2021-01-23 13:15:00.000000000 +0530

According to the above output, Linux kernel version 5.4.0-64 was last booted on Jan 23, 2021. You can also use the% X flag in the above command if you want to display Unix epoch time in the output.

$ stat -c %X /boot/vmlinuz-5.4.0-64-generic 
1611387900

Another way to find out the access time to the Linux kernel is to use the find command as shown below:

$ find /boot/vmlinuz-5.4.0-64-generic -printf "%[email protected] %pn"
1611387900.0000000000 /boot/vmlinuz-5.4.0-64-generic

On modern Linux distributions using the Systemd Service Manager, we can use the journalctl command to display the last time the Linux kernel was used or loaded.

To view the most recent download, run this command:

$ journalctl --boot | grep "Linux version"

or

$ journalctl -b | grep "Linux version"

Output example:

Feb 08 11:28:01 itsecforu kernel: Linux version 5.4.0-65-generic ([email protected]) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 (Ubuntu 5.4.0-65.73-generic 5.4.78)

To view all available previous downloads, run:

$ journalctl --list-boots

You will see a long list of previous downloads, as shown in the output below:

[...] 
-10 b4634cec90874b47a3aa4342b14c49bd Tue 2021-02-02 17:14:46 IST—Tue 2021-02-02 22:19:11 IST
 -9 3b98c3f4a27f4444bf5b08243f4e27a6 Wed 2021-02-03 10:48:10 IST—Wed 2021-02-03 22:20:14 IST
 -8 5e75c35655f24015af92063fe6be1bd7 Thu 2021-02-04 10:44:31 IST—Thu 2021-02-04 11:21:08 IST
 -7 1ac699796f6d4fe288e231720027bb3a Thu 2021-02-04 11:21:29 IST—Thu 2021-02-04 22:26:52 IST
 -6 d3a9d739e07546a6836d9f84a0bbb6c3 Fri 2021-02-05 12:24:21 IST—Fri 2021-02-05 22:15:59 IST
 -5 ba8b180cade44f2bad11710b72b69475 Sat 2021-02-06 10:46:20 IST—Sat 2021-02-06 10:48:42 IST
 -4 58f942c57e044e63934e682ba99e66b9 Sat 2021-02-06 10:49:10 IST—Sat 2021-02-06 11:40:51 IST
 -3 364162c62fbd4d3ca25c2d37b65168cf Sat 2021-02-06 11:45:21 IST—Sat 2021-02-06 15:22:31 IST
 -2 97492fb7ad0e4d3d9f818c428f8e5cbe Sat 2021-02-06 15:24:24 IST—Sat 2021-02-06 22:47:39 IST
 -1 67a81252453045eca42daa9417f48eed Sun 2021-02-07 10:49:30 IST—Mon 2021-02-08 01:00:45 IST
  0 3850ccfefeb9428689c521a206b1df81 Mon 2021-02-08 11:28:01 IST—Mon 2021-02-08 18:46:14 IST

You can now check each boot descriptor to see when a particular kernel version was last used. Output example:

$ journalctl --boot=ba8b180cade44f2bad11710b72b69475 | grep "Linux version"
Feb 06 10:46:20 itsecforu kernel: Linux version 5.4.0-65-generic ([email protected]) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 (Ubuntu 5.4.0-65.73-generic 5.4.78)
Sidebar