With GNOME Disks utility, I can check whether a logical volume is mounted:
And where is it mounted:
How can I get this information from the command line? Having, for example, the logical volume UUID, I would like to know if it is mounted and where.
Just use lsblk. It prints all disks and their corresponding mount points. Including LVM, MD RAID, etc.
-o MOUNTPOINT option if you are only interested in getting the mount point (that was the question). And the -n option to avoid printing the column names.
You may use this tool:
findmnt
To find all mount points or pipe it through grep, if you know device name, e.g.:
findmnt | grep hdd_vg
To find a specific UUID, just use:
findmnt -rn -S UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -o TARGET
To use this simple method, one needs to know the UUID of the partition.
Therefore the step by step guide would be:
ls -l /dev/mapper/
Then looking up its partition UUID with:
blkid /dev/dm-0
And finally just look up the mount point:
findmnt -rn -S UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -o TARGET
Example outputs:
ls -l /dev/mapper/
gives me:
total 0
crw------- 1 root root 10, 236 Nov 13 05:15 control
lrwxrwxrwx 1 root root 7 Nov 13 05:18 mint--vg-root -> ../dm-0
lrwxrwxrwx 1 root root 7 Nov 13 05:18 mint--vg-swap_1 -> ../dm-1
then:
blkid /dev/dm-0
gives me:
/dev/dm-0: UUID="32ee47f8-02df-481d-b731-6e67734999ca" TYPE="ext4"
and finally:
findmnt -rn -S UUID=32ee47f8-02df-481d-b731-6e67734999ca -o TARGET
gives me:
/
Which is the actual mount point in this VM.
lvdisplay). I guess your solution is valid as well.
Having the UUID of a logical volume, find out whether it's mounted and where.
sudo lvs -o vg_name,name,uuid
This will list all known logical volumes, with their UUIDs, names and the names of the volume group containing them. Remember the ‹vgname› and ‹lvname› corresponding to the given UUID.
findmnt -l | grep ' /dev/\S\+'
Simple script:
UUID='B3629a-B11c-4aec-bE1f-rUdk-a6d2-dd0a6bc'
LVName="$(
sudo lvs -o vg_name,name,uuid |
grep "$UUID" |
sed -e 's/^\s*\(\S\+\)\s\+\(\S\+\).*/\1-\2/'
)"
if [ -z "$LVName" ] ; then
echo "Cannot find logical volume with UUID=$UUID"
else
MountPoint="$(
findmnt -l |
grep " /dev/mapper/$LVName" |
awk '{ print $1 }'
)"
if [ -z "$MountPoint" ] ; then
echo "Logical volume /dev/mapper/$LVName with UUID $UUID is not mounted"
else
echo "Logical volume /dev/mapper/$LVName with UUID $UUID is mounted on $MountPoint"
fi
fi
/dev/disk/by-uuid? Read the link then check if that disk is mounted.
You could use blkid -U to get the block device from the UUID e.g.
blkid -U "897da7b7-edb1-4a6c-94e0-0a6175c89273"
/dev/mapper/vg0-lv0
and then use lsblk or findmnt to get the mount point - for example
lsblk -no MOUNTPOINT "$(blkid -U "897da7b7-edb1-4a6c-94e0-0a6175c89273")"
/storage/mythtv
findmnt "$(blkid -U "897da7b7-edb1-4a6c-94e0-0a6175c89273")"
TARGET SOURCE FSTYPE OPTIONS
/storage/mythtv /dev/mapper/vg0-lv0 xfs rw,noatime,attr2,delaylog,allocsize=5
/var/lib/mythtv /dev/mapper/vg0-lv0 xfs rw,noatime,attr2,delaylog,allocsize=5
(the second entry is a bind mount in this case).
If you're using device without lsblk and findmnt(for example: Oracle Enterprise Linux 5), and you can't access the internet in that device, use cat /etc/fstab or cat /proc/mounts.
You can't see the UUID, but you can see logical volume and where it's mounted.