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.
Not so long ago one would say Windows, instead of Ubuntu. The answer would be very similar: in the past, install Linux instead. Here, instead a real Linux distribution instead.
And what do you do if you can’t get the to login screen to access terminal (tty)?
Probably, I will use live cd or go to single user mode to see if I can fix it. I haven’t tried it yet though. Do you have any better way?
does it work in offline mode pc??
Yes, It should work.
Thanks a lot, your list helped me also via an SSH connection from a remote PC. I needed to do it that way because the linux machine did not respond on CTRL+ALT+F1 to open directly tty1.
Thanks SK, that really solved my problem here. Saved my a lot of reinstalling all my programs (did have a backup). I messed up the installation process when at some point i opted for “show the difference” when asked if i wanted to update. At this point the installation went sideways. At the end i was not allowed to re-install before restarting, but the restart was locked (I guess i was deadlocked). Had to use the power button to restart.
Terminal is very useful, i use it a lot, but for most simple users, user-friendliness goes out the window as soon as terminal appears. Seems to me update process may need some reviewing
Thank you this should be a marked post
Very good procedure. Save me a lot of time.
How can this work? If you used a usb stick to run the “live cd” and didn’t mount your linux partitions on the disk, then performing sudo rm /var/lib/apt/lists/lock will apply to the live OS, not the broken one on your hard disk!
I think the “broken” linux partition must be mounted and your commands would look something like this: sudo rm /media/myroot/var/lib etc.
Anyway, I will try it, got nothing to lose at this point.
The method that is described in this article is only referring to if you can still reach ubuntu log in. If you use a live cd or usb you would mount the relevant partitions then chroot into that mount point. Then those commands described can be used.
sudo dpkg –configure -a
“Processing was halted because there were too many errors.” is the error I am getting. I regret my decision to upgrade OS. Any help on this? I don’t have live cd. My cd drive broke long time ago.
Can’t you switch to tty1 by pressing CTRL+ALT+F1? If yes, you don’t need a live cd. Just run the aforementioned commands one by one and see it solves your problem. If you can’t switch to tty1, may be you should try live usb.
When i do ctrl alt f1 I get only ubuntu; advanced options for ubuntu; and uefi firmware settings. Those are the options. No login. No tty. Nowhere that I would be able to enter any commands. I’ve tried all the options within these three and nothing works.
I just verified it. I can able to switch to tty1 by pressing CTRL+ALT+F1 keys. It could be different on UEFI BIOS. I don’t have an UEFI system, so I can’t give solution at the moment. Sorry.
This worked brilliantly for me – thanks. One comment, I am using grub and during the update it asked what I wanted to do about grub. I said keep the original. Afterwards grub worked but the menu had changed. Ubuntu now on there twice, and advanced options added. Not sure if I should have upgraded grub. Anyway, all good.
BTW – I found that I had to use ctrl-alt-f3 to swicth to tty1.
This may be just what I’m looking for! My kubuntu 18.04 system failed to boot into kubuntu after having done a synaptic “auto remove” (I thought it was safe!) After that all I could do was boot into a screen that said something like “screen resolution problem” and offered entering tty mode. At that point I tried installing some “kde” things I thought might have got removed but no luck. I therefore resorted to boot from kubuntu 18.04 usb stick into “kubuntu try” and found my main 1Tb disc was still accessible; I did have backups but I made 2 copies of anything else I might need if a full re-install was needed, eg apt-get data. I thought it might be a basic boot problem so tried the boot-repair app, but it seemed to fail and not convinced it improved matters. I’ve just found your procedure and wonder, if, boot-repair hasn’t made things worse, it might work, I understand the point about the main disk being mount, which mine is so under “kubuntu try” could see if it works under chroot. If it does you’ll have saved my life; I’ll let you know.
hi, how about if I crash since do sudo apt purge python3. I got tty1, I already do above commands and reboot
but I got same result
This saved me a few hours of work. Thank you very much. My 18.04 LTS system got hosed after I tried to uninstall KDE and some of its applications. The crashing terminal is working again and the battery indicator is back.
You are a hero! Had done an upgrade on AntiX and then could not boot. Followed your steps and I’m back up and running. Thank you!!
Hi, DFD. Which distribution you recommend then?
Is “sudo dpkg –configure -a” supposed to be listed twice?
Yes, I ran those commands in the same order and it worked.
I hope this should work on Linux Mint?
Yes, It should work on most Ubuntu derivatives.
If you can’t access the tty or have another problem, check this out: https://ostechnix.com/how-to-boot-into-rescue-mode-or-emergency-mode-in-ubuntu-18-04/
This article helped me immensely. Thank you very much!
Fantastic. Worked flawlessly on broken 18.04 directly up to 20.04. Thanks!
I was trying to upgrade my Ubuntu 18.04.4 LTS to 20.04 LTS
I used the ‘update-manager -d’ command as provided in the tutorial (https://ubuntu.com/tutorials/tutorial-upgrading-ubuntu-desktop#1-before-you-start)
At some point of time my screen went blank and was stuck at “[OK] Started Manage, Install and generate color profiles”
After almost 30 mins, I restarted the system and it wouldn’t boot properly. the screen was stuck at “[OK] Started GNOME Display Manager (etc… etc…)”
I followed the solution in this blog and finally I have my system upgraded to Ubuntu 20.04 LTS, up and running with all the files and previously installed softwares intact.
Thanks, it helped.
Glad you even got to the login screen.
I don’t know what error hit me, OS froze and after I restarted the laptop, Ubuntu won’t get past the EFI loading bit.
It’s ruined my day
When I tried this my login goes in a loop. What went wrong? I am only able to open tty2. Ctrl + Alt + F2
I don’t know the exact reason. However, you can try to fix the OS from tty2 as well.
Thank you! I had an older laptop that i tossed out but kept the msata drive and transferred it to virtual box. I followed the above and was able to login in with no problem.
In your article titled “How To Fix Broken Ubuntu OS Without Reinstalling It” you stated the first thing I should do is login with live cd and backup my data.
You later stated “At the login screen, press CTRL+ALT+F1 to switch to tty1”.
How do I get to this login screen and login?
When I press the CTRL+ALT+F1 I am asked for a user name and password.
What would the user name and password be?
It is your actual log in screen where you enter your password to log into your system.
It is your actual username and its password that you use regularly to log in to your system.
I said backup your data using live cd before following any of these steps. Because, if the steps mentioned in this article didn’t work, you can simply reinstall the system and copy the data from the backup.
what kind of magic is that man.
my mariadb installation went sideways,even after reinstalling, purging and everything, it was still sucking at me.
Ran ur commands blindly, and problem solved. thanks a lot, keep doing the great work dude.
Glad it worked out well for you. Cheers, mate!
Wow. You are a lifesaver. On a brand new installation i screwed up my Webuzo installation and needed a rebuild. Blindly ran your steps and voila all things back to normal. Thanks a ton!!
sudo apt clean
sudo: apt: command not found
This worked like a charm. Thanks a lot.
Wow! Totally amazing. I was upgrading to 18.04 and the power went off. Thanks. Really saved me a lot of time and a complete reinstall.
I cannot thank you enough Senthil for that article. It saved me big time.
It felt like relying on the GPS nav through unknown(at least for me) roads, which let to motorway at the end. Light in the tunnel.
Glad I could help. You are welcome.
Hi so I can access tty3 by ctrl+alt+F3. Can I run these commands on tty3 without any problem? Also just to make sure I dont need a live usb for installation right? Thanks in advance.
I tried these commands and fixed my broken Ubuntu OS without any live usb. I can’t give any assurance if it will work for everyone. Good luck anyway.
Thank you very much.. solved my problem 🙂
I am having a problem when I enter $ sudo apt install -f. When I enter this into my system I get an error message of error: system does not fully support snapd: cannot mount squashfs image using “squashfs” and I get a message also reading E: Sub-process /usr/bin/dpkg returned an error code (1). If you have any information that would be great! Thank you!
Hey, I don’t have any solution for the first problem right now. I never encountered such error before. For the second error message, please look at this link -> https://ostechnix.com/fix-sub-process-usr-bin-dpkg-returned-an-error-code-1-in-ubuntu/
Thank you for wasting my time! none of your so called tips work for me. TTY1 is the login screen so how can you go to a place you are already at?
As I clearly stated in the article itself, It did work for me. As you can see in the comment section, it indeed worked for many users. Probably, your problem is something else. I switched to tty1 from GUI by pressing CTRL+ALT+F1 keys. If you can’t go to tty1, try other ttys and see if it helps.
You, good sir, are my hero! Please let me know where I can send you a small tip as a thank you.
You are welcome. Glad I could help. https://ostechnix.com/donate/
Thank you very much for your donation Mr.Jonathan. Very kind of you.
Just wanted to say thank you very much! I know all the commands on their own, but not the right sequence 😀
This kind of work really helps us all out, thank you!
Glad it worked out for you. Happy to help!
Gracias, me ahorro un monton de tiempo
sudo apt autoremove
, in case you have outdated files that weren’t removed
Worked…purged brave as well
Brilliant, I had stripped out and ITX box (21.10 Impish with older Gigabyte AB350N ),taken out the video card and on restart ,Ubuntu had unusual pale colours, Guessing it was needing some kind of re-initialising of the gaphics, I found this page on the interweb. After stepping through the suggested cli entries, it came up after restart restored to good health. Jolly good general purpose tonic for this little beast, thanks,
Thank you very much.. solved my problem 🙂
Your set of commands worked great when recovering from an aborted upgrade from 20.04 to 22.04. Thank you for that. Beautiful recovery. Now will those same commands work to upgrade another machine from 18.04 to 22.04 with out stopping at 20?
I have taught a bit at a school in Erode and helped lead a student field trip to Ooty.
Yes, It should work for any Ubuntu versions and Ubuntu variants.
You should edit it to tell people that step 2 is not a continuation from step 1. Please indicate that you should exit from the LiveCD and try to boot in to your system regularly. That is not clear at all.
You’re right. I edited the guide as you suggested. Thanks for pointing it out.