Linux kernel version string

How can I determine the build/version of Linux kernel ‘uImage’?

As per this answer superuser.com/a/1234270/439040 if you are in fact dealing with a compressed kernel image bzImage file (people in both the question and answers do seem to be dealing with both formats already) then file -bL [bzImage] , e.g. file -bL /boot/vmlinuz , will work.

7 Answers 7

According to kernel’s format specification, here’s C code:

kver.c

#include int main(int argc, char** argv) < if (argc >1)< FILE* f = fopen(argv[1], "r"); short offset = 0; char str[128]; if(f)< fseek(f, 0x20E, SEEK_SET); fread(&offset, 2, 1, f); fseek(f, offset + 0x200, SEEK_SET); fread(str, 128, 1, f); str[127] = '\0'; printf("%s\n", str); fclose(f); return 0; >else < return 2; >> else < printf("use: kver [kernel image file]\n"); return 1; >> 
gcc -o kver kver.c ./kver /boot/vmlinux-something 

Thanks for this! Unfortunately though, it doesn’t work for me for a 4.19 kernel. Has the spec changed recently? kver against that vmlinux just outputs \n , but no contents.

This is a very useful code sample, however worth noting that (AFAICT) it applies to compressed vmlinuz rather than extracted vmlinux. (And I just get \n when running it against vmlinux too.)

To find out what version of Linux is compiled, use the strings utility on the uncompressed vmlinux image.

strings linux-src/build/build-generic/vmlinux|grep «Linux version»

Linux version 3.2.0-56-generic (root@puerto-cayo) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #86 SMP Fri Nov 1 10:24:18 EDT 2013 (Ubuntu 3.2.0-56.86-generic 3.2.51)

I just realized, the kernels I have immediate access to do have the version string stored uncompressed amongst the headers. strings uImage | grep 2.6 ought to be good enough for any 2.6 kernel which covers pretty much everything in the last 5+ years).

It’s theoretically possible, but not entirely trivial.

Modern Linux kernel versions use a format called bzImage (for x86/x86_64, YMMV on other platforms). It actually consists of an ELF header and some other minutia (like a bit of decompression code) followed by, yes, a compressed image of the actual kernel.

Traditionally, the compression algorithm was zlib (contrary to popular misconception, ‘bzImage’ did not stand for «bzipped image», but for «big zImage» — the original zImage format not being able to handle large kernels), though versions after 2.6.30 also support bzip2 and LZMA.

Читайте также:  Linux mint ускорение работы

What you’ll probably have to do is determine exactly where the compressed data starts (sorry, can’t help you there, but trial and error might work), and write a bit of code to run it through the library for whichever compression algorithm is in use.

Источник

Get linux kernel version like this «310» in bash?

I create a script that I need the current kernel version in a specific way. For example, if I use : 3.10.34-1-MANJARO I want to get only 310 Which is the best/easy way to do it ?

3 Answers 3

cut -d. -f1-2 --output-delimiter=''  

Thanks! I use this command awk -F. ''

cut actually inserts the delimiter when outputting multiple fields, so you get 3.10 , not 310 - you could pipe to tr -d . .

@mklement0 I was perhaps hallucinating -- that's why I made the edit. If it was doable using cut without longish options, I'd have never suggested awk in the first place. Thanks for pointing it out.

@user3064931, no need to use the here string in that case, just do: awk -F. '' <(uname -r)

To complement @devnull's helpful answer with a bash-only solution, using bash's regex-matching operator, =~ :

ver=$([[ $(uname -r) =~ ^(5+)\.(8+) ]]; echo "$$") echo "$ver" # e.g., -> '310', if `uname -r` returned "3.10.34-1-MANJARO" 

An alternative solution using bash parameter expansion:

Note: This will only work if the output from uname -r contains a - in the 3rd . -based component - this appears to the case for Linux distributions (but not, for instance, on OSX).

ver=$(uname -r) # get kernel release version, e.g., "3.10.34-1-MANJARO" ver="$" # remove suffix starting with '.' and containing '-' ver="$" # remove periods (a single `/` would do here) echo "$ver" # e.g., -> '310' 

Tip of the hat to @alvits, who points out that uname -r may have an additional . component describing the architecture - e.g. 3.8.13-16.2.1.el6uek.x86_64 .

Источник

How do I find out the kernel version I am running?

I need this info so I can finish updating my STA Broadcom wireless. However, I'm a noob at Ubuntu and I'm not sure how to find the kernel version or kernel. I checked /lib/modules/ and found this:

2.6.27-10-generic 2.6.32-30-generic 2.6.32-34-generic 2.6.32-38-generic 2.6.27-7-generic 2.6.32-31-generic 2.6.32-35-generic 3.2.0-54-generic 2.6.28-19-generic 2.6.32-32-generic 2.6.32-36-generic 3.2.0-54-generic-pae 2.6.31-23-generic 2.6.32-33-generic 2.6.32-37-generic 

Which one is the running kernel? Another question. Is there a snippet so I don't have to cut and paste? Thanks for your time! 🙂

6 Answers 6

Well there are multiple ways to find the kernel version

Open terminal and execute:

It would display something like:

You can get further information on the current kernel with

It would display something like:

Linux saurav-P4I45Gx-PE 3.8.0-30-generic #44~precise1-Ubuntu SMP Fri Aug 23 17:33:45 UTC 2013 i686 i686 i386 GNU/Linux 

Another way to know the kernel version is to open Synaptic Package Manager and search for linux image . You have to check for the installed Kernel version.

Another way to find version of installed kernels is to run this command:

dpkg -l | grep linux-image | grep ii 

or for just the version strings:

dpkg -l | grep linux-image | grep ii | awk '' 

The latest kernel (the one with the highest version number) will boot by default, so if you have rebooted since the last kernel update, and you have not made adjustments to boot into a kernel other than the default, then you can be reasonably confident that the highest version number displayed will be the version of the running kernel, but you should use uname for more reliable information.

Источник

Get Linux Kernel Version in Ubuntu Command Line

Sagar Sharma

Get kernel version information in Ubuntu

"Linux is an Operating System" and I find myself in an unanswerable situation as Linux is the kernel, not OS itself.

It may not seem big of a deal at first glance but the newer kernels are known to bring hardware compatibility for new hardware and improvements.

And using the uname command with the -r option is by far the most popular way of printing kernel version:

get linux kernel version using uname command

where uname is a utility to print system info and when used with the -r option, it gets us the kernel version only.

But have you ever wondered what the entire string of Linux kernels indicates? Let me break it down for you.

So my kernel version is 5.15.0-47-generic (in broad terms, I'm running Kernel 5.15).

  • 5 - Kernel version.
  • 15 - Major version.
  • 0 - Minor version.
  • 47 - Bug fix.
  • generic - It's a distribution-specific string. For Ubuntu, it means I’m using the desktop version. If you're on the Ubuntu server edition, it would be server instead of generic.

This way, you get to know the currently used kernel. But do you know that your Ubuntu systems have more than one kernel version installed at a time?

But wait, there are other interesting ways to get the kernel version and I'm going to discuss them one by one.

Using hostnamectl command

While the hostnamectl command is primarily used to change the hostname, it can also show the kernel version.

When the hostnamectl command is used without any options whatsoever, it will print basic details related to hardware and software as given:

hostnamectl command in linux

hostnamectl | grep -i kernel

Filter reults using grep command

Using /proc/version file

As Linux follows the "Everything is a file" philosophy, you'd find files under the /proc directory containing information on the running system. The kernel version is one of them.

It may sound complex but you just have to view the contents of /proc/version file.

Using /proc/version file to get linux kernel version

The other details include details such as who compiled your kernel, the compiler used to compile your kernel (GCC) and its version, and the time when it was compiled (11 Aug).

Using Neofetch

Neofetch is a small command line utility that beautifully shows the system information.

It does not come pre-installed on Ubuntu and can be installed pretty quickly by given command:

sudo apt install neofetch

Once you're done with the installation, you can get the system details, including the kernel version by the following command:

neofetch in ubuntu

Unlike me, if you prefer the plain text and required info only (for neofetch only), you can use the grep command to filter results:

use grep command with neofetch

Neofetch can do much more and you can customize it to your liking.

Using dmesg command

While dmesg is considered a powerful tool to write kernel messages, it can also be used to fetch important details about the system.

Since the dmesg will omit hundreds of lines related to the system, its output must be filtered for our specific use case.

So your dmesg command to get the kernel version will be as follows:

use dmesg command to get kernel version

Using inxi Utility

The inxi utility is used to get system information which also includes the kernel version.

But the inxi is not part of the default packages and has to follow the given command to perform the installation:

The inxi is often used by advanced users as you can get in-depth info about software and hardware. And kernel info falls into the system details part, which can be printed by using -S option.

use inxi utility to print system details

Conclusion

As you can see, there are multiple ways to find the kernel versions in the Ubuntu command line. The most common is the uname command but you can use whichever you find more convenient.

Don't forget that your system has more than one kernel version installed at a time. By default, the newest kernel version is used by the system. Additional kernel versions can be used for recovery and troubleshooting. You can list the installed kernels and verify them.

Источник

Оцените статью
Adblock
detector