Ubuntu – How to recover a completely messed up ubuntu system

13.04aptpythonupgrade

I have a system about 3000km away, so I have no access to it. The machine is running ubuntu 13.04 (yes, it's EOL passed long ago), and the python module is completely messed up. when I tried to use do-release-upgrade to upgrade it to 13.10 and then 14.04 (as explained here) I got this error message:

Traceback (most recent call last):
  File "/usr/bin/do-release-upgrade", line 8, in <module>
    from DistUpgrade.DistUpgradeVersion import VERSION
ImportError: No module named DistUpgrade.DistUpgradeVersion

Even UFW stopped working. it showed this error:

Traceback (most recent call last):
  File "/usr/sbin/ufw", line 26, in <module>
    import ufw.frontend
ImportError: No module named ufw.frontend

So I thought I can re-install python, and life is good. Trying to reinstall python did not work at all so I thought maybe I can uninstall python and reinstall it, which also turned out to be a very stupid move! now my python package is reported as purge, trying to do anything with dpkg or apt-get throws a million errors and then exits, and almost none of the tools work!

I dont mind upgrading or installing a fresh copy of ubuntu (which I think I have to do anyway) but I cant find any clue how I can do this over the network? Is it even possible?

Edit 1:

For example when I try to run sudo dpkg --configure -a to fix the problems of the installer, I get an output like this:

dpkg: dependency problems prevent configuration of ubuntu-release-upgrader-gtk:
 ubuntu-release-upgrader-gtk depends on update-manager; however:
  Package update-manager is not configured yet.
 ubuntu-release-upgrader-gtk depends on python3-distupgrade (= 1:0.192.13); however:
  Package python3-distupgrade is not configured yet.
 ubuntu-release-upgrader-gtk depends on python3-dbus; however:
  Package python3-dbus is not configured yet.
 ubuntu-release-upgrader-gtk depends on python3-gi; however:
  Package python3-gi is not configured yet.

dpkg: error processing ubuntu-release-upgrader-gtk (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of apport-gtk:
 apport-gtk depends on python3-apport (>= 2.9.2-0ubuntu8.5); however:
  Package python3-apport is not configured yet.
 apport-gtk depends on python3-gi; however:
  Package python3-gi is not configured yet.

dpkg: error processing apport-gtk (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python3-debian:
 python3-debian depends on python3-chardet; however:
  Package python3-chardet is not configured yet.
 python3-debian depends on python3-six; however:
  Package python3-six is not configured yet.

dpkg: error processing python3-debian (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of update-manager-core:
 update-manager-core depends on python3-update-manager (= 1:0.186.2); however:
  Package python3-update-manager is not configured yet.

dpkg: error processing update-manager-core (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of update-notifier:
 update-notifier depends on update-manager-gnome | update-manager (>= 1:0.165); however:
  Package update-manager-gnome is not installed.
  Package update-manager is not configured yet.
 update-notifier depends on ubuntu-release-upgrader-gtk; however:
  Package ubuntu-release-upgrader-gtk is not configured yet.

dpkg: error processing update-notifier (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of ubuntu-release-upgrader-core:
 ubuntu-release-upgrader-core depends on python3-distupgrade (= 1:0.192.13); however:
  Package python3-distupgrade is not configured yet.

dpkg: error processing ubuntu-release-upgrader-core (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of aptdaemon:
 aptdaemon depends on python3-aptdaemon (= 1.0-0ubuntu9); however:
  Package python3-aptdaemon is not configured yet.
 aptdaemon depends on python3-gi; however:
  Package python3-gi is not configured yet.

dpkg: error processing aptdaemon (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python3-gi-cairo:
 python3-gi-cairo depends on python3-gi (= 3.8.0-2); however:
  Package python3-gi is not configured yet.
 python3-gi-cairo depends on python3-cairo (>= 1.10.0+dfsg-3~exp2); however:
  Package python3-cairo is not configured yet.

dpkg: error processing python3-gi-cairo (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of friends:
 friends depends on friends-dispatcher; however:
  Package friends-dispatcher is not configured yet.

dpkg: error processing friends (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of apport:
 apport depends on python3-apport (>= 2.9.2-0ubuntu8.5); however:
  Package python3-apport is not configured yet.
 apport depends on python3-gi; however:
  Package python3-gi is not configured yet.

dpkg: error processing apport (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 ubuntu-release-upgrader-gtk
 apport-gtk
 python3-debian
 update-manager-core
 update-notifier
 ubuntu-release-upgrader-core
 aptdaemon
 python3-gi-cairo
 friends
 apport

Or trying to run sudo apt-get install -f outputs a lot of error and stops like this:

dpkg: error processing friends-twitter (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              dpkg: dependency problems prevent configuration of python3-aptdaemon.pkcompat:
 python3-aptdaemon.pkcompat depends on python3-aptdaemon (= 1.0-0ubuntu9); however:
  Package python3-aptdaemon is not configured yet.

dpkg: error processing python3-aptdaemon.pkcompat (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              dpkg: too many errors, stopping
Errors were encountered while processing:
 python3-dbus
 language-selector-common
 python3-gi
 python3-xkit
 ubuntu-drivers-common
 python3-commandnotfound
 ufw
 apparmor-utils
 python3-problem-report
 python3-apport
 apport
 apport-gtk
 python3-software-properties
 software-properties-common
 python3-defer

Thanks

Best Answer

Well, I ended up creating an AWS instance based on Ubuntu 13.04, and then move all python packages over from EC2 to my server. This did not fix the problem with apt-get and dpkg, but it let me run other python-based commands (e.g. ufw and do-release-upgrade).

Then I used do-release-upgrade to switch to Saucy and then Trusty. There were some errors during upgrade, but overall it updated to 14.04 successfully.

After update was done, I ran apt-get install -f and dpkg --configure -a again, and this time got a lot less errors, though still failed. I fixed errors one by one, again by borrowing the broken packages from another server running 14.04.

At the end it migrated to 14.04 and all package issues were fixed as well.