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 file systems like ext2,ext3,ext4 etc. One of the most popular tool is fsck
tool. In this tutorial we will look general usage of fsck
Linux具有许多实用程序来管理,诊断,检查和更正不同类型的文件系统。 这些工具提供了很多功能,尤其是Linux本地文件系统,如EXT2,EXT3,EXT4等,其中最常用的工具是fsck
工具。 在本教程中,我们将研究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.
Fsck与其他Linux工具具有相似的语法,但是有一些区别,例如在命令末尾添加文件系统特定的选项,如下所示。
fsck [-lsAVRTMNP] [-r [fd]] [-C [fd]] [-t fstype] [filesystem...] [--] [fs-specific-options]
帮帮我 (Help)
$ fsck -h
fsck阶段(fsck Phases)
During the fsck following phases are evaluated. There 5 phases which will check different functionality of the file system and disk drive.
在fsck期间,将评估以下阶段。 有5个阶段,将检查文件系统和磁盘驱动器的不同功能。
phase 1
– Check Blocks and Sizesphase 1
–检查块和大小phase 2
– Check Path namesphase 2
–检查路径名称phase 3
– Check Connectivityphase 3
–检查连通性phase 4
– Check Reference Countsphase 4
–检查参考计数phase 5
– Check Cylinder Groupsphase 5
–检查气缸组
列出分区(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.
要使用fsck并修复磁盘和分区,我们需要知道并列出分区和磁盘。 有多种可用于列出分区的工具。 在此示例中,我们将使用parted列出分区和文件系统。
$ sudo parted -l
警告(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 operating 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.
Fsck提供了用于不同文件系统的子工具。 文件系统是一种操作系统级别的系统,用于以便利的方式将文件,文件夹,图片和数据存储到HDD,SSD等存储中。 Ext3与ext4不同,它们通常具有不同的工作工具。 Fsck将根据文件系统类型自动选择相关工具。
$ sudo fsck /dev/vdb1
退出码(Exit Codes)
While using fsck there will be some errors, warnings or messages about the operations. Below are some of them
使用fsck时,会出现一些有关操作的错误,警告或消息。 以下是其中一些
- 0 – No errors0 –无错误
- 1 – File system errors corrected1 –文件系统错误已更正
- 2 – System should be rebooted2 –系统应重新启动
- 4 – File System errors left uncorrected4 –文件系统错误未得到纠正
- 8 – Operational error8 –操作错误
- 16 – Usage or syntax error16 –使用或语法错误
- 32 – Fsck canceled by user request32 – Fsck被用户请求取消
- 128 – Shared-library error128 –共享库错误
检查特定文件系统 (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.
在前面的示例中,我们以通用方式使用fsck,fsck决定了指定分区的文件系统,并据此选择了文件系统。 有一种方法可以专门确定文件系统。 我们有以下选择。 编写fsck
制表符将列出可用的选项,如下所示。
$ fsck
检查所有文件系统(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
有效检查文件系统的另一种方法是在一个命令中检查它们。 但是有一些配置可以选择分区。 fsck将查找/etc/fstab
文件以检查文件系统。 如果文件系统未在fstab中列出,则不会进行检查。 让我们用以下命令查看我们当前的fstab内容
$ cat /etc/fstab
And now we will use -A
options to check all file systems listen in fstab file.
现在,我们将使用-A
选项来检查所有文件系统在fstab文件中的侦听。
$ sudo fsck -A
As we can see from above screenshot vda1
partition is all ready mounted and can not checked.
从上面的屏幕截图中可以看到, vda1
分区已全部安装好,无法检查。
不检查已挂载的文件系统 (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.
检查已挂载的文件系统会产生问题。 因此,默认情况下阻止检查已安装的文件系统是最佳实践。 -M
选项可用于防止装入的文件系统以防止出现问题。
$ fsck -M /dev/vdb1
不显示标题(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.
在检查文件系统时,fsck将在检查开始时提供一些称为标题的信息。 如果我们只希望提供fsck的实际操作数据,则此信息可能会出现问题。 可以使用-T
选项跳过此标题信息。
$ fsck -T /dev/vdb1
自动修复问题(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.
检查文件系统时,可能会有很多错误要修复。 对于每个错误,我们都会询问是否要修复此错误。 如果要解决10.000个错误,这将非常困难。 Fsck为这种情况提供了一种简单的解决方法。 可以提供-y
选项来自动修复错误,而无需一一回答所有错误。
$ fsck -y /dev/vdb1
不修复只是报告(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.
有时我们可能只需要获取有关错误和损坏的报告。 Fsck提供的选项仅用于报告目的,没有修复错误。 -n
选项提供此功能。
$ fsck -n /dev/vdb1
翻译自: https://www.poftut.com/linux-fsck-command-tutorial-with-examples/