Merge pull request #6267 from qhwdw/master

Translated by qhwdw
This commit is contained in:
Xingyu.Wang 2017-11-15 07:19:22 -06:00 committed by GitHub
commit 91e04f7ded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,30 +1,30 @@
Translating by qhwdw 4 Tools to Manage EXT2, EXT3 and EXT4 Health in Linux
Linux 中管理 EXT2、 EXT3 和 EXT4 健康状况的 4 个工具
============================================================
A filesystem is a data structure that helps to control how data is stored and retrieved on a computer system. A filesystem can also be considered as a physical (or extended) partition on a disk. If not well maintained and regularly monitored, it can become damaged or corrupted in the long run, in so many different ways.
一个文件系统是一个在电脑上帮你去管理数据怎么去存储和检索的数据结构。一个文件系统也可以认为是在磁盘上的物理(或扩展)分区。如果它没有很好地被维护或定期监视,它可能在长期运行中出现各种各样的错误或损坏。
There are several factors that can cause a filesystem to become unhealthy: system crashes, hardware or software malfunctions, buggy drivers and programs, tunning it incorrectly, overloading it with excessive data plus other minor glitches.
这里有几个可能导致文件系统出问题的因素:系统崩溃、硬件或软件故障、 有问题的驱动和程序、不正确的优化、大量的数据过载加上一些小故障。
Any of these issues can cause the Linux not to mount (or unmount) a filesystem gracefully, thus bringing about system failure.
这其中的任何一个问题都可以导致 Linux 不能完美地去加载(或卸载)一个文件系统,从而导致系统故障。
Read Also: [7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)][7]
扩展阅读:[Linux 中判断文件系统类型Ext2, Ext3 或 Ext4的 7 种方法][7]
In addition, running your system with an impaired filesystem may give rise to other runtime errors in operating system components or in user applications, which could escalate to severe data loss. To avoid suffering filesystem corruption or damage, you need to keep an eye on its health.
另外,一个受损的文件系统运行在你的系统上,可能导致操作系统中的组件或用户应用程序的运行时错误,它可能会进一步扩大到服务器数据的丢失。为避免文件系统错误或损坏,你需要去持续关注它的健康状况。
In this article, we will cover tools to monitor and maintain a ext2, ext3 and ext4 filesystems health. All the tools described here require root user privileges, therefore use the [sudo command][8]to run them.
在这篇文章中,我们将介绍去监视或维护一个 ext2、ext3 和 ext4 文件系统健康状况的工具。在这里描述的所有工具都需要一个 root 用户权限,因此,需要使用 [sudo 命令][8]去运行它们。
### How to View EXT2/EXT3/EXT4 Filesystem Information
### 怎么去查看 EXT2/EXT3/EXT4 文件系统信息
dumpe2fs is a command line tool used to dump ext2/ext3/ext4 filesystem information, mean it displays super block and blocks group information for the filesystem on device.
dumpe2fs 是一个命令行工具,用于去转储 ext2/ext3/ext4 文件系统信息,音味着它可以显示设备上文件系统的超级块和块组信息。
Before running dumpe2fs, make sure to run [df -hT][9] command to know the filesystem device names.
在运行 dumpe2fs 之前,先去运行 [df -hT][9] 命令,确保知道文件系统的设备名。
```
$ sudo dumpe2fs /dev/sda10
```
##### Sample Output
##### 示例输出
```
dumpe2fs 1.42.13 (17-May-2015)
@ -79,42 +79,42 @@ Journal sequence: 0x00580f0c
Journal start: 12055
```
You can pass the `-b` flag to display any blocks reserved as bad in the filesystem (no output implies to badblocks):
你可以通过 `-b` 标记去显示文件系统中的任何保留块,比如坏块(无输出说明没有坏块):
```
$ dumpe2fs -b
```
### Checking EXT2/EXT3/EXT4 Filesystems For Errors
### 检查 EXT2/EXT3/EXT4 文件系统的错误
e2fsck is used to examine ext2/ext3/ext4 filesystems for errors and fsck checks and can optionally [repair a Linux filesystem][10]; it is basically a front-end for a range of filesystem checkers (fsck.fstype for example fsck.ext3, fsck.sfx etc) offered under Linux.
e2fsck 是用于去检查 ext2/ext3/ext4 文件系统的错误并且 fsck 检查并可选去 [修复一个 Linux 文件系统][10];它实际上是底层 Linux 提供的一系列文件系统检查器 示例中的fsck.fstype、fsck.ext3、fsck.sfx 等等 的前端程序。
Remember that Linux runs e2fack/fsck automatically at system boot on partitions that are labeled for checking in /etc/fstab configuration file. This is normally done after a filesystem has not been unmounted cleanly.
记住在系统引导时Linux去检查 /etc/fstab 配置文件中的分区并自动运行 e2fsck/fsck。在一个文件系统没有被干净地卸载之后一般也会运行它。
Attention: Do not run e2fsck or fsck on mounted filesystems, always unmount a partition first before you can run these tools on it, as shown below.
注意不要在已加载的文件系统上运行 e2fsck  fsck在你运行这些工具之前首先要去卸载一个分区如下所示。
```
$ sudo unmount /dev/sda10
$ sudo fsck /dev/sda10
```
Alternatively, enable verbose output with the `-V` switch and use the `-t` to specify a filesystem type like this:
或者,使用 `-V` 开关去启用详细输出,并且使用 `-t` 去指定文件系统类型,像这样:
```
$ sudo fsck -Vt ext4 /dev/sda10
```
### Tunning EXT2/EXT3/EXT4 Filesystems
### 调优 EXT2/EXT3/EXT4 文件系统
We mentioned from the start that one of the causes of filesystem damage is incorrect tunning. You can use the tune2fs utility to change the tunable parameters of ext2/ext3/ext4 filesystems as explained below.
我们前面提到过导致文件系统损坏的其中一个因素就是不正确的调优。你可以使用 tune2fs 实用程序去改变 ext2/ext3/ext4 文件系统的可调优参数,像下面讲的那样。
To see the contents of the filesystem superblock, including the current values of the parameters, use the `-l` option as shown.
去查看文件系统的超级块,包括参数的当前值,使用 `-l` 选项,如下所示。
```
$ sudo tune2fs -l /dev/sda10
```
##### Sample Output
##### 示例输出
```
tune2fs 1.42.13 (17-May-2015)
@ -164,7 +164,7 @@ Directory Hash Seed: 9da5dafb-bded-494d-ba7f-5c0ff3d9b805
Journal backup: inode blocks
```
Next, using the `-c` flag, you can set the number of mounts after which the filesystem will be checked by e2fsck. This command instructs the system to run e2fsck against `/dev/sda10`after every 4 mounts.
接下来,使用 `-c` 标识,你可以设置文件系统通过 e2fsck 检查后加载的分区数量。这个命令指示系统每加载 4 个分区之后,去对 `/dev/sda10` 运行 e2fsck。
```
$ sudo tune2fs -c 4 /dev/sda10
@ -172,7 +172,7 @@ tune2fs 1.42.13 (17-May-2015)
Setting maximal mount count to 4
```
You can as well define the time between two filesystem checks with the `-i` option. The following command sets an interval of 2 days between filesystem checks.
你也可以在两个文件系统检查之间,使用 `-i` 选项去定义一个时间。下列的命令在文件系统检查之间设置了一个 2 天的时间间隔。
```
$ sudo tune2fs -i 2d /dev/sda10
@ -180,13 +180,13 @@ tune2fs 1.42.13 (17-May-2015)
Setting interval between checks to 172800 seconds
```
Now if you run this command below, the filesystem check interval for `/dev/sda10` is now set.
现在,如果你运行下面的命令,对 `/dev/sda10` 已经设置了文件系统检查的时间间隔。
```
$ sudo tune2fs -l /dev/sda10
```
##### Sample Output
##### 示例输出
```
Filesystem created: Sun Jul 31 16:19:36 2016
@ -211,31 +211,31 @@ Directory Hash Seed: 9da5dafb-bded-494d-ba7f-5c0ff3d9b805
Journal backup: inode blocks
```
To change the default journaling parameters, use the `-J` option. This option also has sub-options: size=journal-size (sets the journals size), device=external-journal (specifies the device on which its stored) and location=journal-location (defines the location of the journal).
去改变缺省的日志参数,使用 `-J` 选项。这个选项也有一个子选项 size=journal-size 设置日志的大小、device=external-journal 指定日志存储的设备 location=journal-location 定义日志的位置
Note that only one of the size or device options can be set for a filesystem:
注意,这里仅可以为文件系统设置一个日志大小或设备选项:
```
$ sudo tune2fs -J size=4MB /dev/sda10
```
Last but not least, the volume label of a filesystem can be set using the `-L` option as below.
最后,同样重要的是,可以去使用 `-L` 选项设置文件系统的卷标签,如下所示。
```
$ sudo tune2fs -L "ROOT" /dev/sda10
```
### Debug EXT2/EXT3/EXT4 Filesystems
### 调试 EXT2/EXT3/EXT4 文件系统
debugfs is an simple, interactive command line based ext2/ext3/ext4 filesystems debugger. It allows you to modify filesystem parameters interactively. To view sub-commands or requests, type `"?"`.
debugfs 是一个简单的、交互式的、基于 ext2/ext3/ext4 文件系统的命令行调试器。它允许你去交互式地修改文件系统参数。输入 `"?"`,去查看子命令或要求。
```
$ sudo debugfs /dev/sda10
```
By default, the filesystem should be opened in read-write mode, use the `-w` flag to open it in read-write mode. To open it in catastrophic mode, use the `-c` option.
缺省情况下,文件系统将以读写模式打开,使用 `-w` 标识去以读写模式打开它。使用 `-c` 选项以灾难catastrophic模式打开它。
##### Sample Output
##### 示例输出
```
debugfs 1.42.13 (17-May-2015)
@ -256,13 +256,13 @@ change_root_directory, chroot
....
```
To show free space fragmentation, use the freefrag request, like so.
去展示未使用空间的碎片,必须使用  `freefrag`,像这样。
```
debugfs: freefrag
```
##### Sample Output
##### 示例输出
```
Device: /dev/sda10
@ -297,11 +297,11 @@ Extent Size Range : Free extents Free Blocks Percent
debugfs:
```
You can explore so many other requests such as creating or removing files or directories, changing the current working directory and much more, by simply reading the brief description provided. To quit debugfs, use the `q` request.
通过去简单浏览提供的详细描述,你可以探索更多的其它需求,比如,创建或删除文件或目录,改变当前工作目录等等。去退出 debugfs使用 `q`
Thats all for now! We have a collection of related articles under different categories below, which you will find useful.
现在就这些!我们收集了不同分类下的相关文章,你可以在里面找到对你有用的内容。
#### Filesystem Usage Information:
#### 文件系统使用信息:
1. [12 Useful “df” Commands to Check Disk Space in Linux][1]
@ -309,7 +309,7 @@ Thats all for now! We have a collection of related articles under different c
3. [10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories][3]
#### Check Disk or Partition Health:
#### 检查磁盘或分区健康状况:
1. [3 Useful GUI and Terminal Based Linux Disk Scanning Tools][4]
@ -317,14 +317,14 @@ Thats all for now! We have a collection of related articles under different c
3. [How to Repair and Defragment Linux System Partitions and Directories][6]
Maintaining a healthy filesystem always improves the overall performance of your Linux system. If you have any questions or additional thoughts to share use the comment form below.
维护一个健康的文件系统可以提升你的 Linux 系统的整体性能。如果你有任何问题或更多的想法,可以使用下面的评论去分享。
--------------------------------------------------------------------------------
via: https://www.tecmint.com/manage-ext2-ext3-and-ext4-health-in-linux/
作者:[Aaron Kili][a]
译者:[译者ID](https://github.com/译者ID)
译者:[qhwdw](https://github.com/qhwdw)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出