[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMarch 13, 2023

How to use Fsck Command.

 How To Use Fsck Command.

In this article, we will talk about the fsck command.

fsck (file system check) is a command-line utility that allows you to perform consistency checks and interactive repairs on one or more Linux file systems. It uses programs specific to the type of the file system it checks.

You can use the fsck command to repair corrupted file systems in situations where the system fails to boot, or a partition cannot be mounted.

 

How to Use fsck

The fsck command takes the following general form:

fsck [OPTIONS] [FILESYSTEM]

Only root or users with sudo privileges can clear the buffer.

When no FILESYSTEM is provided as an argument, fsck checks the devices listed in the fstab file.

Never run fsck on mounted partitions as it may damage the file system. Before attempting to check or repair file systems always unmount it first.

The fsck command is a wrapper for the various Linux filesystem checkers (fsck.*) and accepts different options depending on the file system’s type.

Check the manual pages for more information about a specific checker. For example, to view the options available for fsck.ext4, type:

man fsck.ext4

 

Repair Corrupted File System

The simplest use case of the fsck command is to repair a non-root corrupted ext3 or ext4 file system.

  1. If you don’t know the device name, use fdisk, df , or any other tool to find it.

  2. Unmount the device:

    sudo umount /dev/sdc1
  3. Run fsck to repair the file system:

    sudo fsck -p /dev/sdc1

    The -p option tells fsck to automatically repair any problems that can be safely fixed without user intervention.

  4. Once the file system is repaired, mount the partition:

    sudo mount /dev/sdc1

 

Repair Root File System

fsck cannot check the root file system on a running machine because it cannot be unmounted.

If you want to check or repair the root file system, you have several options at your disposal. You can set the fsck to run on boot, boot the system in recovery mode, or use a live CD.

To run fsck in recovery mode:

  1. Enter the boot menu and choose Advanced Options

  2. Select the Recovery mode and then “fsck”.

  3. When prompted to remount the root file system choose “Yes”.

  4. 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

On most Linux distributions, fsck runs at boot time if a file system is marked as dirty or after a certain number of boots or time.

To see the current mount count, check frequency number, check interval, and the time of the last check for a specific partition, use the tune2fs tool:

sudo tune2fs -l /dev/sdc1 | grep -i 'last checked\|mount count'
Mount count:              292
Maximum mount count:      -1
Last checked:             Tue Jul 24 11:10:07 2018
Check interval:           0 (<none>)
  • “Maximum mount count” is the number of mounts after which the filesystem will be checked. The value of 0 or -1 means that fsck will never run.

  • “Check interval” is the maximal time between two filesystem checks.

If for example, you want to run fsck after every 25 boots (mounts), type:

sudo tune2fs -c 25 /dev/sdc1

You can also set the maximal time between two checks. For example, to set it one month you would run:

sudo tune2fs -i 1m /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

On older distributions fsck will run on boot if the /forcefsck file is present:

sudo touch /forcefsck

 

fstab Options

fstab is a configuration file that tells the system how and where to mount the partitions.

The /etc/fstab file contains a list of entries in the following form:

 
# [File System] [Mount Point] [File System Type] [Options] [Dump] [PASS]
/dev/sda1       /             ext4               defaults  0      1
/dev/sda2       /home         ext4               defaults  0      2
server:/dir     /media/nfs    nfs                defaults  0      0

The last, 6th column ([PASS]) is the option that controls the order in which the file system checks are done at reboot time.

  • 0 – Do not check.

  • 1 – The file systems to be checked first and one at a time.

  • 2 – All other file systems which are checked later and possibly in parallel.

The root file system should have a value of 1, and all other file systems you want to be checked should have a value of 2.

 

Conclusion

fsck is a command-line tool for checking and optionally repairing Linux file systems.

Keep reading
How to use ioping command.
January 10, 2024

How to use ioping command.

What is ioping command: The ioping command is a tool used for measuring I/O (input/output) performance of a storage device, such as a hard drive or a solid-state drive (SSD). It is particularly useful for assessing the responsiveness and latency of storage systems. ioping sends I/O requests to the…

Read article
How to understand Data Collection in Linux Systems.
December 22, 2023

How to understand Data Collection in Linux Systems.

How to understand Data Collection in Linux Systems. Linux systems generate a wealth of information about their activities, performance, and security events. Understanding how to collect and analyze these data points is crucial for system administrators and IT professionals. In this comprehensive…

Read article
How to understand Pipes.
December 22, 2023

How to understand Pipes.

How to understand Pipes. Pipes in Linux are a powerful feature that facilitates communication between commands by allowing the output of one command to be used as the input for another. This seamless connection between processes enhances the flexibility and efficiency of command-line operations.…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00