Just in case if your Ubuntu system is crashed due to power failure or network connectivity issue in the middle of the Upgrade process, you might end up with broken Ubuntu Linux. In such cases, you can easily fix broken Ubuntu OS without reinstalling it from scratch. Furthermore, you can accomplish this without the risk of data loss, as explained in the following instructions.
Today, I was upgrading my Ubuntu LTS system. Unfortunately, the power has gone in the middle of the upgrade process and the system is powered off abruptly while the packages are still being upgraded.
When the power is back, I proceeded to boot up the system again. However, after entering the login password in my Ubuntu system, the screen went blank and became unresponsive. Neither the keyboard nor the mouse were functioning.
All I see is just a blank screen! Thankfully, It's just a test machine and there were no important data in it. I can simply wipe off the entire OS and install Ubuntu again.
But, I don't want to do that. Since I got nothing to lose, I just wanted to repair my broken Ubuntu system, without losing data and also without reinstalling it completely. To my luck, it worked!!!
Now let us see how to recover the broken Ubuntu Linux system, without reinstalling it.
Fix Broken Ubuntu OS Without Reinstalling It
1. First of all, try to login with live cd and backup your data in an external drive. Just in case, if this tutorial didn't work, you can still have your data and reinstall everything!
2. After successfully backing up your data, restart the system and log in as usual. At the login screen, press
CTRL+ALT+F1 to switch to
tty1. You can learn more about switching between TTYs here.
3. Now, type the following commands one by one to fix the broken Ubuntu Linux:
$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/lib/dpkg/lock
$ sudo rm /var/lib/dpkg/lock-frontend
$ sudo dpkg --configure -a
$ sudo apt clean
$ sudo apt update --fix-missing
$ sudo apt install -f
$ sudo dpkg --configure -a
$ sudo apt upgrade
$ sudo apt dist-upgrade
4. Finally, reboot the system using command:
$ sudo reboot
You can now be able to login to your Ubuntu system as usual.
After I followed these steps, I managed to successfully fix broken Ubuntu 22.04 without reinstalling it. And also, all the data in my Ubuntu system were intact and everything was in the same way as I left it.
This method may not work for everyone. However, this small tip worked for me and saved a couple minutes from reinstalling my Ubuntu system from scratch.
If you know any other better way, please let me know in the comment section. I will add them in this guide as well.