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


# 前情提要

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

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

# 日志

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 尝试获取权限

出现错误:

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 如下:

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) 错误解决办法