fstab

Ubuntu 系统 fstab 指令,自动挂载硬碟磁区

/etc/fstab 档案的设定可以让系统知道在开机时需要自动载入什麽磁区,在系统开机时就直接可以

使用 UUID 挂载磁区到 fstab

使用 df 查询目前磁区挂载状况

$ df
档案系统          1K-区段       已用      可用 已用% 挂载点
udev             16296356          0  16296356    0% /dev
tmpfs             3263616     182148   3081468    6% /run
/dev/sda2      3841450248 2731170308 915122388   75% /
tmpfs            16318076          0  16318076    0% /dev/shm
tmpfs                5120          0      5120    0% /run/lock
tmpfs            16318076          0  16318076    0% /sys/fs/cgroup
tmpfs             3263616          0   3263616    0% /run/user/1010

使用 blkid 查询磁区的 UUID

$ blkid -s UUID
/dev/sda2: UUID="4fb9f563-7ae4-4df9-a028-fdc6b9e4f1a5"
/dev/sda3: UUID="cf0cf85a-6fed-4c43-901d-c946d6e1c5fa"

也可以到 /dev/disk/by-uuid 目录查询 UUID

$ ll /dev/disk/by-uuid
总计 0
drwxr-xr-x 2 root root  80 Aug 16 12:08 ./
drwxr-xr-x 6 root root 120 Aug 16 12:08 ../
lrwxrwxrwx 1 root root  10 Aug 16 12:09 4fb9f563-7ae4-4df9-a028-fdc6b9e4f1a5 -> ../../sda2
lrwxrwxrwx 1 root root  10 Aug 16 12:09 cf0cf85a-6fed-4c43-901d-c946d6e1c5fa -> ../../sda3

编辑 /etc/fstab 加入自动要载入的磁区

# /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda2 during installation
UUID=4fb9f563-7ae4-4df9-a028-fdc6b9e4f1a5 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda3 during installation
UUID=cf0cf85a-6fed-4c43-901d-c946d6e1c5fa none            swap    sw              0       0

/etc/fstab 各栏位说明*

顺序 栏位 说明
1 <file system> 档案系统或路径(UUID)
2 <mount point> 挂载点(e.g. /)
3 <type> 系统类型(e.g. ext4, swap)
4 <options> 挂载参数
5 <dump> 是否需要备份(0:不备份、1:每日备份、2:隔日备份)
6 <pass> 不正常关机,是否用 fsck 检查档案系统磁区(0:不检查、1:先检查、2:后检查),通常跟目录设定为 1,其他分割区设定为 2

参考资料