Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora Resources > Guides & Solutions (No Questions)
FedoraForum Search

Forgot Password? Join Us!

Guides & Solutions (No Questions) Post your guides here (No links to Blogs accepted). You can also append your comments/questions to a guide, but don't start a new thread to ask a question. Use another forum for that.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 26th February 2004, 04:05 PM
egurski's Avatar
egurski Offline
Registered User
 
Join Date: Feb 2004
Location: Shallotte, NC
Posts: 169
Lightbulb Determine the kernel currently running

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
Code:
#!/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"

Code:
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

Reply With Quote
  #2  
Old 26th February 2004, 05:25 PM
Ug's Avatar
Ug Offline
Retired Community Manager
 
Join Date: Feb 2004
Posts: 2,999
Thanks for that.
__________________
gareth@fedoraforum.org
Registered Linux User # 301555
garethrussell.net


Please adhere to the FedoraForum Guidelines.
Reply With Quote
  #3  
Old 14th March 2004, 04:33 PM
mhelios Offline
Retired Community Manager
 
Join Date: Feb 2004
Location: Queensland, AU
Posts: 736
I edited your post to add vBulletin tags for readability.
__________________
mhelios@fedoraforum.org
Registered Linux User # 348963
GnuPG KeyID: 0xCE9F8922
Reply With Quote
  #4  
Old 14th March 2004, 04:58 PM
foolish's Avatar
foolish Offline
Retired Community Manager
 
Join Date: Feb 2004
Location: Aalesund, Norway
Age: 26
Posts: 1,888
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.

Code:
rpm -q --qf "Kernel: %{version}-%{release}\n Architecture: %{arch}\n" kernel |grep `uname -r`
Will return output like this:

Code:
Kernel:  2.4.22-1.2174.nptl Architecture: i686
__________________
Sindre Pedersen Bjørdal || http://www.fedorasolved.org || Hardware Profile
- Please adhere to the FedoraForum Guidelines.
Reply With Quote
  #5  
Old 16th March 2004, 11:14 PM
theurge's Avatar
theurge Offline
Registered User
 
Join Date: Mar 2004
Location: Kansas City, USA
Age: 36
Posts: 46
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
Reply With Quote
  #6  
Old 17th March 2004, 12:30 AM
egurski's Avatar
egurski Offline
Registered User
 
Join Date: Feb 2004
Location: Shallotte, NC
Posts: 169
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
Reply With Quote
  #7  
Old 28th July 2011, 04:15 AM
packetspike Offline
Registered User
 
Join Date: Apr 2011
Posts: 1
windows_7firefox
Re: Determine the kernel currently running

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 2.6.35.13-92.fc14.x86_64 #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-2.6.35.11-83.fc14.x86_64
-rw-r--r--. 1 root root 109918 May 21 13:31 config-2.6.35.13-92.fc14.x86_64
-rw-r--r--. 1 root root 109841 Oct 18 2010 config-2.6.35.6-45.fc14.x86_64
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-2.6.35.11-83.fc14.x86_64.img
-rw-r--r--. 1 root root 13081615 Jun 12 14:38 initramfs-2.6.35.13-92.fc14.x86_64.img
-rw-r--r--. 1 root root 13003582 Apr 3 13:34 initramfs-2.6.35.6-45.fc14.x86_64.img
-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-2.6.35.11-83.fc14.x86_64
-rw-r--r--. 1 root root 2157581 May 21 13:31 System.map-2.6.35.13-92.fc14.x86_64
-rw-r--r--. 1 root root 2154853 Oct 18 2010 System.map-2.6.35.6-45.fc14.x86_64
-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-2.6.35.11-83.fc14.x86_64
-rwxr-xr-x. 1 root root 3788576 May 21 13:31 vmlinuz-2.6.35.13-92.fc14.x86_64
-rwxr-xr-x. 1 root root 3782016 Oct 18 2010 vmlinuz-2.6.35.6-45.fc14.x86_64
-rw-r--r--. 1 root root 4798912 Jul 27 21:36 vmlinuz-3.0.0
Reply With Quote
  #8  
Old 28th July 2011, 04:37 AM
stevea's Avatar
stevea Online
Registered User
 
Join Date: Apr 2006
Location: Ohio, USA
Posts: 8,297
linuxfedorafirefox
Re: Determine the kernel currently running

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
but
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
__________________
None are more hopelessly enslaved than those who falsely believe they are free.
Johann Wolfgang von Goethe
Reply With Quote
Reply

Tags
determine, kernel, running

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate .config for kernel from running kernel phe Using Fedora 4 9th May 2009 07:04 PM
How to determine the default kernel selection in booting bghayad Installation and Live Media 8 25th October 2007 02:39 AM


Current GMT-time: 05:49 (Saturday, 18-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat