Linux fsck Command Tutorial With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-fsck-command-tutorial-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

Linux have a lot of utilities to manage, diagnose, check and correct different type of file  systems. these utilities provide a lot of features especially Linux native filesystems like ext2,ext3,ext4 etc. One of the most popular tool is fsck tool. In this tutorial we will look general usage of fsck

Syntax

Fsck have similar syntax with other Linux tools but have some difference like adding file system specific options to the end of command as we can see below.

Help

Help
Help

List Partitions

To work with fsck and fix the disks and partitions we need to know and list the partitions and disks. There  are different tools those can be used to list partitions. In this example we will use parted to list partitions and file systems.

 List Partitions
List Partitions

Warning

While interacting with tools related file system be cautious. Because mounted file systems are error prone. Prefer using these tools on a unmounted partitions for more safety.

Check Partition

Fsck provides sub tools for different file systems. File system is an oprating system level system used to store files, folders, pictures and data into storage like HDD, SSD in a convenient manner. Ext3 is different then ext4 and they have generally different tools to work. Fsck will automatically select related tool according to file system type.

Check Partition
Check Partition

Exit Codes

While using fsck there will be some errors, warnings or messages about the operations. Below are some of them

  • 0 – No errors
  • 1 – Filesystem errors corrected
  • 2 – System should be rebooted
  • 4 – File System errors left uncorrected
  • 8 – Operational error
  • 16 – Usage or syntax error
  • 32 – Fsck canceled by user request
  • 128 – Shared-library error
LEARN MORE  Direct and Reverse Ip Look Up With Nslookup

Check Specific File System

In previous example we have used fsck in a generic way that fsck decided the file system of the specified partitions and selected file system accordingly. There is a way to specifically decided the file system. We have following options . After writing fsck tabbing will list available options like below.

Check Specific File System
Check Specific File System

Check All File Systems

Another option to effectively check file systems is check them in one command. But there are some configuration to select partitions. fsck will look /etc/fstab file to check file systems. If a file system is not listed in fstab it will be not checked. Let’s look our current fstab content with the following command

Check All File Systems
Check All File Systems

And now we will use -A options to check all file systems listen in fstab file.

As we can see from above screenshot vda1 partition is all ready mounted and can not checked.

Do Not Check Mounted File Systems

Checking mounted file systems can create problems. So preventing check of mounted file system by default is the best practice. -M option can be used to prevent mounted file systems to prevent problems.

Do not Check Mounted File Systems
Do not Check Mounted File Systems

Do Not Display Title

While checking  file systems fsck will provide some information called title in the begging of the check. This information can be problem if we only want actual operation data provided fsck. This title information can be skipped with -T option.

Do Not Display Title
Do Not Display Title

Automatically Fix Problems

While checking file system there may be a lot of errors to fix. For each error one by one a question will be asked to us whether we want to fix this error. If there are 10.000 errors to fix this will be very hard job. Fsck provides a simple work around for this situation. -y option can be provided to automatically fix the errors without answering all of them one by one.

LEARN MORE  Killing Linux Processes With killall Command

Do Not Fix Just Report

Some time we may need to only get report about errors and corrupts. Fsck provides options for only reporting purposes without fixing errors. -n option provides this feature.

Do Not Fix Just Report
Do Not Fix Just Report
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-fsck-command-tutorial-with-examples/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.