LVM Difference in paths for mounts

So I can do the following:

mount /dev/datavg/datalv /mnt

or

mount /dev/mapper/datavg-datalv /mnt

Are these the same? Is their an advantage to one over the other? Is one better practice?


Solution 1:

To check whether they are the same see what ls -la lists for both files:

$ ls -l /dev/datavg/datalv 
lrwxrwxrwx 1 root root 25 2013-03-01 19:02 /dev/datavg/datalv -> /dev/mapper/datavg-datalv
$ ls -l /dev/mapper/datavg-datalv 
brw------- 1 root root 253, 0 2013-03-01 19:02 /dev/mapper/datavg-datalv

As you see, there's a small difference:

/dev/mapper/datavg-datalv is a device file while /dev/datavg/datalv is a symbolic link.

Although both paths they are interchangeable in commands like mount or fdisk:

# mount /dev/datavg/datalv /mnt
# mount /dev/mapper/datavg-datalv /mnt

my experience is that you should use the device file in /etc/fstab, for example:

/dev/mapper/datavg-datalv /mnt ext3 acl,user_xattr 1 2

How come I recommend this? A couple of years ago I had an issue with a server that didn't come up after a reboot and the cause was a missing device symlink for an LVM filesystem listed in /etc/fstab.

Solution 2:

Maybe this changed since the question was asked, but the man pages for LVM2 state (emphasis mine):

A directory bearing the name of each Volume Group is created under /dev when any of its Logical Volumes are activated. Each active Logical Volume is accessible from this directory as a symbolic link leading to a device node. Links or nodes in /dev/mapper are intended only for internal use and the precise format and escaping might change between releases and distributions. Other software and scripts should use the /dev/VolumeGroupName/LogicalVolumeName format to reduce the chance of needing amendment when the software is updated. Should you need to process the node names in /dev/mapper, you may use dmsetup splitname to separate out the original VG, LV and internal layer names.

Therefore, you should use mount /dev/datavg/datalv /mnt

Regarding dmsetup splitname:

   splitname device_name [subsystem]
          Splits given device name into subsystem constituents.   The  default  subsystem  is
          LVM.  LVM currently generates device names by concatenating the names of the Volume
          Group, Logical Volume and any internal Layer  with  a  hyphen  as  separator.   Any
          hyphens  within  the  names are doubled to escape them.  The precise encoding might
          change without notice in any future release, so  we  recommend  you  always  decode
          using the current version of this command.

Here's a usage example:

# dmsetup splitname /dev/mapper/datavg-datalv
VG                 LV         LVLayer
/dev/mapper/datavg datalv

Interestingly, on my system, /dev/mapper/datavg does not exist so I'm puzzled by that output.

Solution 3:

The answers above are spot-on about checking to see if they are identical. However, I have found a place where the syntax can make a difference for some flavors of Linux:

In Ubuntu 14.04, I've discovered that LVM isn't brought online automatically for mount points with a device path of /dev/VG/LV -- the device path must be in the form /dev/mapper/vg--lv before the system will bring up LVM (i.e. invoke vgscan/vgchange) at boot time.