Linux users often face issues with broken operating systems due to many reasons. This issue frequently occurs when turning on the system after a major software crush, update failure, or physical damage to the system. It’s not undeniable that getting a shake on the hardware (especially in laptops) might break your current operating system. Now, there is no hassle if you’ve started using your Ubuntu fresh, but it would be havoc if you’ve been using Ubuntu professionally and there are tons of files on your system.
In that case, you might not want to erase the current operating system entirely and reinstall Ubuntu. There are ways that you can use to fix your broken Ubuntu OS without reinstalling it on your machine.
Fix Broken Ubuntu OS without Reinstalling
Ubuntu and other Linux distributions connect with the system hardware at the kernel level and run operations. If it’s not a major hardware issue, you can fix the broken OS issue with a little engineering.
In software-level fixing, we often see some specific errors appear when we want to do some operational tasks. Here, we will go through the errors specially and solve them. We will do some pre-booting and after-booting fixing to solve the broken OS.
Since Ubuntu is open source, we can actually edit and fix almost everything if we know what we are doing. This post will show how to fix a broken Ubuntu OS without reinstalling it.
1. Fix Lock /var/lib/apt/lists/lock Error
Since here we are going through an error by error, the first issue we are going to explain and solve is the missing /var/lib/apt/lists/lock
issue. In Ubuntu, executing an aptitude command is an authentic method to install an application or update the repository. But, sometimes, you might get the /var/lib/apt/lists/lock
error after executing the apt command. Before we dig into the solution, let’s see what that error message says.
Step 1: Locate the Lock
 Directory
The directory location of that error says that the apt lock list that is placed in the var directory is unavailable. In simple words, the Debian package (dpkg) is not present at this moment in the system.
This error appears when you remove a directory or repository from the Ubuntu filesystem when that file is in use or suddenly quit that application without conventionally stopping the ongoing processes.
The dpkg lock functionalities are deployed in the system so that two aptitude commands can’t use the same package resource at the same time. It automatically locks that particular package for that time. Most often, the issue gets resolved with a simple reboot.
Step 2: Fix Lock Issues Through CLI
However, if you can’t help the situation with a restart, the quick and efficient solution to the above-mentioned problem would be removing the apt lock lists from the filesystem on your Ubuntu system.
You can execute the following rm command with root access to remove the apt lock lists.
sudo rm /var/lib/apt/lists/lock
You may also try removing the dpkg lock file from the library.
$ sudo rm /var/lib/dpkg/lock $ sudo rm /var/lib/dpkg/lock-frontend
Now, remove the cache file of apt archives from the filesystem by executing the following command given below.
$ sudo rm /var/cache/apt/archives/lock
Finally, you may now run the following dpkg command to reload the system cache and configure the rest of the Debian package files on the Ubuntu system.
$ sudo dpkg --configure -a
Please warp up the entire process by cleaning the junk repository files and freeing up some space from the filesystem.
$ sudo apt clean
2. Fix Ubuntu When It Freezes in Boot
In a Gnome-based Ubuntu system, your system might get freeze very rarely if you run a heavy environment with a very low hardware configuration. However, besides Gnome stopped working, other hardware and operating system-level issues might stop you from logging into the system.
Sometimes, the lock screen manager (gdm or lightdm) might stop working frequently. However, here we will see a few steps to solve the Ubuntu boot when it hangs.
Step 1: Open Up the Boot Menu in Recovery
Before you follow the steps, please make sure your Ubuntu screen is frozen with a purple screen; a still screen with a black screen might be the case where we need to enter the rescue mode or emergency mode to fix the system.
To fix the screen freeze issue on Ubuntu or Debian-based Linux system, please restart the system and press the ESC button to enter the boot menu. If the boot menu does not appear by pressing the ESC button, please search for the dedicated key for your motherboard.
After the boot menu appears, you will see the drop-down menu starting with Ubuntu, advanced options for Ubuntu, and other memory test buttons. Now, press the e
 button from your keyboard to access the system editing script.
Step 2: Edit the Script
Now, scroll down till you see the line that starts with linux
. You can also press the Ctrl + e
button to reach the end of the screen. Then, at the end of the line that starts with linux
add the syntax nomodeset
as shown in the picture below.
nomodeset
You can now exit the script by pressing the CTRL + X
from your keyboard. Some hardware systems also allow you to use the F10 button for exiting the script editor and back to the system.
If the above solution does not work for you and you have an NVIDIA graphics card, you can also try fixing the loping graphics issue by adding the following syntax and the value in the script.
nouveau.noaccel=1
The above-mentioned methods will allow you to enter your Ubuntu system. Now, to fix the screen frize issue permanently, please run the following command on the terminal shell with root access and edit the GRUB file.
$ sudo nano /etc/default/grub
In the GRUB script, please locate the following line.
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
Now, replace that line with the following line supplied below. After you make the changes, save the file and exit it.
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"
Finally, update your Ubuntu GRUB and reboot your Ubuntu system.
$ sudo update-grub
Insights!
Since Ubuntu is a heavy Linux operating system, it has many repositories and dependency tools that make a whole OS. However, if any of those tools get locked or broken, your entire OS might get broken. In the entire post, we have seen a few cases that might cause your system to be corrupted and how to fix broken Ubuntu distros without reinstalling the OS.Â
Please share this post with your friends and the Linux community if you find it useful and informative. You can also write down your opinions regarding this post in the comment section.