19 C
Jaipur
Monday, March 1, 2021

Find When A Specific Linux Kernel Version Is Last Booted

Must read

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

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] %pn"
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.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article