Tip: Using UUID for mounting disks, the convenient way

Latest response

Hi everyone,

I just wanted to share a quick tip I just stumbled upon searching for a way to efficiently use the UUID when mounting disks.

Normally I would just use the blkid command to get the UUID of a particular disk.

blkid /dev/vda1

This involved, either copying the UUID, when possible, or typing it manually. Which is obvious error-prone .

Now I use the command blkid with some additional options

blkid /dev/vda1 -sUUID -ovalue

inside the mount command, as follows:

mount UUID=$(blkid /dev/vda1 -sUUID -ovalue) /mnt

Additional: When using vim one could use :r(ead)! from command mode, when editing /etc/fstab, for example, to insert UUID into file.

:r!blkid /dev/vda1 -sUUID -ovalue

Note: Swap all occurrences of /dev/vda1 and /mnt for your own values. :-)

Regards,
Peter

Responses