Kernel compilation without extra “+” or other markers in the version string

This post was written by eli on May 29, 2014
Posted Under: Linux kernel

So there’s this “+” sign added to the kernel version (as displayed with uname -r) when the kernel is compiled with a git tree that doesn’t sit on an official version (or more precisely, not on an annotated tag). Which kinda makes sense to tell the kernel’s users that the kernel isn’t exactly the vanilla thing. Only it annoys me. Partly because modules, which are compiled under the kernel headers that are extracted from this kernel (if stored separately) will not match — their version will lack the “+” sign, since there is no git repo attached to the headers.

For a while I used to move the .git directory to .gitt before compiling, and then back again afterwards to prevent this plus sign from appearing on my kernels. And then I decided to really fix it.

I’d also mention that assigning KERNELVERSION on the make command doesn’t prevent the “+” sign.

So this is what to do: Edit scripts/setlocalversion and add the line marked in red, somewhere around line 38.

[ ... ]

scm_version()
{
 local short
 short=false

 cd "$srctree"

 return; # Do nothing.

  [ ... ]
}

That’s it. The git’s state is ignored, no more “+” anymore. The trick is to return immediately from the function that is supposed to add these extra version markers as necessary. So it doesn’t get the chance.

Add a Comment

required, use real name
required, will not be published
optional, your blog address