解决Ubuntu包损坏问题:dpkg: error processing package

ubuntu包管理器,不知道怎么坏掉了,执行命令报错:

root@vps:~# apt-get install -f

Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 349 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up linux-image-3.19.0-76-generic (3.19.0-76.84) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
The link /initrd.img is a dangling linkto /boot/initrd.img-3.19.0-76-generic
vmlinuz(/boot/vmlinuz-3.19.0-76-generic
) points to /boot/vmlinuz-3.19.0-76-generic
 (/boot/vmlinuz-3.19.0-76-generic) -- doing nothing at /var/lib/dpkg/info/linux-image-3.19.0-76-generic.postinst line 491.
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.19.0-76-generic /boot/vmlinuz-3.19.0-76-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.19.0-76-generic /boot/vmlinuz-3.19.0-76-generic
update-initramfs: Generating /boot/initrd.img-3.19.0-76-generic
E: /usr/share/initramfs-tools/hooks/fixrtc failed with return 1.
update-initramfs: failed for /boot/initrd.img-3.19.0-76-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-3.19.0-76-generic.postinst line 1025.
dpkg: error processing package linux-image-3.19.0-76-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of linux-image-extra-3.19.0-76-generic:
 linux-image-extra-3.19.0-76-generic depends on linux-image-3.19.0-76-generic; however:
  Package linux-image-3.19.0-76-generic is not configured yet.

dpkg: error processing package linux-image-extra-3.19.0-76-generic (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 linux-image-3.19.0-76-generic
 linux-image-extra-3.19.0-76-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

可以看得出,是这个 linux-image-3.19.0-76-generic 包有问题,依赖或是其它问题,导致apt配置不成功。

编辑 dpkg status 状态文件:

sudo vim /var/lib/dpkg/status

找到包 linux-image-3.19.0-76-generic 和 linux-image-extra-3.19.0-76-generic 那一段,删掉。类似这样:

Package: linux-image-3.19.0-76-generic
Status: install ok half-configured
Priority: optional
Section: kernel
Installed-Size: 47223
Maintainer: Ubuntu Kernel Team <kernel-team@lists.ubuntu.com>
Architecture: amd64
Source: linux
Version: 3.19.0-76.84
Provides: fuse-module, ivtv-modules, kvm-api-4, linux-image, linux-image-3.0, redhat-cluster-modules, virtualbox-guest-modules
Depends: initramfs-tools (>= 0.36ubuntu6) | linux-initramfs-tools, module-init-tools (>= 3.3-pre11-4ubuntu3)
Pre-Depends: dpkg (>= 1.10.24)
Recommends: grub-pc | grub-efi-amd64 | grub-efi-ia32 | grub | lilo (>= 19.1)
Suggests: fdutils, linux-doc-3.19.0 | linux-source-3.19.0, linux-tools, linux-headers-3.19.0-76-generic
Conflicts: hotplug (<< 0.0.20040105-1)
Description: Linux kernel image for version 3.19.0 on 64 bit x86 SMP
 This package contains the Linux kernel image for version 3.19.0 on
 64 bit x86 SMP.
 .
 Also includes the corresponding System.map file, the modules built by the
 packager, and scripts that try to ensure that the system is not left in an
 unbootable state after an update.
 .
 Supports Generic processors.
 .
 Geared toward desktop and server systems.
 .
 You likely do not want to install this package directly. Instead, install                                                                                             
 the linux-generic meta-package, which will ensure that upgrades work                                                                                                  
 correctly, and that supporting packages are also installed. 

然后再运行

 sudo apt-get install -f 

最后可以清理掉不用的文件,根据上面 linux-generic 包后面的版本号找对应应该删除的文件夹:

rm -rf /lib/modules/3.19.0-76-generic/
rm -rf /boot/*3.19.0-76*