- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- LVM device special name
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2010 01:39 PM
02-05-2010 01:39 PM
In my system the special name for a LVM device is different in /etc/fstab than in /etc/mtab:
e.g. in /etc/fstab, it shows:
/dev/vg/space /space ......
e.g. in /etc/fstab, it shows:
/dev/mapper/vg-space /space ......
I wonder if there is an API can convert this two corresponding special names or at least if there is a fix pattern to transform between these two names?
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2010 01:47 PM
02-05-2010 01:47 PM
Re: LVM device special name
However, the transition from /dev/vgname/lvname to /dev/mapper/vgname-lvname seems relatively straightforward.
For example, here are some of mine:
cat /etc/mtab:
/dev/mapper/ediâ archive /archive ext3 rw,acl,user_xattr 0 0
/dev/mapper/ediâ gisprod /gisprod ext3 rw,acl,user_xattr 0 0
/dev/mapper/ediâ gistest /gistest ext3 rw,acl,user_xattr 0 0
/dev/mapper/ediâ oldarch /oldarch ext3 rw,acl,user_xattr 0 0
/dev/mapper/ediâ oraarch /oraarch ext3 rw,acl,user_xattr 0 0
/dev/mapper/ediâ oraback /oraback ext3 rw,acl,user_xattr 0 0
cat /etc/fstab:
/dev/edi/archive /archive ext3 acl,user_xattr 1 2
/dev/edi/gisprod /gisprod ext3 acl,user_xattr 1 2
/dev/edi/gistest /gistest ext3 acl,user_xattr 1 2
/dev/edi/oldarch /oldarch ext3 acl,user_xattr 1 2
/dev/edi/oraarch /oraarch ext3 acl,user_xattr 1 2
/dev/edi/oraback /oraback ext3 acl,user_xattr 1 2
Am I missing something in your question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2010 02:06 PM
02-05-2010 02:06 PM
Re: LVM device special name
It should be:
cat /etc/mtab:
/dev/mapper/edi-archive /archive ext3 rw,acl,user_xattr 0 0
/dev/mapper/edi-gisprod /gisprod ext3 rw,acl,user_xattr 0 0
/dev/mapper/edi-gistest /gistest ext3 rw,acl,user_xattr 0 0
/dev/mapper/edi-oldarch /oldarch ext3 rw,acl,user_xattr 0 0
/dev/mapper/edi-oraarch /oraarch ext3 rw,acl,user_xattr 0 0
/dev/mapper/edi-oraback /oraback ext3 rw,acl,user_xattr 0 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2010 02:18 PM
02-05-2010 02:18 PM
Re: LVM device special name
What I am trying to do is to write a program to convert the LVM special names. To minimize the risk I might encounter, I need to know if special names start with "/dev/mapper" are only for LVM devices but not other type of devices, and they always transform like that. I also wonder if there are any system APIs I could use to ease the programming.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2010 02:43 PM
02-05-2010 02:43 PM
Re: LVM device special name
# ls -l /dev/vg/space
lrwxrwxrwx 1 root root 20 Dec 8 09:29 /dev/vg/space -> /dev/mapper/vg-space
Now my problem would be easier if there is a function that takes the /etc/fstab device name as an in param and returns the /etc/mtab device name. The question is if this function exists?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2010 03:21 PM
02-05-2010 03:21 PM
Re: LVM device special name
Your help will be appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2010 11:09 AM
02-06-2010 11:09 AM
Solution/dev/
In a script, you could convert your /etc/fstab style name to /etc/mtab style (but not vice versa) with "readlink -f". For example, in your case:
readlink -f /dev/vg/space
should return:
/dev/mapper/vg-space
In a program, you can do the same with the readlink() system call.
If you wish to compare two names and see if they point to the same device, you can use the stat()/fstat() functions on both names and compare the stat structures returned. If both have the same st_rdev value, they both point to the same LV.
In a script, you could do something like this:
#!/bin/sh
FIRSTDEV=$(stat -L -c '%F.%t.%T' /dev/mapper/vg-space)
SECONDDEV=$(stat -L -c '%F.%t.%T' /dev/vg/space)
if [ "$FIRSTDEV" = "$SECONDDEV" ]; then
echo "Both names are referring to the same LV"
else
echo "The names point to different LVs, or to something completely different"
fi
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2010 11:43 AM
02-06-2010 11:43 AM
Re: LVM device special name
The /dev/mapper directory is the location where the _device-mapper subsystem_ maintains its persistent device names.
The device-mapper subsystem is a basic building block for various disk services, including (but not limited to):
- LVM (/dev/mapper/vg00-lvol1)
- disk encryption (/dev/mapper/sda2_crypt)
- multipathing (/dev/mapper/mpath1)
- software RAID
Each of these services can have its own naming pattern, and some of these services also create compatibility symlinks in other parts of the /dev hierarchy, for legacy compatibility or other reasons.
There is also /dev/mapper/control, the control device for the device-mapper subsystem itself.
So: no, not all devices in /dev/mapper always refer to LVM devices.
There is "dmsetup": a generic tool for listing and modifying all device-mapper mappings. Try "dmsetup ls --tree": if you have LVM and multipathing, or LVM and disk-encryption, this will display how they work together and what gets mapped into what.
Of course, the service-specific tools are usually more appropriate for common system administration needs.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2010 05:52 PM
02-06-2010 05:52 PM
Re: LVM device special name
There are a few more questions:
1. Is the /dev/
2. Which application decides those patterns in the two tab files? And which application actually edits those two tab files for LVM devices?
Thanks, for bearing with me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2010 01:42 AM
02-07-2010 01:42 AM
Re: LVM device special name
The mount command always canonicalizes the device name, by reading every symlink and replacing it with the real pathname. The canonicalized form is always used in /etc/mtab.
In /etc/fstab, it's also possible to identify a disk device by LABEL=
Use the "man fstab" command to get more information about the structure of the /etc/fstab file. If you are writing your own program, you might want to download the source code of the "mount" command and study the parts that are used to read /etc/fstab.
2.) The content of /etc/fstab is primarily for the "mount" command, but other administration tools may use the data too.
The /etc/fstab file is edited mostly by *you*, the sysadmin. You have the option of using all the helper programs you want.
Some desktop environments *may* include features that automatically add & remove entries to /etc/fstab for USB sticks and other hot-pluggable storage. The current preference seems to be to use HAL and dbus sub-systems for storing such hot-plug information instead of /etc/fstab, though.
If you use a GUI desktop that auto-manipulates /etc/fstab, it's your responsibility as a sysadmin to read the documentation so that you understand how that feature works. In a server system a GUI desktop environment can often be totally left out, so it might be a non-issue.
The /etc/mtab should normally be written by the "mount" command only. As long as the system is operating normally, there should be no need to make any other changes to the /etc/mtab file.
At boot time, the /etc/mtab file is completely cleared and then re-generated as each filesystem is mounted.
If the root filesystem is in read-only state (because of e.g. a hardware problem that affects the root filesystem), the information in /etc/mtab might be out of date. The /proc/mounts is another source for much of the same data, but it has the extra feature of being dynamically generated by the kernel, so it's never out of date.
The /etc/mtab and /proc/mounts files use the same format. The only difference is that when you've granted non-root users permission to mount some devices, /etc/mtab will store extra information to identify filesystems that have been mounted by a non-root user.
You then have the option to configure the system to allow the user-mounted filesystems to be unmounted only by the sysadmin or the user who originally mounted it. This is to prevent users interfering with each other in a multi-user system: user A might be trying to read files from a CD-ROM or memory stick, and user B might keep unmounting it.
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2010 06:12 PM
02-07-2010 06:12 PM
Re: LVM device special name
However, from what you have mentioned, if fstab uses LABEL=
My real intention is to search in mtab and try to match every FS in fstab. Originally it was written as:
for each line in fstab do
for each line in mtab do
if the mount point in fstab is exactly the same as the one in mtab then a match is found, go to the next line in fstab;
else if the device name in fstab is exactly the same as the one in mtab then a match is found, go to the next line in fstab;
else go to the next line in mtab.
The problem with the above code is, when a symlink is used in fstab for a LVM device, neither the corresponding mount points nor the corresponding device names are exactly the same. Hence the matching logic needs to be modified.
I think I still have another option to fix it. That is, to use the readlink function for a mount point in fstab, that should always return its real path which is listed in mtab, right? I try not to use lstat since it could hang on staled NFS.
Any suggestions will be appreciated!