LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-10-2021, 02:41 AM   #1
joemon83
Member
 
Registered: Jan 2009
Posts: 71

Rep: Reputation: 11
device mapper in LVM


Hi,

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 ?
 
Old 11-10-2021, 02:58 AM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
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.

From the Wikipedia article:
Quote:
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.

Last edited by shruggy; 11-10-2021 at 03:09 AM.
 
Old 11-10-2021, 04:01 AM   #3
joemon83
Member
 
Registered: Jan 2009
Posts: 71

Original Poster
Rep: Reputation: 11
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 ?
 
Old 11-10-2021, 04:37 AM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,904

Rep: Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025Reputation: 5025
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.

Hope that helps.

Last edited by GazL; 11-10-2021 at 04:39 AM.
 
Old 11-10-2021, 04:47 AM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
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.

Last edited by shruggy; 11-10-2021 at 06:11 AM.
 
1 members found this post helpful.
Old 11-10-2021, 05:00 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122
Erk - I remember the original LVM1. It's a wonder it ever progressed to an accepted tool - especially at such a critical point in the I/O stack.
 
Old 11-10-2021, 08:34 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
DM is a kernel-level block device driver which communicates with other block device drivers to actually perform the I/O.

The analogy with "virtual memory" is actually a very good one.
 
Old 11-10-2021, 09:44 PM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,781

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Quote:
Originally Posted by sundialsvcs View Post
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.
 
Old 11-18-2021, 08:48 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
device-mapper error running kpartx on a LVM karateckie Linux - Software 2 12-15-2009 04:13 PM
Is device-mapper necessary if you don't use LVM? raypen Linux - Software 1 06-23-2008 06:17 AM
LVM problems, device-mapper missing dworkin Linux - Newbie 3 03-22-2004 04:54 PM
lvm 2 device-mapper Kroenecker Linux - Newbie 4 12-29-2003 11:19 AM
LVM and device-mapper instalation- Help zick Linux - General 0 10-29-2003 10:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration