Maks
Maks

Reputation: 7955

Where do I find the version of a Linux kernel source tree?

I have downloaded from a hardware vendor just a tarball of their Linux source tree (no Git repository metadata), is there a way to find out the version number of the kernel?

Is the version number usually stored in a file somewhere in the source tree?

I'd like to be able to do this without compiling and running the kernel.

Upvotes: 93

Views: 94123

Answers (6)

paxdiablo
paxdiablo

Reputation: 882786

Check the top-level Makefile, an example of which is here. At the top of that, you should see something like:

VERSION = 3
PATCHLEVEL = 1
SUBLEVEL = 0
EXTRAVERSION = -pax
NAME = Custom Pax Version

The advantage of this method is that you only need the ability to view the files themselves rather than having to run a build process.

Upvotes: 129

MichaIng
MichaIng

Reputation: 133

In case someone needs to script it: With awk, the version can be printed from Makefile like this:

awk '/^VERSION =/{a=$3};/^PATCHLEVEL =/{b=$3};/^SUBLEVEL =/{c=$3};/^EXTRAVERSION =/{d=$3};END{print a"."b"."c d}' Makefile

If the EXTRAVERSION appendix shall be skipped:

awk '/^VERSION =/{a=$3};/^PATCHLEVEL =/{b=$3};/^SUBLEVEL =/{c=$3};END{print a"."b"."c}' Makefile

If someone knows how to make awk continue with the next pattern if the current pattern has been matched once, that would make it failsafe in case multiple lines start with VERSION = respectively. But I haven't seen this in any Linux source code version.

Upvotes: 2

Clock ZHONG
Clock ZHONG

Reputation: 1000

In the Linux source tree's root file, check the Makefile content. In its beginning part:

# SPDX-License-Identifier: GPL-2.0
VERSION = 4
PATCHLEVEL = 14
SUBLEVEL = 67

Then you linux source tree's version is: 4.14.67

Upvotes: 2

srinivas pokala
srinivas pokala

Reputation: 11

In the kernel source tree, check the root directory Makefile to get the kernel version as below.

Example as below:

 $ head Makefile
 # SPDX-License-Identifier: GPL-2.0
 VERSION = 5
 PATCHLEVEL = 18
 SUBLEVEL = 0
 EXTRAVERSION = -rc3
 NAME = Superb Owl
 # *DOCUMENTATION*
 # To see a list of typical targets execute "make help"
 # More info can be located in ./README

From the above we get the source code version is 5.18.0-rc3

Upvotes: 1

peterh
peterh

Reputation: 1

Yet another solution: in the older times include/linux/version.h, currently include/generated/uapi/linux/version.h, but only after at least a partially successful compilation.

Upvotes: 5

Adrian Cornish
Adrian Cornish

Reputation: 23916

You can find the version by running

make kernelversion

In the source tree

Upvotes: 133

Related Questions