Recovering from power loss-interrupted Ubuntu distribution upgrade

Was doing an Ubuntu maverick (10.10) to natty (11.04) upgrade on a test system (desktop) and the power was lost. No UPS. On reboot it didn’t come back properly and I got,

The disk drive for / is not ready yet or not present

As far as I know this was part way through the package installations. If it fails during the package download then there is never any problem but with a part-install then parts of the system are running the new version and parts are on the old distribution.

The fix is fairly easy – at the prompt above then type M to get to the manual recovery.

The disk will be mounted as read-only so then remount this,

sudo mount -o remount,rw /

then try these commands,

sudo apt-get update
sudo dpkg --configure -a

then reboot and then the system should come back in a partially upgraded but stable state and you can continue with the distribution upgrade with,

sudo apt-get upgrade -f
sudo apt-get dist-upgrade

After the reboot it will be on the new distribution. Note that if a package is corrupted then you may need to delete that one package file from the /var/cache/apt/… location and re-run the sudo apt-get upgrade -f command. It is a pity the distribution upgrade process doesn’t have this kind of logic built in to facilitate unattended completion or recovery of a partial distribution upgrade.

Other useful commands that are related but not part of the repair: To start off the upgrade process (which was interrupted by the power supply problem),

sudo do-release-upgrade

To verify what version you are running,

lsb_release -r