Mount a disk partition using the UUID in linux.
- May 10th, 2021
- Write comment
I was mounting an external drive using the partition device file. I found that over time the mounted partition would give an I/O error. It turned out it was because the device file had changed. I decided to mount it using UUID to see if took care of the issue.
Here what I did to mount it and add it to the startup:
# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): p
Disk /dev/sdc: 3.7 TiB, 4000787029504 bytes, 7814037167 sectors
Disk model: One Touch HDD
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: E396A756-646C-40DC-A8F8-59CC11D40FA8Device Start End Sectors Size Type
/dev/sdc1 2048 7814035455 7814033408 3.7T Linux filesystemCommand (m for help): quit
Use this command to determine the UUID:
# blkid
…
/dev/sdc1: UUID=”20f17e14-71c3-498f-8872-97dcd80c1d3e” TYPE=”ext4″ PARTUUID=”ccbd82af-94e0-431a-a54b-b9100a087133″
…
You can use lsblk as well:
# lsblk -fs
NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINT
…
sdc1 ext4 20f17e14-71c3-498f-8872-97dcd80c1d3e
└─sdc
…
Add the entry to the fstab:
# vi /etc/fstab
…
UUID=20f17e14-71c3-498f-8872-97dcd80c1d3e /external ext4 defaults 0 0
Then mount it:
# mount /external