How to use the command fsck (with examples)

How to use the command fsck (with examples)

The fsck command is used to check the integrity of a filesystem or repair it. It is important to note that the filesystem should be unmounted at the time the command is run. This command is commonly used when there are concerns about the health of a filesystem and there may be damaged blocks that need to be repaired.

Use case 1: Check filesystem /dev/sdXN, reporting any damaged blocks

Code:

sudo fsck /dev/sdXN

Motivation: It is important to regularly check the health of a filesystem to identify and address any potential issues, such as damaged blocks. This use case allows us to perform a thorough check on the filesystem and report any damaged blocks that may need attention.

Explanation:

  • sudo: This command is often executed with administrative privileges, denoted by sudo, which allows the user to perform actions as a superuser or administrator.
  • fsck: The main command used to check the integrity of the filesystem.
  • /dev/sdXN: This argument specifies the location of the filesystem to be checked. Replace X with the appropriate drive identifier and N with the specific partition number.

Example output:

fsck from util-linux 2.36.2
e2fsck 1.45.6 (20-Mar-2020)
/dev/sdXN: clean, xx/xx files, xx/xx blocks

Use case 2: Check filesystem /dev/sdXN, reporting any damaged blocks and interactively letting the user choose to repair each one

Code:

sudo fsck -r /dev/sdXN

Motivation: This use case is useful when encountering damaged blocks on a filesystem and a user wants to have more control over the repair process. By using the -r flag, the command allows the user to manually choose whether to repair each damaged block.

Explanation:

  • sudo: To execute the fsck command with administrative privileges.
  • fsck: The main command used to check the integrity of the filesystem.
  • -r: This flag enables interactive mode, which prompts the user to choose whether to repair each damaged block.
  • /dev/sdXN: Specifies the location of the filesystem to be checked. Replace X with the appropriate drive identifier and N with the specific partition number.

Example output:

fsck from util-linux 2.36.2
e2fsck 1.45.6 (20-Mar-2020)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
...
Pass 5: Checking group summary information
/dev/sdXN: x/xx files, xx/xx blocks

Use case 3: Check filesystem /dev/sdXN, reporting any damaged blocks and automatically repairing them

Code:

sudo fsck -a /dev/sdXN

Motivation: In some cases, it may be preferable to automate the repair process when encountering damaged blocks on a filesystem. The -a flag allows the fsck command to automatically address and repair any damaged blocks it encounters during the check.

Explanation:

  • sudo: To execute the fsck command with administrative privileges.
  • fsck: The main command used to check the integrity of the filesystem.
  • -a: This flag enables automatic repair mode, allowing the command to automatically repair any damaged blocks encountered.
  • /dev/sdXN: Specifies the location of the filesystem to be checked. Replace X with the appropriate drive identifier and N with the specific partition number.

Example output:

fsck from util-linux 2.36.2
e2fsck 1.45.6 (20-Mar-2020)
/dev/sdXN: x/xx files, xx/xx blocks

Conclusion:

The fsck command is a powerful tool for checking the integrity of a filesystem and repairing any damaged blocks. It is important to regularly use this command to ensure the health and stability of your filesystems. With the provided examples, you can perform different types of checks and choose the most suitable option based on your needs and preferences.

Tags :

Related Posts

How to use the command 'osage' (with examples)

How to use the command 'osage' (with examples)

The ‘osage’ command is a part of the Graphviz software package and is used to render an image of a clustered network graph from a Graphviz file.

Read More
Using the "s" Command (with examples)

Using the "s" Command (with examples)

Introduction The “s” command is a powerful tool that allows you to perform web searches directly from your terminal.

Read More
How to use the command "qm wait" (with examples)

How to use the command "qm wait" (with examples)

The “qm wait” command is used to wait until a virtual machine is stopped in the Proxmox Virtual Environment (PVE).

Read More