编译内核版本号带“+“问题

编译内核后版本号中带"+"

基于Linux-5.9.10版本。
问题描述
修改过内核,然后为了避免版本号与现有的一样,不好区分,因此加上了CONFIG_LOCALVERSION,然而发现编译后的版本号中总是带了"+“,对于某些python库比如disutils库中会对版本号读取,带了”+"可能会影响程序的正常运行。

为何会带"+"号

kernel源码路径下Makefile中:

filechk_kernel.release = \
    echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"

include/config/kernel.release文件由顶层Makefile决定生成,setlocalversion中:

# localversion* files in the build and source directory
res="$(collect_files localversion*)"
if test ! "$srctree" -ef .; then
    res="$res$(collect_files "$srctree"/localversion*)"
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"

setlocalversion执行最终打印res变量,res变量由三部分构成:localversion,CONFIG_LOCALVERSION,LOCALVERSION;
而其中,如果定义了CONFIG_LOCALVERSION_AUTO,则res由localversion和scm_version构成,scm_version可以由.scmversion文件定义或git提交的commit记录生成。
如果没有定义CONFIG_LOCALVERSION_AUTO,则res变量会res = $res${scm:++}执行,scm只要定义了且非空,就会用"+“替换掉scm,所以版本号中带了”+"。

解决

.config中定义
CONFIG_LOCALVERSION_AUTO=y即可
如果还想自己添加内核版本号字符串呢
CONFIG_LOCALVERSION="xxxxxx"
然后make distclean, cp config .config , make prepare, cat include/config/kernel.release查看效果

另一个解决方法

看下setlocalversion用法及参数检查

usage() {
    echo "Usage: $0 [--save-scmversion] [srctree]" >&2
    exit 1
}

scm_only=false
srctree=.
if test "$1" = "--save-scmversion"; then
    scm_only=true
    shift
fi
if test $# -gt 0; then
    srctree=$1
    shift
fi
if test $# -gt 0 -o ! -d "$srctree"; then
    usage
fi

# 省略一堆代码

if $scm_only; then
    if test ! -e .scmversion; then
        res=$(scm_version)
        echo "$res" >.scmversion
    fi
    exit
fi

# 省略一堆代码

那么一种粗暴的解法就是,修改顶层Makefile,添加–save-scmversion参数,这样就不用该config配置

filechk_kernel.release = \
    echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion --save-scmversion $(srctree))"
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译Ubuntu内核的步骤如下: 1. 下载内核源代码: 在终端中执行以下命令来下载最新版本的内核源代码: ``` $ git clone git://kernel.ubuntu.com/ubuntu/ubuntu-<RELEASE-CODE-NAME>.git ``` 其中 `<RELEASE-CODE-NAME>` 是你要编译的Ubuntu版本的代号,比如 "focal" 代表 Ubuntu 20.04 LTS。 2. 安装编译所需的依赖: 在终端中执行以下命令来安装编译所需的依赖: ``` $ sudo apt-get build-dep linux-image-$(uname -r) $ sudo apt-get install libncurses-dev flex bison openssl libssl-dev ``` 3. 配置内核: 进入内核源代码目录,执行以下命令来配置内核: ``` $ cd ubuntu-<RELEASE-CODE-NAME> $ cp /boot/config-$(uname -r) .config $ make menuconfig ``` 这会打开一个菜单界面,你可以根据需要进行内核配置的修改。 4. 编译内核: 执行以下命令来编译内核: ``` $ make -j$(nproc) ``` `-j$(nproc)` 表示使用与你的系统内核数量相同的线程数进行编译,可以加快编译速度。 5. 安装编译好的内核: 执行以下命令来安装编译好的内核: ``` $ sudo make modules_install $ sudo make install ``` 6. 更新引导: 执行以下命令来更新引导: ``` $ sudo update-initramfs -c -k <KERNEL-VERSION> $ sudo update-grub ``` `<KERNEL-VERSION>` 是你编译好的内核版本号。 7. 重启系统: 编译和安装完成后,你可以通过以下命令来重启系统: ``` $ sudo reboot ``` 请注意,编译内核需要一定的时间和计算资源,并且对系统有一定的风险。在进行这个过程之前,请确保你了解相关知识并备份重要数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值