建立加載點
這個加載點是一個目錄。
sudo mkdir /mnt/data
查看分區情況
使用命令
sudo fdisk -l
下面是我的機器返回的數據。
$ sudo fdisk -l
Disk /dev/nvme0n1: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: D6C15E41-D668-412C-994D-FE3964207B0B
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System
/dev/nvme0n1p2 1050624 1000214527 999163904 476.4G Linux filesystem
Disk /dev/sda: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: AF732948-7B52-445F-8515-2D43DECD1391
Device Start End Sectors Size Type
/dev/sda1 34 32767 32734 16M Microsoft reserved
/dev/sda2 32768 3907026943 3906994176 1.8T Microsoft basic data
Partition 1 does not start on physical sector boundary.
根據上面的信息,我們可以看到,需要掛載的硬盤是 /dev/sda2,我們將掛載到 /mnt/data 中。
手動掛載硬盤
sudo mount /dev/sda2/ /mnt/data/
設置開機自動掛載
查詢掛載硬盤UUID
利用命令 sudo blkid /dev/sda2。
$ sudo blkid /dev/sda2
/dev/sda2: LABEL="data" UUID="009d8c29-b9e6-4846-a069-870b0bf1e3ba" TYPE="ext4" PARTLABEL="data" PARTUUID="2ba4e602-2ad3-4b91-986a-53ed46d46dbe"
從上面的反饋,我們可以看到兩個信息。
1、硬盤的 UUID。UUID="009d8c29-b9e6-4846-a069-870b0bf1e3ba"
2、硬盤的文件系統類型。 TYPE="ext4"
修改文件 fstab
打開 /etc/fstab 文件。
sudo vi /etc/fstab
在文件的最後添加需要掛載的硬盤信息。格式爲:
[UUID=************] [掛載磁盤分區] [掛載磁盤格式] 0 2
第一個數字:0 表示開機不檢查磁盤,1 表示開機檢查磁盤;
第二個數字:0 表示交換分區,1 代表啓動分區(Linux),2 表示普通分區。
最終的 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/nvme0n1p2 during installation
UUID=9de0e2ed-9b98-4b6e-a0fc-fc3cf0690ab7 / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=E184-7925 /boot/efi vfat umask=0077 0 1
/swapfile none swap sw 0 0
UUID=009d8c29-b9e6-4846-a069-870b0bf1e3ba /mnt/data ext4 defaults 0 2