Tip: Using UUID for mounting disks, the convenient way
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
Hi peter,
Thanks for your information. is usefull one when we mount the ciritical filesystems.
Regards,
Ramkumar A
Mount-by-UUID is an ok solution, but it makes your /etc/fstab kind of horrible to try to read. It's a lot "friendlier" to either control your block-devices via LVM2 and mount by the LVM2 object-pathname, use multipathd's friendly-name mapping option and mount by it's "friendly" pathname, or assign a label to the device and reference your block-device with LABEL= directives.
The other examples seem useful, but I think this is just overcomplicating things:
mount UUID=$(blkid /dev/vda1 -sUUID -ovalue) /mnt
You'll need to know the current name of the block device for the blkid command anyway, so why not skip the middleman and just use it with the mount command?
I don't see any benefit at all in the use of UUID in this case.
When you mount a filesystem by UUID, the mount command will just look up the corresponding device name and using it for the actual mount operation, which you can confirm by looking at /proc/mounts: all mounted filesystems, whether they are mounted using block device names or LABEL= or UUID= directives, will be listed by device names. The UUID is not stored by the kernel.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
