Mounting Drives to Static Mount Point by UUID

I’ve found the simplest way to consistently mount a removable drive – in this case two external Seagate spinners, to a fixed path as follows:

1
vi /etc/fstab

You can retrieve your drive’s UUID with the blkid command:

1
2
3
4
5
6
7
8
9
[root@nuuk /]# blkid
/dev/mapper/centos-root: UUID="6d76a0d8-fdc2-4e28-aa76-34a9c759d922" TYPE="xfs"
/dev/sda2: UUID="Zjfdde-pPX6-yWSh-VDQX-0Q0h-HAFE-hexAVI" TYPE="LVM2_member"
/dev/sda1: UUID="5cd945c2-5ca7-48c5-b67b-0f3610534e8f" TYPE="xfs"
/dev/sdd1: UUID="35cc9bad-565a-4192-9586-9fe41135de86" TYPE="xfs" PARTUUID="58ac1180-3638-4fae-994c-3fdf45587199"
/dev/sdc1: LABEL="usb_drive1" UUID="8ca92e8d-8ea7-4bf5-8c6e-df966adb3cf7" TYPE="ext4"
/dev/sdb1: LABEL="usb_drive3" UUID="05d7f9c8-3243-4980-a920-91fa18bc8590" TYPE="ext4"
/dev/mapper/centos-swap: UUID="876fd1b6-bc46-4a02-9843-c21c0fa9c115" TYPE="swap"
/dev/mapper/centos-home: UUID="e5a23e29-9dd7-4baf-8bc2-1ff33e6df881" TYPE="xfs"

And add the following lines to /etc/fstab replacing the UUIDs retrieved from the previous step.

1
2
3
UUID=8ca92e8d-8ea7-4bf5-8c6e-df966adb3cf7 /media/usb_drive1 ext4 defaults 0 1
UUID=05d7f9c8-3243-4980-a920-91fa18bc8590 /media/usb_drive3 ext4 defaults 0 1
UUID=35cc9bad-565a-4192-9586-9fe41135de86 /media/usb_drive2 xfs defaults 0 1

My result looks like this….save and reboot:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#
# /etc/fstab
# Created by anaconda on Thu Jan 31 19:49:31 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=5cd945c2-5ca7-48c5-b67b-0f3610534e8f /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0

UUID=8ca92e8d-8ea7-4bf5-8c6e-df966adb3cf7 /media/usb_drive1 ext4 defaults 0 1
UUID=05d7f9c8-3243-4980-a920-91fa18bc8590 /media/usb_drive3 ext4 defaults 0 1
UUID=35cc9bad-565a-4192-9586-9fe41135de86 /media/usb_drive2 xfs defaults 0 1

The same method can be used to mount iSCSI luns as well.

Lima

About the author

Lima is the visual nautical indicator for "stop instantly."

Leave a Reply