• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

Fsck Command in Linux (Repair File System)

Written by Admin, Updated On December 10, 2022
fsck, terminal
Fsck Command in Linux (Repair File System)

The fsck command is used to check perform consistency and repair Linux file systems. It is useful to repair corrupted file systems when system fails to boot, or a partition cannot be mounted. We will discuss about the fsck command in this article.

Make sure you are logged in with root or user with sudo privileges.

How to Use fsck#

Following is the basic syntax of fsck command:

fsck [OPTIONS] [FILESYSTEM]

If you run the fsck command without any options, it will check the devices listed in the fstab file.

It’s recommended to always unmount the mounted partitions before attempting to check or repair file systems. It may damage your mounted file systems.

The fsck command accepts different options depending on the file system’s type. For example, to view the options available for fsck.ext4, type:

man fsck.ext4

Repair Corrupted File System#

It is a common use of the fsck command to repair a non-root corrupted ext3 or ext4 file system.

1. Find the device name using fdisk, df or any other tool to find.

2. Unmount the device:

sudo umount /dev/sdc1

3. Run fsck to repair the file system:

sudo fsck -p /dev/sdc1

Here, -p option is used to repair the problems automatically safely without user intervention.

4. When the file system is repaired, again mount the partition:

sudo mount /dev/sdc1

Repair Root File System#

In the current running system fsck command cannot check the root file system. You can set the fsck to run on boot, or use a live disk.

You also can run fsck command in recovery mode:

  • Go to the boot menu and choose Advanced Options
  • Select the Recovery mode and then “fsck”.
  • Choose “Yes” when it prompt to remount the root file system.
  • Once done, resume the normal boot.

To run fsck from a live distribution:

1. Boot the live distribution.

2. Use fdisk or parted to find the root partition name.

3. Open the terminal and run:

sudo fsck -p /dev/sda1

4. Once done, reboot the live distribution and boot your system.

Check File Systems on Boot#

Generally, all Linux distributions runs fsck at boot time, if a file system is marked as dirty.

Use the tune2fs tool to get the current mount count, check frequency number, check interval, and the time of the last check for a specific partition:

sudo tune2fs -l /dev/sdc1 | grep -i 'last checked|mount count'
Mount count:              392
Maximum mount count:      -1
Last checked:             Tue Oct 01 10:11:08 2019
Check interval:           0 (<none>)

In Maximum mount count shows the number of mounts after which the filesystem will be checked. If the value is 0 or -1 that means fsck will never run.

Check interval is the maximal time between two filesystem checks.

For example, you want to run fsck after every 15 boots or mounts, you would type:

sudo tune2fs -c 15 /dev/sdc1

You also can set the maximal time between two checks. For instance, to set two month run:

sudo tune2fs -i 2m /dev/sdc1

To force fsck to run at boot time on SystemD distributions pass the following kernel boot parameters:

fsck.mode=force
fsck.repair=yes

Conclusion#

The fsck is a command-line tool for checking and repairing Linux file systems. Visit the fsck man page or type man fsck in your terminal, to learn more about the fsck command.

If you have any questions or feedback, feel free to leave a comment.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article History Command in Linux (Bash History)
Next Article   How to Mount Windows Share on Linux using CIFS

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install PHP 8.2 on Debian 11
    How to Install PHP 8.2 on Debian 11 Linux February 24, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook