Ubuntu `apt` 报错 “Errors were encountered while processing: base-passwd“ 的解决方法

Ubuntu apt 更新时出现报错:

Setting up base-passwd (3.5.52build1) ...
Changing home-directory of irc from /var/run/ircd to /run/ircd
1 changes have been made, rewriting files
Writing passwd-file to /etc/passwd
Error making backupfile /etc/passwd.org: Invalid cross-device link
dpkg: error processing package base-passwd (--configure):
 installed base-passwd package post-installation script subprocess returned error exit status 4
Errors were encountered while processing:
 base-passwd
E: Sub-process /usr/bin/dpkg returned an error code (1)

由于是 postinst hook 阶段出现问题,想到需要检查这个 hook:

apt download base-passwd
dpkg-deb -xv base-passwd_*.deb base-passwd_extracted/
dpkg-deb -e base-passwd_*.deb base-passwd_extracted/DEBIAN
cat base-passwd_extracted/DEBIAN/postinst

发现其中有

update-passwd --verbose

这个命令。

因此,执行

sudo update-passwd --verbose

命令输出:

Changing home-directory of irc from /var/run/ircd to /run/ircd
1 changes have been made, rewriting files
Writing passwd-file to /etc/passwd
Error making backupfile /etc/passwd.org: Invalid cross-device link

这就是产生错误的原因。

要知道 update-passwd 命令会执行什么操作,使用:

sudo update-passwd --verbose --dry-run

命令输出:

Reading passwd from /usr/share/base-passwd/passwd.master
Reading group from /usr/share/base-passwd/group.master
Reading passwd from /etc/passwd
Reading shadow from /etc/shadow
Reading group from /etc/group
Changing home-directory of irc from /var/run/ircd to /run/ircd
Would commit 1 changes

由此可见,该命令执行失败的操作是

Changing home-directory of irc from /var/run/ircd to /run/ircd

因此,我手动使用 vi 命令修改:

vi /etc/passwd

根据上面的提示,找到 irc,将对应的 /var/run/ircd 改为 /run/ircd。修改后 apt 恢复正常。

你可能感兴趣的:(ubuntu,linux,运维)