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.
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.
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.
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
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
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.
If your Ubuntu OS filesystem had any fixable issues or file damages, they should now be resolved.
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.
It worked! Thank you very much for the clear instructions.
It didn’t work with me my whole data is listed…
Is this Ubuntu or Debian specific or will it work on any Linux distro?
@Painter,
It will work on all Debian derivatives such as Ubuntu, Mint, etc…
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.