Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check for errors in the Linux file system using the FSCK command

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to use the FSCK command to check errors in the Linux file system, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

The fsck command is used to check and attempt to fix errors in the file system. When an error occurs in the file system, you can use the fsck instruction to try to fix it.

FSCK is an important Linux/Unix tool that detects and fixes errors in the file system. It is similar to the "chkdsk" tool in the Windows operating system, but it is prepared for Linux, MacOS, and FreeBSD operating systems.

FSCK is called FileSystemConsistencyCheck. Most of the time, it runs when the system starts, but it can also be started manually by the superuser if necessary.

It can operate in three modes.

1. Check for errors and it is up to the user to decide what to do when errors are found

two。 Check for errors and fix them automatically

3. Check for errors but only show errors when they are found and do not fix them.

Syntax of FSCK

The syntax for manually executing FSCK is

1.$fsckoptionsdrives

The options supported by fsck are

-p automatic repair (do not ask)

-n No changes are made to the file system

-y answer "yes" to all questions

-c check all bad blocks and add them to the list of bad blocks

-f force a check even if the file system is marked as clean

-v output details

-bsuperblock uses alternative super blocks

-Bblocksize specifies the block size of the super block

-jexternal_journal specifies the location of the external log

-lbad_blocks_file is added to the specified list of bad blocks (file)

-Lbad_blocks_file specifies the list of bad blocks (file)

We can specify these options at will depending on what we want to do. Let's look at some examples.

Case of Fsck command

Note: please finish reading this paragraph before you begin to discuss the case. We should not use fsck to check mounted disks, which is likely to cause permanent damage to the disks. So before we start using fsck, we need to unmount the disk using the following command

1.$umountdrivename

Like this.

1.$umount/dev/sdb1

You can view the partition number with the following command

1.$fdisk-l

In addition, when you run fsck, you may make an error and return some error codes. Here is a list of some common errors and their meanings

0-No errors

1-fixed some file system errors

2-the system needs to be restarted

4-File system error not fixed

8-Operation error

16-usage or syntax error

32-fsck cancelled by user

128-shared library error

Now let's look at some examples of fsck commands.

Error checking on a single partition

Run the following command at the terminal to check a single partition

1.$umount/dev/sdb1

2.$fsck/dev/sdb1

Check for file system errors and automatically fix them

Use option-a to check for consistency and automatically fix these errors. You can also replace the-an option with-y.

$fsck-a/dev/sdb1

Check for file system errors but do not fix them

If we only want to know what errors are on the file system and do not want to fix them, we can use the option-n

$fsck-n/dev/sdb1

Check for errors in all partitions

The-An option checks for file system errors on all partitions at once

$fsck-A

To disable checking of the root file system, you can use the option-R

$fsck-AR

Check only partitions of the specified file system type

Using the option-t and the file system type, you can have fsck check only partitions of the specified file system type, such as "ext4"

$fsck-text4/dev/sdb1

Or

$fsck-t-Aext4

Consistency check is performed only on unmounted disks

To ensure that fsck operates only on unmounted disks, you can use the option-M

$fsck-AM

The above is how to use the FSCK command to check for errors in the Linux file system. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report