我正在尝试更新一个软件包,但是更新失败,似乎是因为出现了 rpm 数据库错误 - 有没有办法修复它?
bash-4.2# yum update icinga2
...
Transaction test succeeded
Running transaction
Traceback (most recent call last):
File "/bin/yum", line 29, in <module>
yummain.user_main(sys.argv[1:], exit_code=True)
File "/usr/share/yum-cli/yummain.py", line 375, in user_main
errcode = main(args)
File "/usr/share/yum-cli/yummain.py", line 281, in main
return_code = base.doTransaction()
File "/usr/share/yum-cli/cli.py", line 817, in doTransaction
resultobject = self.runTransaction(cb=cb)
File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 1818, in runTransaction
self.plugins.run('pretrans')
File "/usr/lib/python2.7/site-packages/yum/plugins.py", line 188, in run
func(conduitcls(self, self.base, conf, **kwargs))
File "/usr/lib/yum-plugins/show-leaves.py", line 40, in pretrans_hook
_old_leaves = _get_installed_leaves(conduit)
File "/usr/lib/yum-plugins/show-leaves.py", line 34, in _get_installed_leaves
for po in conduit.getRpmDB().returnLeafNodes():
File "/usr/lib/python2.7/site-packages/yum/rpmsack.py", line 1296, in returnLeafNodes
return [ self._makePackageObject(h, mi) for (h, mi) in ts.returnLeafNodes(headers=True) ]
File "/usr/lib/python2.7/site-packages/rpmUtils/transaction.py", line 174, in returnLeafNodes
for p in _return_all_provides(h):
File "/usr/lib/python2.7/site-packages/rpmUtils/transaction.py", line 166, in _return_all_provides
for prov in hdr[rpm.RPMTAG_FILENAMES]:
_rpm.error: invalid header data
答案1
修复损坏的 RPM 数据库
rm -rf /var/lib/rpm/__db*
rpm --rebuilddb
yum clean all
答案2
今天遇到了这个错误信息。就我而言,这是本地安装的软件包存储的软件包元数据损坏的问题。
如果是本地软件包问题,可以使用以下命令识别有问题的软件包。它会_rpm.error: invalid header data
在有问题的软件包名称后立即打印出来。请注意,这将需要一段时间才能运行,并将打印出每个已安装软件包的名称。
repoquery --disablerepo='*' -a --installed | \
xargs -t -n1 repoquery --disablerepo='*' --list --installed | \
grep '_rpm.error: invalid header data'
重新安装这些软件包_rpm.error
之后,我的问题就解决了。
yum reinstall -y <offending-packages>
当 repo 的元数据或 rpm 文件损坏时,我也遇到过非常类似的错误。如果您有访问权限,您可以使用以下命令识别损坏的 rpm:
find /path/to/repo/root -name '*.rpm' | \
xargs rpm -K | \
grep 'NOT OK'
要解决此问题,请删除这些 rpm 并更新 repo 元数据,并在必要时从源重新同步。
rm /path/to/bad/rpm
createrepo --update /path/to/repo/root