Getting Started with Linux /etc/fstab File
Ubuntu: 20.04
在 Linux 系統中會有一個 /etc/fstab 的檔案,其全名為 Filesystem Table,它主要是負責紀錄硬碟與掛載目錄的對應。
在早期,如果要掛載硬碟到特定目錄時,必須手動使用 mount 指令執行,且在重啟系統以後又要再來一次。如果透過 /etc/fstab 控制相關的資訊的話,一來不需要每次都重新掛載,二來在管理上也非常方便。
Basic Usage
在使用之前,必須先瞭解 fstab 的欄位。
Structure
# <file system> <mount point> <type> <options> <dump> <pass>
fstab 主要有六個欄位:
File System: 需要掛載的裝置(硬碟、Partitions、外接光碟機等等)。Mount Point: 要掛載的目錄。Type: 檔案系統型別,像是ext4、xfs等等。Options: 開機自動載入時的相關細部設定,例如限制讀寫許可權等等。Backup Operation(Dump): 備份設定,1為備份,0為否。File System Check Order(Pass): 用來判斷是否在掛載前執行fsck,有三種選項:0: 不檢查 Filesystem1: 最高優先檢查 Filesystem,通常用於根目錄的 Partition2: 最後檢查 Filesystem
Example
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/sda / ext4 errors=remount-ro 0 1
UUID=68434ede-ef44-4f3b-8ede-e5a27a68857e /mogdata/dev3268 ext4 rw,noatime,nodiratime 2 2
UUID=039ac52a-7c7f-486d-abff-ffa789b6eb34 /mogdata/dev3274 ext4 rw,noatime,nodiratime 2 2