Home Ubuntu How to Repair a Damaged Filesystem in Ubuntu

How to Repair a Damaged Filesystem in Ubuntu

The reputation of the various Linux operating system distributions speaks for itself. These prime operating system environments continue to be secure, open-source, open to frequent software updates, and are embraced by a growing user community and developers’ support.

However, these Linux OS attributes and stripes do not guarantee a bulletproof status. Sometimes you do not have control of what happens or what will happen to your Linux OS filesystem.

A Linux filesystem tends to get damaged or corrupted due to unavoidable circumstances like the unsafe removal of a media or drive hosting the Linux OS, instantaneous system crashes, and unexpected power losses.

How to Repair Ubuntu Filesystem

When victimized by filesystem damage or corruption on a Linux system, a user’s first instinct is usually to install a fresh copy of the operating system.

The inconvenience of this approach is that you could spend unnecessary hours backing up your data and reinstalling the Linux OS when a quick solution could be right in front of a terminal. Ubuntu is well-equipped with terminal-based tools that can quickly repair/fix a damaged/corrupted filesystem.

The most ideal tool for this job is the fsck (file system consistency check) utility. However, using the fsck command on a mounted filesystem is highly discouraged as it might result in additional damages to those files.

We, therefore, have the option of attempting an on-boot repair of the damaged filesystem.

Create a Bootable Ubuntu USB Drive

Download an Ubuntu OS ISO file and use it to create a bootable USB drive. This bootable USB drive should have the Ubuntu OS image inside it. A straightforward tool for this job is balenaEtcher.

Once you created a bootable Ubuntu USB drive, connect to the machine and restart your machine and press the boot devices to associate keys e.g. F12, to reveal a boot menu.

Ubuntu Boot Menu
Ubuntu Boot Menu

Trace the menu option associated with the USB/CD-ROM drive and press [Enter]. It will boot your Ubuntu into Live mode, here go with the Try Ubuntu option.

Try Ubuntu Option
Try Ubuntu Option

You will be logged in to an Ubuntu desktop environment (Live CD approach). From here, you will have more control of your initial Ubuntu OS installation and its associated filesystem.

Ubuntu Live Boot Desktop
Ubuntu Live Boot Desktop

At this point, we are comfortable enough to start executing the needed commands that will help us to identify the associated filesystem partitions to repair our damaged filesystem.

$ sudo fdisk -l
Find Ubuntu Filesystem Partitions
Find Ubuntu Filesystem Partitions

In this case, the targeted filesystem partition with Ubuntu installation is /dev/sda5.

Repair Ubuntu Filesystem Using Fsck Command

First, unmount the filesystem partition you suspect is damaged. In most cases, it is usually unmounted but we need to be certain:

$ sudo umount /dev/sda5

To trace and repair the possibility of any file damages on this filesystem partition, we need to execute the following fsck command.

$ sudo fsck -p /dev/sda5
Repair Ubuntu Filesystem
Repair Ubuntu Filesystem

You can re-use the above fsck command syntax with other Linux filesystems you suspect to be damaged.

From here, you can comfortably exit the terminal and restart your computer to default to the originally installed Ubuntu OS version.

Boot Ubuntu OS
Boot Ubuntu OS

If your Ubuntu OS filesystem had any fixable issues or file damages, they should now be resolved.

Ubuntu Login
Ubuntu Login

Being able to repair your damaged Ubuntu filesystem through this approach saves you from the headache of having to backup data and re-install your Linux OS. This methodology is efficient such that you don’t have to deal with filesystem partition mount issues while running FSCK.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

5 thoughts on “How to Repair a Damaged Filesystem in Ubuntu”

  1. Gnome disk utility and GParted will both un-mount, check, and repair a hard drive with a GUI if you are not a command-line user.

    Reply

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.