View Full Version : Determine the kernel currently running

26th February 2004, 05:05 PM
There is an easy way, that does not require root authority to determine the currently active kernel. The command to do this is called "uname". You can type "info uname" to see all the options available.

The simplest form is "uname -r" which will give you the currently running kernel.

There are several other ways to do this, but some require root authorization (i.e. cat /etc/lilo.conf or cat /boot/grub/grub.conf). You could also do a "ll /boot/vmlinu*" to see what kernels are in the boot directory (this is useful if you've loaded a new kernel and then discover that you have a lot of kernels - you havent't performed a "rpm -e kernel-2.4.22-1.2122"
I usually run this after a new kernel install so that I never have more than 2 versions of my kernel.

In order to make life even easier, I developed a script that not only tells you which kernel is currently running but how long the system has been running, and the kernels installed on your system. I am including it below

# The purpose of this script is to tell query which kernel
# is currently running on your system...
# Feb 25, 2004 by Ed Gurski (ed@gurski.com)
KERNEL="`uname -r`" # Get the name of the current kernel
UPTIME="`uptime`" # Determine how long the system has been running
RPM="`rpm -qa|grep kernel-2|sort`" # Show all installed kernels on this system
echo ""
echo $UPTIME|
while read a b c d e f
echo "As of $a the system has been up for $c days and $e hours"

echo ""
echo "The running kernel is =====> $KERNEL"
echo ""
echo "The Kernels installed on this system are:"
echo "$RPM"
echo ""

You can call this antything you like, but I woud place it in "/usr/local/bin". You can also change the "grep kernel-2" to "grep kernel" if you have legacy kernels or if you want to see what kernel utilities are also loaded. I am also including a sample output from this command that I call "which_kernel"

As of 11:00:11 the system has been up for 6 days and 22:32, hours

The running kernel is =====> 2.4.22-1.2174.nptl

The Kernels installed on this system are:



26th February 2004, 06:25 PM
Thanks for that.

14th March 2004, 05:33 PM
I edited your post to add vBulletin tags for readability.

14th March 2004, 05:58 PM
Here's another way to determine the running kernel, and the architecture of it. it checks against the rpm-database and as such is more useful when you're installing a rpm that depends on the kernel (like alsa modules or nfts modules)

It might be handy to set this command as an alias in your .bash_profile for easier use.

rpm -q --qf "Kernel: %{version}-%{release}\n Architecture: %{arch}\n" kernel |grep `uname -r`

Will return output like this:

Kernel: 2.4.22-1.2174.nptl Architecture: i686

17th March 2004, 12:14 AM

Just a slight cosmetic bugfix for your useful script (thanks)...

This line:

echo "As of $a the system has been up for $c days and $e hours"

Should be:

echo "As of $a the system has been up for $c days and $e minutes/hours"

Depending on if $e is greater than 59 or not.

Here's the output your script gave me:

As of 17:06:26 the system has been up for 28 days and 57 hours

The running kernel is =====> 2.4.22-1.2166.nptl

The Kernels installed on this system are:

[cboyd@micron bin]$ uptime
17:07:21 up 28 days, 57 min, 2 users, load average: 0.31, 0.16, 0.06

17th March 2004, 01:30 AM
Thanks for the heads-up. I will change the script accordingly. I may also interogate and then parse the uptime command and add that as part of the script. Once completed I will repost...


28th July 2011, 04:15 AM
Slight problem with this script is that it reads static files via commands and if you complied your own Kernel and installed it the "uname" command is useless. it reads the flat file in /etc and that is not updated in a new local compile kernel.

[root@ThePacketSpike scripts]# uname -a
Linux ThePacketSpike #1 SMP Sat May 21 17:26:25 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux

however my kernel is 3.0.0

[root@ThePacketSpike scripts]# ls -al /boot/
total 68951
dr-xr-xr-x. 5 root root 1024 Jul 27 21:37 .
dr-xr-xr-x. 27 root root 4096 Jul 27 21:40 ..
-rw-r--r--. 1 root root 109910 Feb 7 02:21 config-
-rw-r--r--. 1 root root 109918 May 21 13:31 config-
-rw-r--r--. 1 root root 109841 Oct 18 2010 config-
drwxr-xr-x. 3 root root 1024 Oct 22 2010 efi
-rw-r--r--. 1 root root 162660 Mar 29 08:11 elf-memtest86+-4.10
drwxr-xr-x. 2 root root 1024 Jul 27 21:37 grub
-rw-r--r--. 1 root root 12993050 Apr 3 18:14 initramfs-
-rw-r--r--. 1 root root 13081615 Jun 12 14:38 initramfs-
-rw-r--r--. 1 root root 13003582 Apr 3 13:34 initramfs-
-rw-r--r--. 1 root root 5283185 Jul 27 21:37 initramfs-3.0.0.img
-rw-r--r--. 1 root root 565069 Apr 3 18:01 initrd-plymouth.img
drwx------. 2 root root 12288 Apr 3 13:29 lost+found
-rw-r--r--. 1 root root 160984 Mar 29 08:11 memtest86+-4.10
lrwxrwxrwx. 1 root root 22 Jul 27 21:36 System.map -> /boot/System.map-3.0.0
-rw-r--r--. 1 root root 2156574 Feb 7 02:21 System.map-
-rw-r--r--. 1 root root 2157581 May 21 13:31 System.map-
-rw-r--r--. 1 root root 2154853 Oct 18 2010 System.map-
-rw-r--r--. 1 root root 2347833 Jul 27 21:36 System.map-3.0.0
lrwxrwxrwx. 1 root root 19 Jul 27 21:36 vmlinuz -> /boot/vmlinuz-3.0.0
-rwxr-xr-x. 1 root root 3785120 Feb 7 02:21 vmlinuz-
-rwxr-xr-x. 1 root root 3788576 May 21 13:31 vmlinuz-
-rwxr-xr-x. 1 root root 3782016 Oct 18 2010 vmlinuz-
-rw-r--r--. 1 root root 4798912 Jul 27 21:36 vmlinuz-3.0.0

28th July 2011, 04:37 AM
Packetspike is right - I usually roll my own kernel without creating an rpm. The script won't find my kernel at all.

rpm ... will show the kernels installed in the atabase
dir -1 /lib/modules/ | grep "^[0-9]." | sort -n
will show all kernels installed (assuming they use loadable modules).

Note that some Linuces don't use initramfs at all (direct boot).
Most don't store the config or System map in /boot
some don't use vmlinuz (bzimage format).

Scanning through grub.conf (menu.lst) isn't a bad apprach.

Many don't store the kerlen as vmlinuz

8th June 2015, 05:23 PM
Packetspike is right - I usually roll my own kernel without creating an rpm. The script won't find my kernel at all.

Many don't store the kerlen as vmlinuz

old post/thread . . . thanks - works for F22kde

[root@mkna233-244-dhcp /]# uname -r

[root@mkna233-244-dhcp /]# dir -1 /lib/modules/ | grep "^[0-9]." | sort -n