Open In App

How to Fix fsck File System errors in Ubuntu?

Last Updated : 27 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Experiencing file system errors on Ubuntu can be frustrating, but the fsck command in Ubuntu is a powerful tool that helps you fix these issues. If you're looking to fix fsck file system errors in Ubuntu, this guide will walk you through the steps of running fsck file system check and how to use it effectively to resolve file system errors in Ubuntu. By following these instructions, you can ensure that your system remains stable and your data is safe from corruption.

Prerequisites to fix fsck File System errors in Ubuntu

What is fsck in Ubuntu?

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 File system?

to check and repair filesystem, First 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
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:

  • Method 1: Force the fsck to the system root.
  • Method 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
Touch/force fsck.

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
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-GNU-GRUB
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.
select-fsck-from-the-menu
fsck option.

Step 5: Select the “Yes” option

  • Now you will have to select the yes option from the option menu.
Select-Yes-in-GNU-GRUB
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-process-finished
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

fsck-disk-check
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

Using the fsck command in Ubuntu is an essential part of system maintenance, especially when dealing with file system errors. Whether you need to run fsck on Ubuntu boot or perform a manual repair, understanding how to utilize fsck for file system repair will help you keep your system running smoothly. Make sure to run these checks periodically to avoid potential data loss or corruption in the future.


Next Article
Article Tags :

Similar Reads