Home Linux Find When A Specific Linux Kernel Version Is Last Booted
Find When A Specific Linux Kernel Version Is Last Booted

Find When A Specific Linux Kernel Version Is Last Booted

By sk
1324 Views

You should have installed or upgraded to many new Kernel versions over the time in your Linux machine. If you have multiple Linux Kernels installed on your system, how would you find when a specific Linux Kernel version is last booted? That's what we are going to find out now. This guide explains how to check when a Linux kernel last used or booted on.

List all installed Linux Kernels

Before we find out when a specific Linux Kernel is booted on, let us check the list of all installed Kernels in our Linux system.

By default, all installed Linux Kernels and their associated files are stored under /boot directory. Simply check the contents of this directory using find command to view the list of installed Kernels:

$ find /boot/vmli*

Sample output from my Ubuntu 20.04 LTS desktop:

/boot/vmlinuz
/boot/vmlinuz-5.4.0-64-generic
/boot/vmlinuz-5.4.0-65-generic
/boot/vmlinuz.old
Check installed Kernels in Linux
Check installed Kernels in Linux

As you see in the above output, there are two Linux Kernels versions (5.4.0-64 and 5.4.0-65) are installed. By default, the latest Kernel will boot, so the last access time of the 5.4.0-65 is today. Now let us check when the older Kernel version i.e. 5.4.0-64 is last booted.

Find when a specific Linux Kernel version is last booted

We can easily find when a Kernel is last booted by viewing the last access time of the relevant Kernel image file. In Linux, there is a command line utility named stat that helps us to find such detail.

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

To find out when a specific Linux Kernel version (E.g. vmlinuz-5.4.0-64-generic) is last booted, run:

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

Here,

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

Sample output:

2021-01-23 13:15:00.000000000 +0530
Find when a specific Linux Kernel version is last booted using stat command
Find when a specific Linux Kernel version is last booted using stat command

As per the above output, the Linux Kernel version 5.4.0-64 was last booted on January 23, 2021.

You can also use capital %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

The another way to find the access time of a Linux Kernel is to use find command like below:

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

Display when a specific Linux Kernel version is last booted using journalctl command

In modern Linux distributions that uses Systemd service manager, we can use journalctl command to display when a Linux kernel is last used or booted on.

To view the most recent boot, run this command:

$ journalctl --boot | grep "Linux version"

Or,

$ journalctl -b | grep "Linux version"

Sample output:

Feb 08 11:28:01 ostechnix 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)
View most recent boot in Linux with journalctl command
View most recent boot in Linux with journalctl command

To list all available previous boots, run:

$ journalctl --list-boots

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

[...] 
-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
List all available previous boots in Linux using journalctl command
List all available previous boots in Linux using journalctl command

You can now check each boot descriptor to find when a specific Kernel version is last used.

Example:

$ journalctl --boot=ba8b180cade44f2bad11710b72b69475 | grep "Linux version"

Sample output:

Feb 06 10:46:20 ostechnix 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)
Display when a specific Linux Kernel version is last booted using journalctl command
Display when a specific Linux Kernel version is last booted using journalctl command

Hope this helps.

You May Also Like

10 comments

Jalal February 9, 2021 - 10:18 am

Hi,

Thanks a lot

another way, we can check by “uname” command

Reply
sk February 9, 2021 - 11:25 am

As far as I know, uname command can only the display the access tie of current Kernel only. Correct me if I am wrong.

Reply
linux admin February 9, 2021 - 11:46 am

That is a complete nonsense…
Take a lookat this:

date ;uname -sr ; uptime; stat -c ‘%n %x’ vmli*
Tue Feb 9 07:11:26 CET 2021
Linux 4.15.0-46-generic
07:11:26 up 9 days, 10:55, 1 user, load average: 0.07, 0.05, 0.01
vmlinuz-4.15.0-13-generic 2020-07-31 09:14:39.000000000 +0200
vmlinuz-4.15.0-46-generic 2020-07-31 09:14:45.000000000 +0200
vmlinuz-4.4.0-200-generic 2021-01-15 17:24:09.000000000 +0100
vmlinuz-4.4.0-201-generic 2021-01-30 02:17:47.000000000 +0100

I’m using kernel 4.15. (ubuntu 18.04)

Reply
sk February 9, 2021 - 1:01 pm

I don’t know why you get this result. These steps gives me correct results for me.

Reply
M0nst3r February 10, 2021 - 8:04 pm

Try this one, it’s simple and straight. Sometimes the “stat” command is not available:

date -r /boot/vmlinuz* +%Y-%m-%d

Reply
sk February 10, 2021 - 8:14 pm

It doesn’t give me correct results. I checked it with my current Kernel today and it displayed way older date.

Reply
Hugh February 11, 2021 - 12:00 am

If you have atime turned off does it still update?

Reply
sk February 11, 2021 - 11:44 am

I don’t think so. Check it yourself and let us know.

Reply
Rob February 12, 2021 - 8:59 pm

‘stat -c %x’ will return the atime for the file in question. The fact that this is the same for the time that a kernel booted is merely coincidental, and therefore unreliable. Also given the rise in popularity of solid state storage in the past few years, a lot of mainstream distros will mount filesystems with the noatime flag, to prevent timestamp updates every time a file is accessed, thereby preventing unnecessary writes and reducing the life of the device. In such scenarios, running a stat -c %x on the kernel will not accurately return the boot time.

Reply
sk February 12, 2021 - 9:56 pm

Thanks for the clarification. I didn’t know it.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More