7

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?

  • 1
    Check if they return the same device when listing with ls -la. If that's the case, they are equivalent. However, I've always preferred /dev/mapper because it is easier to read and mentally sort in /etc/fstab (at least for me). – jaume Mar 1 '13 at 14:51
  • Thanks for the info. I especially appreciate you showing me how to find the info for myself. Both symlinks appear to point to the same device. – HayekSplosives Mar 1 '13 at 15:41
  • You're welcome, I've expanded my comment as an answer and added a reason as to why you should use /dev/mapper devices in /etc/fstab. Take a look at it. – jaume Mar 1 '13 at 18:55
8

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.

| improve this answer | |
  • I think the best method to mount partitions is using UUID instead of a fixed block device path in /etc/fstab. Because udev sets up these device files and if your udev is broken you have exactly the issue as you describe. Using UUID you didn't have these problems at all. – teissler Mar 2 '13 at 10:18
  • Yes, you can use UUIDs, but remember that mount looks for entries in /dev/disk/by-uuid/ (see man mount), which are symlinks to the device files. The symlinks are created by udev (find the specific rule grepping for "by-uuid" in /lib/udev/rules.d/ or /etc/udev/rules.d/), so when using UUIDs you depend on udev too. – jaume Mar 6 '13 at 12:39
  • This is probably the best and most comprehensive answer I've gotten. Thank you very much – HayekSplosives Mar 8 '13 at 17:58
1

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.

| improve this answer | |
1

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.

| improve this answer | |

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.