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.
Table of Contents
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
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
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 "%A@ %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 (buildd@lcy01-amd64-018) (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 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
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 (buildd@lcy01-amd64-018) (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)
Hope this helps.
10 comments
Hi,
Thanks a lot
another way, we can check by “uname” command
As far as I know,
uname
command can only the display the access tie of current Kernel only. Correct me if I am wrong.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)
I don’t know why you get this result. These steps gives me correct results for me.
Try this one, it’s simple and straight. Sometimes the “stat” command is not available:
date -r /boot/vmlinuz* +%Y-%m-%d
It doesn’t give me correct results. I checked it with my current Kernel today and it displayed way older date.
If you have atime turned off does it still update?
I don’t think so. Check it yourself and let us know.
‘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.
Thanks for the clarification. I didn’t know it.