1. 程式人生 > >ubuntu18.04 開機自動掛載第二塊硬碟到指定目錄

ubuntu18.04 開機自動掛載第二塊硬碟到指定目錄

ubuntu 開機後無法在終端中直接進入外掛硬碟目錄,需要在檔案管理器中點選訪問一下,系統才會真正的掛載。
可通過編輯/etc/fstab,新增自動掛載操作。

  1. 得到分割槽的UUID
    UUID的介紹:硬碟分割槽的UUID by - smstong
    感興趣的可以詳細閱讀一下。
    執行命令 blkid
[email protected]:~$ blkid
/dev/sda1: UUID="CE17-75D8" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="53a016a4-76aa-4fbf-ad9d-091ba5f47d17"
/dev/sda2: UUID="202IDC-r8D4-flZR-6GV0-0Or3-fxAz-ptPgYY" TYPE="LVM2_member" PARTUUID="77903296-aed3-4c07-a13c-991c019cd6a8"
/dev/sdb1: UUID="d2c70c37-de0d-48fe-9fcc-8600f6ece7d0" TYPE="ext4" PARTUUID="55452bf2-1528-48eb-9fc4-ef52369a9b78"
/dev/mapper/ubuntu--vg-root: UUID="d43d9024-6c92-4e33-a817-550364aa8122" TYPE="ext4"

記錄自己硬碟的UUID,例如我這裡是:d2c70c37-de0d-48fe-9fcc-8600f6ece7d0
2.編輯/etc/fstab 檔案,需要root許可權
新增一行:
UUID=d2c70c37-de0d-48fe-9fcc-8600f6ece7d0 /home/mark/sdb ext4 defaults 0 0

[email protected]:~$ cat /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>
/dev/mapper/ubuntu--vg-root /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=CE17-75D8  /boot/efi       vfat    umask=0077      0       1
/dev/mapper/ubuntu--vg-swap_1 none            swap    sw              0       0
# add by mark
UUID=d2c70c37-de0d-48fe-9fcc-8600f6ece7d0  /home/mark/sdb  ext4   defaults  0  0

關於fstab的介紹百度百科裡有:fstab【百度百科】