Open In App

How to fix fsck errors in Ubuntu?

The fsck tool is used widely by Linux and Ubuntu users for checking various types of errors that may occur in the filesystems, windows have a similar facility in which we can scan for broken disks and issues and try to fix them, similarly, the fsck is also used widely in the systems for checking and fixing errors.

Prerequisites

The fsck (file system consistency check) is a type of Linux utility that is used to check for filesystems for various types of errors and issues that may be present. The tool is mainly used for fixing errors and generating the reports for it. So in this article, we will understand this utility and its various commands.

How to Check and Repair Filesystem

First of all, let’s understand the basic syntax that is used for the fsck utility, following is the basic syntax for the fsck utility:



fsck <options> <filesystem>

There are various methods to check and fix errors in the Ubuntu system using the fsck utility lets understand each one by one.

Method 1: View Mounted Disks and Partitions

First, we will have to check whether the disks are mounted or not, for this we will have to run the following command:

df -h

This will give the following output:

df -h command.

To avoid this issue we will use the following command which will unmount the partition:

umount /dev/sdb

Note: This will not return anything but it will unmount the partition.

Understand the fsck Exit codes

Every time we run the fsck it will return an exit code so it is important to know the exit codes to have an understanding of what the return says, following are the exit codes with their description used in fsck:

Code

Description

0

No errors.

1

Filesystem errors corrected.

2

The system should be rebooted.

4

Filesystem errors were left uncorrected.

8

Operational error.

16

Usage or some type of syntax error.

32

Checking canceled by the user through request.

128

Shared-library error.

Running fsck for Checking Errors

Sometimes we may have to run the fsck on the partition which is also root in the system, since we can’t run any of the fsck commands when the partition is mounted then we can use one of the following methods:

1. Force the fsck to the system root.

2. Run the fsck in the rescue mode.

let’s understand each of these methods one by one:

Method 1: Force the fsck to the system root

This is very easy as compared to the other method, in this we only have to create a file named “forcefsck” inside of the root partition of our system, for this, we will use the following command:

touch /forcefsck

This will give us the following output:

touch /forcefsck.

Now you can use the various commands in the fsck to fix errors.

Method 2: Run the fsck in the rescue mode

This is a much lengthy process as compared to the 1st method, but still, let’s understand how we can use this method to run the fsck tool:

Step 1: Run Reboot Command

First, you need to reboot the system using the following command:

reboot

Step 2: Open Advanced options

Now once it’s in boot you will have to hold the shift key until the GNU GRUB menu shows and then we will have to select the “Advanced options” from the menu.

Advanced options for Ubuntu.

Step 3: Select Recovery Mode

From this menu, we will have to select the recovery mode as you can see in the image below:

Recovery Mode in GNU GRUB.

Step 4: Select the fsck from the menu

Now from this recovery menu, you will have to select the fsck option.

fsck option.

Step 5: Select the “Yes” option

Now you will have to select the yes option from the option menu.

Select the “Yes” option.

Step 6: Entering the fsck menu

This will lead us to the following menu, if you see a similar menu as well then you are not facing any errors.

fsck from util-linux.

Fix the Detected Error Automatically

Now we will have to run the fsck command to check for errors, for this, we will use the following command:

sudo fsck /dev/sda3

Fix Detected Errors Automatically with fsck

We can also fix any errors that occur automatically by using the following command:

sudo fsck -y /dev/sda3

This will give us the following output: understand LinuxunderstandLinux

Fix Detected Errors Automatically.

How to Skip Fsck on any Mounted Filesystems

If you want to skip any fsck for a specific filesystem from checking, then you will have to add -t and then you will add “no” before any particular filesystem, let’s understand with an example, if we want to skip ext3 filesystem then we can run the following command for this:

sudo fsck -AR -t noext3 -y

Note: This will not return something but instead it will automatically skip fsck checks on any mounted filesystems.

Conclusion

In this article, we understood what fsck utility is and looked at some of the methods to implement fsck and also understood how we can fix the errors in the Ubuntu system using the fsck utility tool, follow this article and you will have a good understanding about the fsck utility and how it’s used.

FAQs on How to Fix errors in Ubuntu

How do I run fsck to repair Linux file system errors?

You can enter the boot menu by simply pressing the shift key after rebooting your ubuntu system and then select the advance options from the menu and go to recovery mode, from here you can choose fsck to repair your linux file system’s errors.

How do I repair the filesystem in Ubuntu?

You can use the fsck tool which is used in ubuntu in order to fix different types of errors that we get in the linux filesystems such as ubuntu, you can run the fsck tool via terminal or by rebooting your system and entering the GNU menu by pressing shift button.

What is fsck on Ubuntu?

The fsck is a popular tool in ubuntu which is used for the purpose of fixing various types of file and file system errors in ubuntu and other linux distributions, we use fsck because it provides us various options to quickly solve the errors in the system.

How do I recover a corrupted Linux OS?

You can recover a corrupted linux OS by using the fsck tool in various situations such as when the system is not booting or when it is not possible to mount the partition etc.


Article Tags :