Merge pull request #6783 from lujun9972/translate-MjAxNzEyMjYgQ2hlY2sgTGludXggZmlsZXN5c3RlbSBmb3IgZXJyb3JzLSBGU0NLIGNvbW1hbmQgd2l0aCBleGFtcGxlcy5tZAo=

translate done at 2017年 12月 27日 星期三 15:03:24 CST
This commit is contained in:
Vic Yu 2017-12-27 16:39:51 +08:00 committed by GitHub
commit 79357d83c4
2 changed files with 159 additions and 137 deletions

View File

@ -1,137 +0,0 @@
translating by lujun9972
Check Linux filesystem for errors: FSCK command with examples
======
FSCK is a very important Linux/Unix utility, it is used to check & repair the errors in the file system. It is similar to 'chkdsk' utility in Windows operating systems. It is available for Linux, MacOS, FreeBSD operating systems.
FSCK stands for File System Consistency Check & most of the times, it runs at boot time but can also be started manually by super user, if need arises.
It can be used with 3 modes of operation,
**1-** Check for errors & let the user decide what should be done with each error,
**2-** Check for errors & make repairs automatically, or,
**3-** Check for errors & display the error but does not perform any repairs.
**(Recommended Read:[Learn to use TCPDUMP command with examples][1])**
### Syntax for using FSCK
We can use the FSCK command manually with the following syntax,
**$ fsck options drives**
The options that can be used with fsck command are,
**-p ** Automatic repair (no questions)
**-n** Make no changes to the filesystem
**-y ** Assume "yes" to all questions
**-c** Check for bad blocks and add them to the badblock list
**-f ** Force checking even if filesystem is marked clean
**-v ** Be verbose
**-b ** superblock Use alternative superblock
**-B** blocksize Force blocksize when looking for superblock
**-j ** external_journal Set location of the external journal
**-l ** bad_blocks_file Add to badblocks list
**-L ** bad_blocks_file Set badblocks list
We can use any of the following options, depending on the operation we need to perform. Let's discuss some of the options of fsck command with examples.
### Fsck command with examples
**Note:-** Before we discuss any examples, please read this. We should not be using FSCK on mounted drives, as there will be high chances that fsck on mounted drive wll damage the drive permanently. So before performing fsck, we must un-mount the drive with the following command,
**$ umount drivename**
For example,
**$ umount /dev/sdb1**
You can check the partition number with the following command,
**$ fdisk -l**
Also while running the fsck, we might get some error codes. Below mentioned is the list of error codes that we might get along with their meanings,
**0** - No errors
**1** - Filesystem errors corrected
**2** - System should be rebooted
**4** - Filesystem errors left uncorrected
**8** - Operational error
**16** - Usage or syntax error
**32** - Fsck canceled by user request
**128** - Shared-library error
Now let's discuss usage of fdisk command with examples,
### Perform an error check on a single partition
To perform a file check on a single partition, run the following command from the terminal,
**$ umount /dev/sdb1**
**$ fsck /dev/sdb1**
### Check filesystem for errors & repair them automatically
Run the fsck command with 'a' option to perform consistency check & to repair them automatically, execute the following command. We can also use 'y' option in place of option 'a'.
**$ fsck -a /dev/sdb1**
### Check filesystem for errors but don't repait them
In case we only need to see the error that are occurring on our file system & dont need to repair them, than we should run fsck with option 'n',
**$ fsck -n /dev/sdb1**
### Perform an error check on all partitions
To perform a filesystem check for all partitions in single go, use fsck with 'A' option,
**$ fsck -A**
To disable the root file system check, we will use the option 'R'
**$ fsck -AR**
### Check only partition with mentioned filesystem
In order to run fsck on all the partitiions with mentioned filesystem type, for example 'ext4', use fsck with option 't' followed by filesystem type,
**$ fsck -t ext4 /dev/sdb1**
or
**$ fsck -t -A ext4**
### Perform consistency check only on unmounted drives
To make sure that the fsck is performed only on unmounted drives, we will use option 'M' while running fsck,
**$ fsck -AM**
This was our tutorial on fsck command with examples. Please feel free to send in your questions or queries to us, using the comment box below.
--------------------------------------------------------------------------------
via: http://linuxtechlab.com/linux-filesystem-errors-fsck-command-with-examples/
作者:[Shusain][a]
译者:[lujun9972](https://github.com/lujun9972)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linuxtechlab.com/author/shsuain/
[1]:http://linuxtechlab.com/learn-use-tcpdump-command-examples/

View File

@ -0,0 +1,159 @@
检查 Linux 文件系统中的错误:通过案例学习 FSCK 命令
======
FSCK 是一个很重要的 Linux/Unix 工具,它用于检测并修复文件系统中的错误。它类似于 Windows 操作系统中的 'chkdsk' 工具,但是是为 LinuxMacOSFreeBSD 操作系统所准备的。
FSCK 全称为 File System Consistency Check。在大多数时候它在系统启动时运行但是如果需要的话它也能被超级用户手工启动。
它可以进行三种模式的操作,
**1-** 查错并在发现错误时由用户决定如何处理,
**2-** 查错并自动修复,以及,
**3-** 查错但在发现错误时只显示错误而不进行修复。
**(推荐阅读:[通过案例学习 TCPDUMP 命令 ][1])**
### FSCK 的语法
手工执行 FSCK 的语法为,
```
$ fsck options drives
```
fsck 支持的选项有,
**-p ** 自动修复(不询问)
**-n ** 不对文件系统做出改动
**-y ** 多有所问题都回答 "yes"
**-c ** 检查所有的坏块并将之添加到坏块列表中
**-f ** 即使文件系统标记为 clean 也强制进行检查
**-v ** 输出详细信息
**-b ** superblock 使用替代的超级块
**-B ** blocksize 指定超级块的块大小
**-j ** external_journal 指定外部日志的位置
**-l ** bad_blocks_file 添加到指定的坏块列表(文件)
**-L ** bad_blocks_file 指定坏块列表(文件)
我们可以根据要做的操作任意指定这些选项。下面让我们来看一些例子。
### Fsck 命令的案例
**注意:-** 在开始讨论案例之前,请先读完这段话。我们不应用 FSCK 检查已挂载的磁盘,这很可能会对磁盘造成永久性的伤害。因此在开始使用 fsck 之前,我们需要使用下面命令来卸载磁盘,
```
$ umount drivename
```
比如像这样,
```
$ umount /dev/sdb1
```
可以通过下面命令来查看分区编号,
```
$ fdisk -l
```
另外,在运行 fsck 时,可能出错并返回一些错误码。下面是一些常见的错误及其意义的列表,
**0** - 没有错误
**1** - 修复了一些文件系统错误
**2** - 系统需要被重启
**4** - 文件系统错误未被修复
**8** - 操作错
**16** - 使用或语法错
**32** - Fsck 被用户取消
**128** - 共享库出错
现在让我们来看一些 fsck 命令的例子,
### 在单个分区上进行错误检查
在终端运行下面过命令来对单个分区进行检查run the following command from the terminal
```
$ umount /dev/sdb1
$ fsck /dev/sdb1
```
### 检查文件系统错误并自动修复
使用选项 a 进行一致性检查并会自动修复这些错误。也可以用 'y' 替代 'a' 选项。
```
$ fsck -a /dev/sdb1
```
### 检查文件系统错误但并不进行修复
若我们只想知道文件系统上有哪些错误而不想修复这些错误,那么可以使用选项 'n'
```
$ fsck -n /dev/sdb1
```
### 检查所有分区中的错误
'A' 选项一次性检查所有分区上的文件系统错误,
```
$ fsck -A
```
若要禁止检查对根进行检查可以使用选项 'R'
```
$ fsck -AR
```
### 只检查指定文件系统类型的分区
使用选项 t 跟上文件系统类型,可以让 fsck 只检查指定文件系统类型的分区,比如指定文件系统类型为 'ext4'
```
$ fsck -t ext4 /dev/sdb1
```
或者
```
$ fsck -t -A ext4
```
### 只在卸载的磁盘上进行一致性检查
要保证 fsck 只在卸载的磁盘上操作,可以使用选项 'M'
```
$ fsck -AM
```
这就是我们的案例教程了。有任何疑问欢迎在下面的留言框中留言。
--------------------------------------------------------------------------------
via: http://linuxtechlab.com/linux-filesystem-errors-fsck-command-with-examples/
作者:[Shusain][a]
译者:[lujun9972](https://github.com/lujun9972)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linuxtechlab.com/author/shsuain/
[1]:http://linuxtechlab.com/learn-use-tcpdump-command-examples/