How to get the mount point of flash drive by using uuid?
I am beginner in ubuntu linux and i need to write simple bash script, that can identify necessary flash drive(which contains only one vfat partition) using uuid of this partition, and get the mount point of this flash drive.The /etc/fstab file does'nt contains mountig rule for this drive. For example, let partition uuid as 7DCD-9380 Using the readlink tool i can get device link in /dev catalog :
teddy@st1:~$ readlink -f /dev/disk/by-uuid/7DCD-9380
/dev/sdc1
But how i can get mount point of /dev/sdc1 device ?
Solution 1:
What you're after is findmnt
. For example:
$ findmnt -rn -S UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -o TARGET
/mnt/mountpoint
or
$ findmnt -rn -S PARTUUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -o TARGET
/mnt/mountpoint
If nothing is mounted matching that UUID, nothing is output and the return code is 1 (failure), otherwise, the mountpoint is output and the return code is 0 (success).
Explanation of options
-r, --raw use raw output format
-n, --noheadings don't print column headings
-S, --source <string> the device to mount (by name, maj:min,
LABEL=, UUID=, PARTUUID=, PARTLABEL=)
-o, --output <list> the output columns to be shown
Available columns:
...
TARGET mountpoint
...
Solution 2:
mount
knows this.
Example:
mount | grep /dev/sdc1
Or (likely to be faster):
grep '/dev/sdc1' /etc/mtab
Solution 3:
The kernel's mount table is at /proc/mounts
. This is slightly more reliable than /etc/mtab
, because a system/software error may result in the mtab
being corrupted or not written to when it should be.