大网数据广告活动
服务器运维问答

Debian removed /var/lib/dpkg/info/, is there a way to save the system?

· 52CE 我爱测

Removed accidentally /var/lib/dpkg/info/, now I am having problems with installing/removing packages, it prompts errors, cause can not find the info about installed packages. Is there any way to save the system or need to reinsta…

问题原文

原帖链接 · Wiggler Jtag · CC BY-SA 3.0

Removed accidentally /var/lib/dpkg/info/, now I am having problems with installing/removing packages, it prompts errors, cause can not find the info about installed packages.

Is there any way to save the system or need to reinstall debian completely? :/

已采纳解答

原帖链接 · Insyte · CC BY-SA 3.0

You should be able to regenerate the directory using something like this:

for i in $(dpkg -l|awk '/^ii/ {print $2}')
do
    apt-get --reinstall -y install $i
done

What that snippet should do is reinstall every package you already have installed. It will also upgrade everything. If you don't want to do that, you'll have to extend the script to install the specific version you currently have installed, which is not guaranteed to work as those packages may no longer exist in the repository.

More info and a slightly different approach: http://people.adams.edu/~cdmiller/posts/Ubuntu-dpkg-recovery/

EDIT: Important tip from the above linked article:

Some packages will still not install correctly as more stuff is missing from /var/lib/dpkg. In particular the package "ucf" is important to enable the kernel and possibly some others to install correctly.

Without /var/lib/dpkg/info/ucf.templates the kernel install produces this error:

failed to install/upgrade: User postinst hook script [/sbin/update-grub] exited with value 10

Install ucf:

apt-get --reinstall install ucf

That article describes recovering from completely deleting all of /var/lib/dpkg, so this extra step may not apply to your situation.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-03-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。