January 27, 2022

How To Fix Broken Ubuntu OS Without Reinstalling It

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, and also without losing data as described below.

Introduction

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 while upgrading packages.

When the power is back, I did boot the system again. Right after entering the login password in my Ubuntu system, it's gone blank and didn't respond. Keyboard and mouse also didn't work.

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 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. 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, 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.