# fstab

**fstab** 是 Unix 及类 Unix 系统上的 `/etc/fstab` 文件，一张描述系统可挂载的文件系统的静态表，包括本地磁盘、交换空间以及 NFS 等远程文件系统。程序读取该文件但不写入；创建和维护它是系统管理员的责任。记录的顺序很重要，因为 fsck、mount 和 umount 会按顺序处理该文件。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 位置与作用 | `/etc/fstab`，文件系统的静态信息；由 mount、umount、fsck、swapon 以及许多其他工具和守护进程读取<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup> |
| 行格式 | 六个以空白分隔的字段：`fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno`<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup> |
| 设备标识 | 推荐使用 `LABEL=` 或 `UUID=` 作为 `fs_spec` 的形式，因为 `/dev/sdb7` 等设备名取决于硬件检测顺序，在添加或移除磁盘时可能改变<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup> |
| 检查顺序 | 根文件系统的 `fs_passno` 为 1，其他为 2，0 表示不检查；不同驱动器上的文件系统并行检查<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup> |
| 备份字段 | `fs_freq` 由 dump(8) 用于确定哪些文件系统需要转储；默认为零（不转储）<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup> |
| systemd 集成 | `/etc/fstab` 中的条目在启动时和配置重新加载时由 systemd-fstab-generator 转换为原生挂载单元<sup>[2](https://cgit.freedesktop.org/systemd/systemd/tree/man/systemd.mount.xml?id=deb6120920e6341b1c16f5f088ab057358bb8fc4)</sup> |
| 历史 | fstab 文件格式的前身出现在 4.0BSD 中<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup> |

## 六个字段

每个文件系统在单独一行中描述，字段之间用制表符或空格分隔。字段内的空格或制表符必须转义为 `\040` 或 `\011`，即使在引号字符串内也是如此。以 `#` 开头的行是注释，空行被忽略。一个典型的条目如下：

```
LABEL=t-home2   /home      ext4    defaults,auto_da_alloc      0  2
```

**fs_spec。** 第一个字段指定挂载的内容：块特殊设备节点（如 `/dev/cdrom` 或 `/dev/sdb7`）、NFS 的 `host:dir` 形式的远程文件系统、交换文件或交换设备，或用于回环设备的文件系统镜像。对于没有后备存储的文件系统，可以使用任意字符串；典型用法是 procfs 用 `proc`，tmpfs 用 `mem`、`none` 或 `tmpfs`。udev 和 sysfs 等特殊文件系统通常根本不列在 fstab 中。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup>

该字段也可以不使用设备名，而使用 `LABEL=<label>`、`UUID=<uuid>`，或者对于 GUID 分区表磁盘，使用 `PARTUUID=` 或 `PARTLABEL=`。手册页推荐使用标识符而非设备名，因为设备名往往只是硬件检测顺序的巧合。mount 将 UUID 视为字符串，通常为小写，但 FAT 和 NTFS 文件系统的卷 ID 使用大写字符，例如 `UUID="A40D-85E7"`。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup>

**fs_file。** 第二个字段是挂载点。对于交换空间，应指定为 `none`。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup>

**fs_vfstype。** 第三个字段给出文件系统类型。Linux 支持许多类型，包括 ext4、xfs、btrfs、f2fs、vfat、ntfs、hfsplus、tmpfs、sysfs、proc、iso9660、udf、squashfs、nfs 和 cifs。条目 `swap` 表示用于交换的文件或分区，`none` 对于绑定挂载或移动挂载很有用。可以给出多个类型，用逗号分隔，文件系统子类型用 `.subtype` 后缀书写，例如 `fuse.sshfs`；较旧的前缀记法 `sshfs#example.com` 已弃用。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup>

**fs_mntops。** 第四个字段是逗号分隔的挂载选项列表，对于 mount 和 swapon 是可选的，不过通常的惯例是至少包含关键字 `defaults`。它通常包含挂载类型，`ro` 或 `rw`（默认为 `rw`），以及适合该文件系统类型的选项。基本的与文件系统无关的选项包括 `noauto`（使文件系统不参与 `mount -a` 运行，如启动时的运行）、`user` 和 `owner`（允许用户或设备所有者挂载）、`nofail`（设备不存在时抑制错误报告），以及 `comment` 或 `x-<name>`（供维护 fstab 的程序使用）。内核默认选项集通常为 `rw, suid, dev, exec, auto, nouser, async`；mount 本身没有硬编码的默认值。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup>

**fs_freq 和 fs_passno。** 第五个字段由 dump(8) 用于确定哪些文件系统需要转储，默认为零。第六个字段由 fsck(8) 用于确定启动时文件系统检查的顺序：根文件系统的 `fs_passno` 应为 1，其他文件系统为 2，值为零表示不检查该文件系统。同一驱动器上的文件系统按顺序检查，而不同驱动器上的文件系统同时检查以利用硬件的并行性。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup> fsck 手册页补充说，当多个文件系统共享同一趟次编号时，fsck 会尝试并行检查它们，同时避免对同一物理磁盘同时进行多项检查，常见的 1 和 2 配置正是让 fsck 自动并行化的原因。<sup>[3](https://man7.org/linux/man-pages/man8/fsck.8.html)</sup>

## 文件的使用方式

`mount -a` 命令通常从启动脚本运行，挂载 fstab 中提到的所有适当类型的文件系统，除了那些行中包含 `noauto` 关键字的文件系统；`-F` 选项使 mount 分叉，以便并行挂载文件系统。挂载 fstab 中列出的文件系统时，只需在命令行上给出设备或挂载点即可。可以使用 `mount --fstab path` 提供替代文件，该选项主要设计用于 initramfs 和 chroot 脚本；用户（非 root）挂载始终需要 fstab 来验证用户的权限。<sup>[4](https://www.man7.org/linux/man-pages/man8/mount.8.html?source=post_page---------------------------)</sup>

程序应通过 getmntent(3) 例程或 libmount 读取记录，而不是自行解析文件。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup> 作为文件系统类型的 `ignore` 关键字，曾经是标记未使用分区的一种方式，自 util-linux v2.22 起，基于纯 libmount 的 mount 工具已不再支持。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup>

## systemd 下的 fstab

在 systemd 系统上，`/etc/fstab` 中列出的挂载会在启动时以及系统管理器配置重新加载时动态转换为原生的挂载单元，通过 fstab 配置挂载点通常是首选方法。转换由 systemd-fstab-generator 完成。<sup>[2](https://cgit.freedesktop.org/systemd/systemd/tree/man/systemd.mount.xml?id=deb6120920e6341b1c16f5f088ab057358bb8fc4)</sup> 因此，fstab 手册页建议在修改文件后运行 `systemctl daemon-reload`。<sup>[1](https://man7.org/linux/man-pages/man5/fstab.5.html)</sup>

systemd 理解 fstab 中额外的 `x-systemd.*` 挂载选项，这些选项塑造生成的依赖图。`x-systemd.automount` 为文件系统创建自动挂载单元，`x-systemd.device-timeout=` 设置 systemd 在放弃该条目之前等待设备出现的时间；此选项只能在 `/etc/fstab` 中使用。挂载由 `local-fs.target` 或 `remote-fs.target` 拉入，取决于文件系统是本地还是远程，`nofail` 选项控制依赖是否为硬依赖。<sup>[2](https://cgit.freedesktop.org/systemd/systemd/tree/man/systemd.mount.xml?id=deb6120920e6341b1c16f5f088ab057358bb8fc4)</sup> `x-systemd.requires=` 和 `x-systemd.requires-mounts-for=` 等选项表达额外的依赖关系，对于具有外部日志设备的文件系统或需要先挂载底层文件系统的覆盖文件系统很有用。<sup>[5](https://cgit.freedesktop.org/systemd/systemd/tree/NEWS)</sup> 在启动期间，systemd 不调用 `fsck -A`；它单独调度挂载的激活，考虑设备、网络和其他依赖关系，因此会针对每个设备单独调用 fsck。<sup>[3](https://man7.org/linux/man-pages/man8/fsck.8.html)</sup>

## 远程文件系统

对于 NFS 挂载，fstab 行以 `server:path` 形式指定服务器和导出路径，并指定挂载点、文件系统类型和挂载选项。第五和第六个字段不被 NFS 使用，因此惯例上各包含数字零。服务器名可以是非限定主机名、完全限定域名、点分四段 IPv4 地址，或方括号中的 IPv6 地址。在 `/etc/fstab` 中使用 `nfs4` 文件系统类型已弃用，建议使用 `nfs`。<sup>[6](https://man7.org/linux/man-pages/man5/nfs.5.html)</sup>

## 各系统的变体

该格式在 BSD 家族中共享，但存在本地差异。OpenBSD 的 fstab(5) 保留相同的六个字段，但通过路径名或磁盘标签 UID（DUID）标识设备，支持从交换空间挂载的内存文件系统，并将 `fs_type` 为 `xx` 视为忽略的条目，这是一种记录未使用磁盘分区的方式；其 `fs_freq` 字段指定转储被视为过时之前的天数。<sup>[7](https://man.openbsd.org/fstab.5)</sup> SunOS 4.1.3 手册页描述了同一张表，以及 `/etc/mtab`（mount 和 umount 维护的当前已挂载文件系统文件），并指出文件系统的条目必须出现在其挂载点所在文件系统的条目之后。<sup>[8](https://man.freebsd.org/cgi/man.cgi?manpath=SunOS+4.1.3&query=fstab&sektion=5)</sup> [HP-UX](https://www.edgepedia.org/zh/hp-ux) 也使用该文件，趟次编号决定 fsck 顺序，某些类型的条目被 mount 和 fsck 忽略。<sup>[9](https://man.freebsd.org/cgi/man.cgi?manpath=HP-UX+11.11&query=fstab&sektion=4)</sup>

## References

1. [fstab(5) - Linux manual page, util-linux](https://man7.org/linux/man-pages/man5/fstab.5.html)
2. [systemd.mount(5), systemd source documentation](https://cgit.freedesktop.org/systemd/systemd/tree/man/systemd.mount.xml?id=deb6120920e6341b1c16f5f088ab057358bb8fc4)
3. [fsck(8) - Linux manual page, util-linux](https://man7.org/linux/man-pages/man8/fsck.8.html)
4. [mount(8) - Linux manual page, util-linux](https://www.man7.org/linux/man-pages/man8/mount.8.html?source=post_page---------------------------)
5. [NEWS - systemd/systemd, System and Session Manager](https://cgit.freedesktop.org/systemd/systemd/tree/NEWS)
6. [nfs(5) - Linux manual page](https://man7.org/linux/man-pages/man5/nfs.5.html)
7. [fstab(5) - OpenBSD manual pages](https://man.openbsd.org/fstab.5)
8. [fstab(5) - SunOS 4.1.3 manual page](https://man.freebsd.org/cgi/man.cgi?manpath=SunOS+4.1.3&query=fstab&sektion=5)
9. [fstab(4) - HP-UX 11.11 manual page](https://man.freebsd.org/cgi/man.cgi?manpath=HP-UX+11.11&query=fstab&sektion=4)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Operating systems › File systems

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/fstab

English original: https://www.edgepedia.org/fstab
