Home Linux Commandline Tools How to Check/Repair Linux File System on Boot

How to Check/Repair Linux File System on Boot

An operating system user that is still a learner in the OS world can never escape the challenges the current elite users have overcome. The user impact of such challenges depends on the operating system flavor or distribution you are under.

For Linux users, you might think you are facing an impossible challenge only to realize that there are multiple valid solutions for every single OS problem faced.

[ You might also like: How to Backup Linux Filesystem Using dump Command ]

The Linux file system is a maze that most users hesitate to enter. It is because this file system is responsible for the performance consistency of your Linux operating system and any slight modification to its hierarchy or file system structure can be a nightmare for any user.

The FSCK Linux Command

The Linux operating system handles file system issues through the fsck command-line utility. It is a prepackaged file system check toolkit that interactively checks and repairs corrupted files that might affect the performance of your operating system.

$ man fsck

Most of the time, it is these corrupt files that are responsible for failed system boots and partition mounts.

FSCK Command Usage

The standard syntax for fsck command-line utility is as follows:

# fsck [OPTIONS] [FILESYSTEM]

You need to be a sudoer user or have sudo privileges to effectively use the FSCK tool.

FSCK adheres to some predefined rules.

  • It references the /etc/fstab file when a user does not provide [FILESYSTEM] as a command argument.
Linux fstab File
Linux fstab File

The <pass> column for the <mount point> (/) and <type> (ext4) is set to 1 because its file system checks and repair are prioritized.

It is not recommended to use the fsck command with mounted partitions as there is a high likelihood of permanent file system damage.

Repairing A Corrupted Linux File System

The first step is to identify the device partition that holds the Linux file system you would like to check and repair.

$ sudo fdisk -l
List Linux File System Partitions
List Linux File System Partitions

The second step is to unmount the device whose file system you want to check and repair. e.g.

$ sudo umount /dev/sda5

The third step is to check and possibly repair the device’s file system using FSCK.

$ sudo fsck -p /dev/sda5 

The -p command option is for automatic repair without any user intervention.

The final step is to re-mount your device once the fsck file system check and repair is complete.

$ sudo mount /dev/sda5 

Repairing Linux File System on Boot-Time

On a running machine, it is not possible to simultaneously check and repair your Linux file system while using the OS. In this case, we have the options of using a live CD/bootable usb drive or checking and repairing the Linux file system on boot (For installed Linux systems).

Linux File System Repair on Boot

1. Restart your machine, press [Esc] or [Shift] and select Advanced Options on the resulting boot menu.

Ubuntu Advanced Options
Ubuntu Advanced Options

2. Select Recovery Mode and choose the fsck option from the resulting list of menu options.

Ubuntu Recovery Mode
Ubuntu Recovery Mode

3. Hit [Enter] and choose the fsck menu option.

Ubuntu Fsck Option
Ubuntu Fsck Option

4. Choose Yes when asked whether to remount your OS root file system.

Mount Ubuntu Filesystem
Mount Ubuntu Filesystem

5. Once the file system check and repair is complete, direct your system to resume normal boot.

Resume Ubuntu Normal Boot
Resume Ubuntu Normal Boot

Live CD/USB File System Repair

  1. Boot into your machine from the live distribution (CD or USB).
  2. Open the Linux terminal and use sudo fdisk -l command to find the targeted Linux root partition name.
  3. If the root partition is identified by a name like /dev/sda1, running the following command will check and possibly repair its associated file system.
$ sudo fsck -p /dev/sda1 

FSCK is a very effective tool to get you started on understanding the nature and performance of your Linux system. The man fsck command has more options on using the FSCK utility to check and optionally repair broken or corrupt Linux file systems.

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.

8 thoughts on “How to Check/Repair Linux File System on Boot”

  1. I use a usb drive with “Parted Magic” or a live OS with “GParted” on it to check and repair filesystems. I find the terminal a bit dangerous for myself. With a GUI I know exactly what disk I am repairing.

    Reply
    • @James,

      GUI is always best for newbies, but when you are working on servers without GUI, here fsck plays important role in checking and repairing file systems for errors…

      Reply
  2. Does that work on NTFS file systems? How about FAT32, EXTFAT, FAT16, BTRFS, ZFS, or ReiserFS-4? What file systems does it NOT work for, if any?

    What things will it fix, and what will it NOT fix?

    This article leaves a LOT of questions unanswered!

    Reply
    • @William,

      The fsck utility supports all the Unix file systems. If you have NTFSProgs installed, you could be able to perform fsck on the NTFS file system as well…

      The fsck tool is used to fix potential system errors and generate reports.

      Reply
    • @Bill,

      There is an fsck.btrfs tool that is used to check the consistency of a btrfs filesystem, and optionally repairs them…

      For ZFS, it really does not need an fsck tool because the data on the disk is always perfect. If you still need fsck equivalent for ZFS there is a tool called fsck.zfs.

      Reply
  3. Creating ‘forcefsck‘ empty file at the root of a block device not working?

    > touch /forcefsck
    

    After reboot, the system will check the file system on the block device mounted on '/' before mounting.

    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.