其实,一直以来,我们编译KVM(Linux

kernel)生成的RPM包中的kernel版本总是带有一个“莫名其妙”的加号(+),其实我知道大概是因为我们修改了Linux.git(或

kvm.git)中的一些文件。但是我们只是修改了一下Makefile,让我们做RPM包是方便而已,一般我也没有在编译时修改其他的源代码文件,所以

我想把这个加号去掉,对其进行了简单的研究,问题已经搞定了,记录如下吧。

kernel版本出现一个加号(plug sign)的原因可能是如下两点,当然前提是使用Linux的GIT repository,且CONFIG_LOCALVERSION_AUTO和LOCALVERSION都没有设置。

(1)如果当前repository的commit ID不是某一个tag,则默认有一个加号。因为在最上层的Makefile中只有该repository中最近一次tag的版本信息,需要用加号(+)来标识它并非一个tag(如:3.5.0)。

(2)如果当前repository的commit ID刚好是一个tag,且其中有GIT管理下的文件被改动,这默认有一个加号(+)。

如果想避免这个烦人的加号,可以将scripts/setlocalversion脚本中带有’ echo “+” ‘和’ res=”$res${scm:++}” ‘的这两行删掉即可。

To avoid the additional plus sign in kernel release version, just remove

‘ echo “+” ‘ line and ‘ res=”$res${scm:++}” ‘ line in

scripts/setlocalversion file.

首先,Linux的顶层的Makefile关于版本的信息,以及对”make kernelrelease”的定义如下:

VERSION = 3

PATCHLEVEL = 5

SUBLEVEL = 0

EXTRAVERSION =

NAME = Saber-toothed Squirrel

#..............

@echo ' kernelrelease - Output the release version string'

@echo ' kernelversion - Output the version stored in Makefile'

#..............

kernelrelease:

@echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"

kernelversion:

@echo $(KERNELVERSION)

然后,我们执行“make kernelrelease”则会生成kernel发布的版本信息,如下:

然后,我们执行“make kernelrelease”则会生成kernel发布的版本信息,如下:

注意,这个加号其实是作为本地的版本号加进去的,详见scripts/setlocalversion这个脚本,有如下的部分重要内容。

scm_version()

{

local short

short=false

cd "$srctree"

if test -e .scmversion; then

cat .scmversion

return

fi

if test "$1" = "--short"; then

short=true

fi

# Check for git and a git repo.

if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then

# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore

# it, because this version is defined in the top level Makefile.

if [ -z "`git describe --exact-match 2>/dev/null`" ]; then

# If only the short version is requested, don't bother

# running further git commands

if $short; then

echo "+"

return

fi

# If we are past a tagged commit (like

# "v2.6.30-rc5-302-g72357d5"), we pretty print it.

if atag="`git describe 2>/dev/null`"; then

echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'

# If we don't have a tag at all we print -g{commitish}.

else

printf '%s%s' -g $head

fi

fi

if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then

printf '%s' -dirty

fi

# All done with git

return

fi

#................

}

#................

# CONFIG_LOCALVERSION and LOCALVERSION (if set)

res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"

# scm version string if not at a tagged commit

if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then

# full scm version string

res="$res$(scm_version)"

else

# append a plus sign if the repository is not in a clean

# annotated or signed tagged state (as git describe only

# looks at signed or annotated tags - git tag -a/-s) and

# LOCALVERSION= is not specified

if test "${LOCALVERSION+set}" != "set"; then

scm=$(scm_version --short)

res="$res${scm:++}"

fi

fi

echo "$res"

如下的一些信息可以方便你理解上面的这段脚本。

[root@jay-linux linux.git]# git rev-parse --verify --short HEAD

28a33cb

[root@jay-linux linux.git]# git describe --exact-match 2>/dev/null

v3.5

[root@jay-linux linux.git]# git diff-index --name-only HEAD

mm/oom_kill.c

[root@jay-linux linux.git]# man git

#...........

git-rev-parse(1)

Pick out and massage parameters.

git-describe(1)

Show the most recent tag that is reachable from a commit.

git-diff-index(1)

Compares content and mode of blobs between the index and repository.

#............

另外,对于setlocalversion中的一个语法解释一下:

${var:-value1} 在变量var不为空时,保持var原有的值不变;如果var变量未设置或者为空,这表达式结果为value1,但是变量var的值并不改变(未设置或为空)。

${var:+value1} 在变量var不为空时,表达式结果为value1;如果var变量未设置或者为空,这表达式结果为空。${var+value1}的效果一样。

${var:=value1} 在变量var不为空时,保持var原有的值不变;如果var变量未设置或者为空,这表达式结果为value1,变量var也被赋值为value1。

${var:?value1} 在变量var未设置或为空时,脚本会退出并抛出一个错误信息(包含value1)。

另外,如下一篇博客也研究了这个问题,供大家参考。

http://blog.csdn.net/adaptiver/article/details/7225980

转载地址:

linux 版本号 加号,Linux kernel编译生成的版本多一个加号“+”相关推荐

  1. linux 内核调试 booting the kernel.,Uncompressing Linux....... done, booting the kernel就不动了的一个可能原因...

    最近搞阳初2410的板子,做的U-BOOT1.2.0能从NAND FLASH启动起来了,但是引导内核真是搞怪,前几天还能引导的,这几天又不能引导了,但是这些内核用VIVI都是能引导的,搞得头痛死了,总 ...

  2. Linux内核目录结构(2.6版本以上的kernel)

    1.documentation: 没有内核代码,提供文档帮助. 2.arch: arch是architecture的缩写.所有与体系结构相关的代码都在这个目录以 include/asm-*/目录中.L ...

  3. [ Linux ] 如何查看内核 Kernel 版本(查多个Kernel的方法)

    上图来源于:turnoff.us,描述了Linux内核结构,有兴趣的同学可以访问原址看看 文章目录 什么是 Linux内核 查看 Linux内核Kernel 的场景情况 查看 Kernel 的几种方式 ...

  4. 如何查看Linux版本号(内核版本号和发行版本号)

    首先,要分清内核版本号和发行版本号的区别. 因为所有linux都是使用kernel.org上来的内核来作为发行版的基础的,所以内核版本号的高低大致能体现该linux版本的新旧. 而发行版本的版本号完全 ...

  5. linux内核和发行版本的关系,简述Linux内核和Linux发行版的区别

    做服务器运维工作,要经常和Linux的版本号打交道,但一直搞不明白Linux内核和Linux发行版到底是个啥东西.其实要理解Linux内核和Linux发行版之间的关系,只要能理解下面的关系就可以了: ...

  6. 基于Yocto构建嵌入式Linux系统U-boot、kernel内核、rootfs文件系统

    前言 Yocto 是一个很强大的构建工具,其功能不仅仅是用来获取BSP源码和简单地编译源码,开发者还可以使用Yocto对其 开发板添加各种第三方开发库,而不需要每次重新从零开始编译源码,解决第三方依赖 ...

  7. linux内核说明,Linux内核版本说明

    在下水平相当有限,不当之处,还望大家批评指正^_^ 1. 标准内核版本信息 第一列,版本性质:主分支(mainline),稳定版(stable),长期维护版(longterm) 第二列,版本号.-rc ...

  8. Linux、GUN/Linux、GUN、GPL以及各个发行版本详细介绍-扫盲篇

    什么是Linux? 也许很多人会不屑的说,Linux不就是个操作系统么.错!Linux不是一个操作系统,严格来讲,Linux只是一个操作系统中的内核.内核是什么?内核建立了计算机软件与硬件之间通讯的平 ...

  9. 香蕉派 banana pi github 最新Linux 代码升级到kernel 4.2.

    2019独角兽企业重金招聘Python工程师标准>>> 香蕉派 banana pi github 最新Linux 代码升级到kernel 4.2. https://github.co ...

最新文章

  1. asp.net开发中自定义网站的目录
  2. 华为企业管理经典案例_企业税务筹划-华为公司税筹案例分析
  3. Docker实战第二天(Docker常用命令详解)
  4. 测试范围不统一,引发的冲突问题
  5. (转)Linux查看CPU,硬盘,内存的大小
  6. emacs org-mode 常用命令
  7. JAVA的三大框架是什么?
  8. [线性代数] 1.2 全排列和对换
  9. python爬取招聘网站源码及数据分析_如何用爬虫抓取招聘网站的职位并分析
  10. 网站实时监控系统的设计与实现
  11. Sphinx全文索引搜索常见的一些错误处理收集
  12. FBI阅人术——用最短的时间了解一个人
  13. HDU2955 01背包
  14. Matlab的parfor的使用条件
  15. Oracle获取上一年的时间
  16. 外媒:京东方正寻求为苹果iPhone供应OLED屏幕
  17. RabbitMQ(Java操作工作队列-按劳分配方式)
  18. Windows下strongswan-5.5.3源码安装
  19. 新东西012--Android软键盘弹出位置控制
  20. 海信电视通过U盘安装应用

热门文章

  1. 开源jeecms,jeebbs学习笔记4——从jo_user表看持久层设计
  2. 常用电脑的人养眼绝招
  3. ASP.NET 配置概览
  4. 【免费毕设】ASP.NET通用作业批改系统设计(源代码+lunwen)
  5. Python基础教程和入门教程
  6. myeclipse里html添加背景颜色,myeclipse怎么设置主题-设置myeclipse主题背景颜色的教程 - 河东软件园...
  7. python中变量通过变量名访问_如何在python中访问给定变量的名称?
  8. php 多城市,thinkphp3.2 一站多城市配置
  9. http协议编程java_Java与Http协议的详细介绍
  10. MFC常见控件:滚动条控件