PDA

View Full Version : Determine the kernel currently running


egurski
2004-02-26, 09:05 AM CST
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

#!/bin/sh
#
# 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
clear
echo ""
echo $UPTIME|
while read a b c d e f
do
echo "As of $a the system has been up for $c days and $e hours"
done

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:
kernel-2.4.22-1.2166.nptl
kernel-2.4.22-1.2174.nptl


Enjoy

:cool:

Ug
2004-02-26, 10:25 AM CST
Thanks for that.

mhelios
2004-03-14, 09:33 AM CST
I edited your post to add vBulletin tags for readability.

foolish
2004-03-14, 09:58 AM CST
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

theurge
2004-03-16, 04:14 PM CST
egurski,

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:
kernel-2.4.22-1.2115.nptl
kernel-2.4.22-1.2149.nptl
kernel-2.4.22-1.2166.nptl
kernel-2.4.22-1.2174.nptl

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

egurski
2004-03-16, 05:30 PM CST
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...

Ed