Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am just trying to understand the role of device mapper in the working of LVM. Can someone please explain. If LVM metadata contains configuration details of volume groups, and it knows which physical disk to write to, doesn't it work like linux normal partition. What does LVM use device mapper for ? And is device mapper something that can be avoided while using LVM ?
No. AFAIK device mapper is required by LVM. Being a kernel driver, it's at a lower level than LVM. LVM doesn't speak to hardware directly, but via DM. This abstraction level allows you e.g. to use LVM on top of a software RAID provided by DM.
In the 2.6-series of the Linux Kernel, the LVM is implemented in terms of the device mapper, a simple block-level scheme for creating virtual block devices and mapping their contents onto other block devices. This minimizes the amount of relatively hard-to-debug kernel code needed to implement the LVM. It also allows its I/O redirection services to be shared with other volume managers (such as EVMS). Any LVM-specific code is pushed out into its user-space tools, which merely manipulate these mappings and reconstruct their state from on-disk metadata upon each invocation.
Yea, true. LVM cannot speak directly to hardware, but via DM.
But so is the case with normal partitions too.
The request goes to hardware via device drivers, just like any other hardware requests.
What does device mapper do, which device drivers cant ?
device-mapper is responsible for mapping blocks in a block device(s) into a virtual block device: much like the virtual memory system maps pages of physical memory into a virtual address space.
So, if stored on disk you have: AB........CD.........E.....F...
where each character represents a block of data.
Device mapper can make it look like a single contiguous block device, i.e. ABCDEF even when those blocks are spread across multiple devices.
lvm metadata is used to tell device-mapper which blocks will make up a given logical volume, but it's device-mapper that is doing the actual work of mapping them.
lvdisplay --maps or lvs --segments are good commands for seeing how the blocks of your lv are actually organised on disk.
Why not just do that in the device driver? The answer is that dev-mapper is an abstraction layer. The backing devices underneath it don't even have to be of the same type.
Historically, LVM1 in Linux 2.4.x didn't require DM. It provided its own kernel module, lvm-mod, instead. The LVM we have now is LVM2, and it does require DM to interface with the kernel.
DM is not used exclusively by LVM though. Once upon a time, there was a competing volume manager, EVMS, that also used the DM interface. DM allowed them to re-use much of the common infrastructure. Nowadays, it's used e.g. by Stratis. Beside volume management, DM has many other applications. It is used for software RAID, disk encryption, DM multipath, data integrity protection, etc. Rather than re-implementing the same functions in a separate driver for each task, they all make use of DM facilities.
If you're interested to know what exactly DM does, here is a good description. The RHEL 7 LVM Administration guide has even more details on it. And here is how DM and LVM2 started to be.
DM is a kernel-level block device driver which communicates with other block device drivers to actually perform the I/O.
And really, all it is doing is setting up the same type of map that the kernel uses, for example, to map offsets within a partition to actual major and minor device numbers and LBAs. It's using ONE mapping mechanism to perform the magic needed for a variety of features.
When you talk to "an LVM volume group," you talk to the mapper. The mapper then segregates your request into appropriate physical I/O requests which are sent by the mapper to the devices. The results are then reassembled if necessary and returned to you. This is the technology that maintains the LVM illusion.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.