# fstab

我们来看一下`/etc/fstab`文件一般长啥样

```
# device                dir             type            options         dump    pass 
/dev/sda                /               xfs             defaults        0       1
/dev/sdb                /data1          xfs             defaults        0       0
/dev/sdc                /data2          xfs             defaults        0       0
```

1、设备

第一列表示设备（官方管这一列叫文件系统，但是这一叫法太容易混淆，所以这里我管它叫设备），设备可以是一个硬盘（未分区），或者是一个分区（主分区、逻辑分区），或者是一个逻辑卷。

在`/etc/fstab`配置文件中你可以以三种不同的方法表示设备：内核名称、UUID 或者 label。使用 UUID 或是 label 的好处在于它们与磁盘顺序无关。如果你在 BIOS 中改变了你的存储设备顺序，或是重新拔插了存储设备，或是因为一些 BIOS 可能会随机地改变存储设备的顺序，那么用 UUID 或是 label 来表示将更有效可以用设备名，也可以使用设备的UUID。比如上面的例子有三块硬盘X、Y、Z，它们分别插在插槽1、2、3上，它们的内核名称分别叫`/dev/sda`、`/dev/sdb`与`/dev/sdc`，如果硬盘Y与Z更换一下插槽，那么硬盘Y的内核名称就会变成`/dev/sdc`，硬盘Z的内核名称就会变成`/dev/sdb`。

可以通过以下命令查看磁盘的UUID

```
$ blkid /dev/xxx
```

2、目录

将设备挂载到系统中哪个目录

3、文件系统类型

设备的文件系统类型，比如ext3、ext4、xfs。在挂载之前，必须先手动将设备格式化为某种文件系统类型。

4、选项

挂载的选项。

5、dump

此处为1的话，表示要将整个里的内容备份；为0的话，表示不备份。现在很少用到dump这个工具，在这里一般选0。

6、pass

`fsck`读取`pass`的数值来决定需要检查的文件系统的检查顺序。允许的数字是`0`、`1`和`2`。 根目录应当获得最高的优先权`1`, 其它所有需要被检查的设备设置为`2`。 `0`表示设备不会被`fsck`所检查

## Refenrence

\[1] <https://wiki.archlinux.org/index.php/Fstab_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87>)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pshizhsysu.gitbook.io/linux/ci-pan-yu-fen-qu/fstab.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
