4

With GNOME Disks utility, I can check whether a logical volume is mounted:

enter image description here

And where is it mounted:

enter image description here

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.

9

Just use lsblk. It prints all disks and their corresponding mount points. Including LVM, MD RAID, etc.

1
  • I would mention the -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. – Peque Feb 15 '19 at 14:59
5

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.

1
  • Now I get it. What you propose is using the partition UUID. I was asking for the logical volume UUID in my question (the one you see with lvdisplay). I guess your solution is valid as well. – Peque Nov 12 '16 at 16:23
3

Having the UUID of a logical volume, find out whether it's mounted and where.

  1. Find out volume group name and logical volume name:

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.

  1. Now list all mounted device-backed file systems, and find your logical volume:

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
3
  • Thanks. It works very well. I will wait 24 hours before accepting, in case someone else wants to share a different approach. – Peque Nov 12 '16 at 15:42
  • if you have the UUID why not look up the disk in /dev/disk/by-uuid? Read the link then check if that disk is mounted. – Centimane Nov 12 '16 at 22:35
  • @Centimane Because only main LV extended partition is listed there, and this does not help. – LinuxSecurityFreak Nov 13 '16 at 7:32
0

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).

0
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.