How To Fix Broken Ubuntu OS Without Reinstalling It - OSTechNix
How To Fix Broken Ubuntu OS Without Reinstalling It - OSTechNix
KEEP IN TOUCH
FACEBOOK TWITTER
LINKEDIN YOUTUBE
EMAIL REDDIT
RSS
HOME BACKUP TOOLS COMMAND LINE UTILITIES DATABASE DEVOPS MOBILE PROGRAMMING SECURITY VIRTUALIZATION
UBUNTU FAQ LINUX LINUX ADMINISTRATION LINUX COMMANDS LINUX TROUBLESHOOTING TIPS AND TRICKS
TROUBLE SHOOTING UNIX/LINUX BEGINNERS
63 comments 33
This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More
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 x 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 o abruptly while the packages are being upgraded.
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 o 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.
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 x 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 reboot
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.
Related read:
How To Fix “E: Could not get lock /var/lib/dpkg/lock” Error On Ubuntu
APT APT COMMANDS DPKG FIX BROKEN UBUNTU OS LINUX LINUX ADMINISTRATION LINUX COMMANDS
63 comments 33
SK
Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix
enthusiast and FOSS supporter. He lives in Tamilnadu, India.
PiVPN – Simplest OpenVPN Setup Install Snap packages in Arch Ubuntu 16.04 LTS beta 1 has been
And Con guration, Designed... Linux, and Fedora released
July 11, 2017 June 20, 2016 February 26, 2016
63 COMMENTS
DFD REPLY
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.
MULYA REPLY
And what do you do if you can’t get the to login screen to access terminal (tty)?
SK REPLY
Probably, I will use live cd or go to single user mode to see if I can x it. I haven’t tried it yet
though. Do you have any better way?
LADDD44 REPLY
SK REPLY
J REPLY
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.
JEVBR REPLY
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 di erence” 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
RANDY REPLY
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.
JAZ REPLY
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.
SK REPLY
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.
A.B REPLY
When i do ctrl alt f1 I get only ubuntu; advanced options for ubuntu; and ue rmware
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.
SK REPLY
I just veri ed it. I can able to switch to tty1 by pressing CTRL+ALT+F1 keys. It
could be di erent on UEFI BIOS. I don’t have an UEFI system, so I can’t give
solution at the moment. Sorry.
KEVMATE REPLY
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.
KEVMATE REPLY
TOBIZ REPLY
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 o ered 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.
VAYA REPLY
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
GENERALFAULT REPLY
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.
YJOJO REPLY
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!!
CARLOS REPLY
BUBBA REPLY
SK REPLY
ILIYAN REPLY
SK REPLY
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/
TUXOR99 REPLY
Thanks, it helped.
CHOLA REPLY
ABISHEK REPLY
When I tried this my login goes in a loop. What went wrong? I am only able to open tty2. Ctrl + Alt + F2
SK REPLY
I don’t know the exact reason. However, you can try to x the OS from tty2 as well.
EL CAB REPLY
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.
SCOTT REPLY
In your article titled “How To Fix Broken Ubuntu OS Without Reinstalling It” you stated the rst 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?
SK REPLY
ARCHIE REPLY
SK REPLY
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!!
SHIVA REPLY
SUJIT REPLY
SMILE REPLY
Thank you!
MAXWOW REPLY
Wow! Totally amazing. I was upgrading to 18.04 and the power went o . Thanks. Really saved me a lot of
time and a complete reinstall.
JONASZ REPLY
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.
SK REPLY
SID REPLY
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.
SK REPLY
I tried these commands and xed my broken Ubuntu OS without any live usb. I can’t give any
assurance if it will work for everyone. Good luck anyway.
MOHAMED REPLY
MICHAEL REPLY
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!
SK REPLY
Hey, I don’t have any solution for the rst problem right now. I never encountered such error
before. For the second error message, please look at this link -> https://ostechnix.com/ x-sub-
process-usr-bin-dpkg-returned-an-error-code-1-in-ubuntu/
Good luck.
SCOTT REPLY
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?
SK REPLY
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.
SK REPLY
SK REPLY
Thank you very much for your donation Mr.Jonathan. Very kind of you.
YIM REPLY
Just wanted to say thank you very much! I know all the commands on their own, but not the right sequence
SK REPLY
MARTINI73 REPLY
BOB REPLY
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,
VAZIR REPLY
LEAVE A COMMENT
Your Comment
Name* Email*
Save my name, email, and website in this browser for the next time I comment.
* By using this form you agree with the storage and handling of your data by this website.
SUBMIT
This site uses Akismet to reduce spam. Learn how your comment data is processed.
1 comment 3
KEEP IN TOUCH
We've already shown you how to upgrade to Ubuntu 20.04 LTS desktop from Ubuntu 18.04 LTS or Ubuntu FACEBOOK TWITTER
19.10 desktop systems. Now let us see how to upgrade to Ubuntu 20.04 LTS server from Ubuntu 18.04 LTS or
Ubuntu 19.10 server with screenshots. The method of upgrading between LTS releases and normal edition to LINKEDIN YOUTUBE
RSS
Contents
1. Prerequisites
1. Backup Important Data
2. Update Your Current Ubuntu System
3. Setting up software sources
4. Help us to help you:
Prerequisites
Before upgrading to latest Ubuntu version, we must take care of some important things rst.
First of all, It is strongly recommended to backup your important data, con guration les, and anything that
you can’t a ord to lose.
$ sudo reboot
I strongly recommend everyone to use Screen tool when attempting to upgrade a remote server via SSH. This
will keep running the upgrade the process in case your SSH session is dropped for any reason.
$ screen
If your SSH connection is broken when upgrading, you can re-attach to the upgrade session easily with
command:
$ screen -Dr
Install the "update-manager-core" and "ubuntu-release-upgrader-core" packages if they are not installed
already:
If you’re upgrading from Ubuntu 18.04 LTS to 20.04 LTS, you need to set prompting behavior for for the release
upgrader as lts.
[...]
Prompt=lts
If you’re upgrading from Ubuntu 19.10 to 20.04 LTS, set prompting behavior as normal.
$ sudo do-release-upgrade -d
If you’re running the upgrade process under SSH session, the following warning message will appear. Just type
“y” to continue.
[...]
Continue running under SSH?
Continue [yN]
Now, an additional sshd will be started on port '1022' to make recovery easier, just in case of failure. If anything
goes wrong with the running ssh, you can still connect to the additional one. If you run a rewall, you may need
to temporarily open this port. As this is potentially dangerous it's not done automatically. You can open the port
with the commands:
Or,
If you are running the Upgrade on a local server, you need not to do the above steps.
After a few seconds, the upgrade wizard will display the summary of how many packages are going to be
removed, how many packages will be upgraded, how many new packages are going to be newly installed and
the total download size.
Press “y” to start the upgrade process. This will take a while to complete depending upon the speed of your
Internet connection.
During the upgrade process, some services installed on your system need to be restarted when certain libraries
are upgraded. Since these restarts may cause interruptions of service for the system, you will normally be
prompted on each upgrade for the list of services you wish to restart. You can choose this option to avoid being
prompted; instead, all necessary restarts will be done for you automatically so you can avoid being asked
questions on each library upgrade.
To automatically restart the services during package upgrades without asking, choose "Yes" and press ENTER to
continue.
Once the upgrade is complete, you would see the following message. Press "y" to complete Ubuntu upgrade
process and restart the server:
[...]
System upgrade is complete.
Restart required.
Continue [yN]
$ lsb_release -a
Sample output:
Suggested read:
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. In such cases, refer the following guide to x it.
FOCAL FOSSA LINUX UBUNTU UBUNTU LTS UBUNTU SERVER UPGRADE TO UBUNTU 20.04 SERVER
1 comment 3
SK
Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix
enthusiast and FOSS supporter. He lives in Tamilnadu, India.
How To Create A Montage From iWant – The Decentralized Peer To How To Run Windows Software
Images In... Peer File... On Linux With...
April 2, 2020 July 10, 2017 February 11, 2022
1 COMMENT
JON REPLY
Thanks. I’d tried this 3 times before, but something always went wrong. With your help, I nally got all the
way through.
LEAVE A COMMENT
Your Comment
Name* Email*
Save my name, email, and website in this browser for the next time I comment.
* By using this form you agree with the storage and handling of your data by this website.
SUBMIT
This site uses Akismet to reduce spam. Learn how your comment data is processed.
2
Fix “Sub-process /usr/bin/dpkg
returned an error code (1)” In
Ubuntu
June 22, 2020
3
How To Switch Between
Multiple PHP Versions In
Ubuntu
August 9, 2018
OSTechNix (Open Source, Technology, Nix*) regularly
publishes the latest news, how-to articles, tutorials and
tips & tricks about free and opensource software and
technology.
OSTechNix © 2022. All Rights Reserved. This site is licensed under CC BY-NC 4.0.