第三方linux内核下apt install时提示Failed to set capabilities on file XXX解决方法

强行魔改最(bìng)为(bù)致命x2


前情提要

今天在探索PYNQ on Z7020,安装netdata时,dpkg报错碰到了这个问题。

硬件是正点原子启明星V2,系统镜像为正点原子提供的 pynq on ubuntu18.04.

日志

1
2
3
4
5
Setting up netdata (1.9.0+dfsg-1) ...
Failed to set capabilities on file `/usr/lib/arm-linux-gnueabihf/netdata/plugins.d/apps.plugin' (Operation not supported)
The value of the capability argument is not permitted for a file. Or the file is not a regular (non-symlink) file
dpkg: error processing package netdata (--configure):
installed netdata package post-installation script subprocess returned error exit status 1

定位及分析

注意第二行和第三行,判断是setcap命令出现了问题。

首先看了第一篇参考[1],执行getcap /usr/lib/arm-linux-gnueabihf/netdata/plugins.d/apps.plugin尝试获取权限

出现错误:

1
Failed to get capabilities of file '/usr/lib/arm-linux-gnueabihf/netdata/plugins.d/apps.plugin' (Operation not supported)

定位问题,根据第二篇参考[2]所述,确定问题是内核不支持该功能。

解决方案

严格来说,解决方案有两种:

  1. 修改内核使之支持该功能;
  2. 修改postinst脚本回避掉setcap的相关问题

其中第一个方案一劳永逸,第二个方案每次遇到相同问题的时候都需要处理,会更麻烦

不过因为我手头只有系统镜像img文件,没有源码,所以暂时不能修改内核,只能采取第二种方法了

相关命令参考了[3]。

操作如下:

  1. sudo nano /var/lib/dpkg/info/[package_name].postinst 打开postinst脚本
  2. 寻找setcap相关代码,定位到某一行
  3. 注释掉该行代码
  4. sudo apt install [package_name]重新安装

第四步安装的最后重新报了一个warning如下:

1
2
W: APT had planned for dpkg to do more than it reported back (0 vs 4).
Affected packages: netdata:armhf

不过warning=nothing,忽略掉就好/doge

后记

感觉自己好像越来越能解决问题了呢(虽然方法很冒险…

参考

[1] 记录一次setcap提权失败的经历
[2] Failed to get capabilities of file (Operation not supported)
[3] dpkg: error processing package * (—configure)错误解决办法