banner



How To Repair Ubuntu 18.04

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.

58 comments

DFD December 10, 2018 - 6:59 pm

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.

Reply

Mulya December 11, 2018 - 9:23 am

And what do you do if you can't get the to login screen to access terminal (tty)?

Reply

sk December 11, 2018 - 11:34 am

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?

Reply

laddd44 January 7, 2019 - 10:53 am

does it work in offline mode pc??

Reply

sk January 7, 2019 - 11:38 am

Yes, It should work.

Reply

J April 5, 2019 - 9:45 pm

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.

Reply

JEVBR April 25, 2019 - 6:34 pm

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

Reply

José Rosales June 21, 2019 - 7:11 am

Thank you this should be a marked post

Reply

Richy Doc August 13, 2019 - 3:01 am

Very good procedure. Save me a lot of time.
Thank.
Richard.

Reply

randy September 18, 2019 - 8:50 am

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.

Reply

Jaz November 15, 2019 - 4:57 pm

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.

Reply

Jose Tuttu George December 23, 2019 - 4:33 pm

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.

Reply

sk December 23, 2019 - 4:41 pm

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.

Reply

Kevmate December 29, 2019 - 9:31 pm

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.

Reply

Kevmate December 29, 2019 - 9:32 pm

BTW – I found that I had to use ctrl-alt-f3 to swicth to tty1.

Reply

tobiz January 13, 2020 - 9:25 pm

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.

Reply

vaya March 8, 2020 - 10:29 am

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

Reply

GeneralFault April 9, 2020 - 10:23 pm

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.

Reply

yjojo April 10, 2020 - 12:06 am

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!!

Reply

Carlos April 13, 2020 - 10:06 am

Hi, DFD. Which distribution you recommend then?

Reply

Bubba April 26, 2020 - 7:02 am

Is "sudo dpkg –configure -a" supposed to be listed twice?

Reply

sk April 26, 2020 - 11:57 am

Yes, I ran those commands in the same order and it worked.

Reply

Iliyan April 26, 2020 - 12:24 pm

I hope this should work on Linux Mint?

Reply

sk April 26, 2020 - 1:27 pm

Yes, It should work on most Ubuntu derivatives.

Reply

Tim Palmer April 30, 2020 - 12:54 pm

This article helped me immensely. Thank you very much!

Reply

Tuxor99 April 30, 2020 - 7:18 pm

Fantastic. Worked flawlessly on broken 18.04 directly up to 20.04. Thanks!

Reply

Goutham Vijapur April 30, 2020 - 10:58 pm

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.

Reply

Yahia Asrawi May 15, 2020 - 6:01 am

Thanks, it helped.

Reply

chola May 16, 2020 - 10:35 pm

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

Reply

Abishek June 9, 2020 - 11:22 am

When I tried this my login goes in a loop. What went wrong? I am only able to open tty2. Ctrl + Alt + F2

Reply

sk June 9, 2020 - 11:36 am

I don't know the exact reason. However, you can try to fix the OS from tty2 as well.

Reply

El Cab June 15, 2020 - 9:47 pm

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.

Reply

Scott July 1, 2020 - 7:00 am

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?

Reply

sk July 1, 2020 - 11:38 am

At the login screen, press CTRL+ALT+F1 to switch to tty1

It is your actual log in screen where you enter your password to log into your system.

When I press the CTRL+ALT+F1 I am asked for a user name and password.

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.

Reply

Archie July 1, 2020 - 9:12 pm

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.

Reply

sk July 1, 2020 - 9:54 pm

Glad it worked out well for you. Cheers, mate!

Reply

Raviprasad Cadambi July 18, 2020 - 7:46 pm

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!!

Reply

shiva July 26, 2020 - 9:10 pm

sudo apt clean
sudo: apt: command not found

Reply

Sujit August 25, 2020 - 7:46 am

This worked like a charm. Thanks a lot.

Reply

Smile September 15, 2020 - 8:06 am

Thank you!

Reply

maxwow October 6, 2020 - 2:11 am

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.

Reply

jonasz October 6, 2020 - 9:03 pm

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.

Reply

sk October 6, 2020 - 11:00 pm

Glad I could help. You are welcome.

Reply

sid October 28, 2020 - 9:21 pm

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.

Reply

sk October 28, 2020 - 10:59 pm

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.

Reply

Mohamed November 10, 2020 - 3:07 am

Thank you very much.. solved my problem 🙂

Reply

Michael November 18, 2020 - 10:07 pm

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!

Reply

sk November 18, 2020 - 10:52 pm

Reply

Scott December 28, 2020 - 4:45 am

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?

Reply

sk December 28, 2020 - 11:03 am

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.

Reply

Jonathan Wheeler February 28, 2021 - 2:38 am

You, good sir, are my hero! Please let me know where I can send you a small tip as a thank you.

Reply

sk February 28, 2021 - 11:22 am

Reply

sk March 3, 2021 - 10:48 am

Thank you very much for your donation Mr.Jonathan. Very kind of you.

Reply

Yim July 23, 2021 - 1:46 am

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!

Reply

sk July 23, 2021 - 12:41 pm

Glad it worked out for you. Happy to help!

Reply

Juan Carlos August 7, 2021 - 5:05 am

Gracias, me ahorro un monton de tiempo

Reply

Mark Aaron September 6, 2021 - 7:42 am

sudo apt autoremove

, in case you have outdated files that weren't removed

Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

How To Repair Ubuntu 18.04

Source: https://ostechnix.com/how-to-fix-broken-ubuntu-os-without-reinstalling-it/

Posted by: bellephroodession51.blogspot.com

0 Response to "How To Repair Ubuntu 18.04"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel