Ubuntu – Fixing a broken dpkg and apt package manger

aptbootdpkggrub2

I am working VM which I haven't administered in the past and it is in a bad state (but I need to rescue it). I am not a linux expert but in the past 5 years I have been able to fix problems by using google. After a complete day yesterday I dunno what else to do then asking dumb questions by just stating my problem.

  • The system won't do a regular boot (I can however open a rescue root shell in which I can mount the file system and enable networking to some degree (I can reach outside networks but I cannot open port 22 or start an ssh deamon – I can however start apache and open port 80)
  • I cannot install or remove software since dpkg always complains about old linux header images (I think a former administrator has deleted manually linux headers from the boot partition to make space.)
  • Now each time I try to do apt-get install or remove or upgrade or whatever it complains that there where too many errors in dkpg and especially there where errors with some old linux images (which are not present on my boot partition) and it aborts. It also complains of not finding files (related to the old linux headers)
  • I found one instruction that suggested to reinstall grub2 which I followed through. I think removing worked but installing broke in the same way as not other software can be installed. I am pretty confident the next time I wan't to restart the machine I will not even be able to enter a rescue system because grub2 seems to be uninstalled.
  • I cannot do something like apt-get install linux-image-generic

I understand that this post does not even bare a proper question but I don't even know how to formulate one. There seem to be so many things broken that obviously I kind of lost track of where to start.

edit

output of dpkg --get-selections : http://pastebin.com/CRFaaJ7m

output of apt-get install linux-generic: http://pastebin.com/7t20Bavu

output of dpgk --configure -a: http://pastebin.com/Hpmch9dM

also I think the output might be interesting (especially starting at line 484): http://pastebin.com/uUi86FtT

Best Answer

  • Could see only one old kernel from dpkg status, but I'm not sure if it really on the disk.

    Anyway:

    1. Make a backup of the DPKG status file

      cp /var/lib/dpkg/status /var/lib/dpkg/status.backup0
      
    2. Clear those manually removed kernels from the DPKG status

      Check which line is the package entry

      grep -n linux-image-extra-3.13.0-93-generic /var/lib/dpkg/status
      

      Open status for edit (change xxxxx with the line number)

      nano +xxxxx /var/lib/dpkg/status
      

      Change its status to deinstall as this example

      Package: linux-image-extra-3.13.0-93-generic
      Status: install ok installed
      

      to

      Package: linux-image-extra-3.13.0-93-generic
      Status: deinstall ok config-files
      

      Ctrl+O to save & Ctrl+X to exit

    3. Make the previous step for the following packages

      linux-image-3.13.0-93-generic
      linux-image-extra-3.13.0-101-generic
      linux-image-3.13.0-101-generic
      
    4. Modify DBus post -install script to skip errors

      nano /var/lib/dpkg/info/dbus.postinst
      

      and comment set -e#set -e (around line # 5)

    5. Continue previous installation

      dpkg --configure -a
      
    6. Fix dependencies

      apt -f install
      
  • Related Question