Linux Admin Reference – Understand Device Mapper and DM-Multipath – Red Hat Enterprise Linux
Other Learning Articles that you may like to read
Free Courses We Offer
Paid Training Courses we Offer
Device-mapper is a very important component of Linux 2.6 kernel. It is used for many critical storage related applications, such as LVM2, Linux native multipath tool device-mapper-multipath, device-mapper software RAID, etc. A solid understanding of device-mapper helps system administrators to investigate various kinds of issues with these applications.
In the Linux kernel, the device-mapper is a generic framework to map one block device into another. It is not just for LVM2. By using device-mapper, the kernel provides general services to dm-multipath, LVM2 and EVMS, device-mapper software RAIDs, dm-crypt disk encryption and offers additional features such as file system snapshots.
In device-mapper architecture there are three important concepts to be familiarized
1. Mapped Device
2. Mapping Table
3. Target Device
Mapped device is a logical device provided by device-mapper driver. It provides an interface to operate on. The logical volumes in LVM2 and pseudo disks in dm-multipath are good examples of mapped devices.
- Reference 1 – Linux Admin Reference for LVM2 Administration
- Reference 2 – Linux Admin Reference for Advanced LVM2 Administration
Mapping table represents a mappi
ng from a mapped device to target devices. One table can be seen as an group of variables including mapped device’s starting address, length and target device’s physical device, starting address, length. The unit used here is a sector (512 bytes). The command “dmsetup create” will create such a table with parameters provided.
Target device is a modularized plugin. The device-mapper filters and redirects I/O requests with it. some good examples for target devices
- linear for LVM2
- mirror for RAID
- stripped for LVM2
- snapshot for LVM2
- multipath for dm-multipath
How application deals with device mapper
Device-mapper works by processing data passed in from a virtual block device, that it itself provides, and then passing it on to another block device.
Applications (like dm_multipath and LVM2) that want to create new mapped devices talk to the Device-mapper via the libdevmapper.so shared library, which in turn issues ioctls to the /dev/mapper/control device node.
What is DM-Multipath
Device-Mapper Multipath (DM-Multipath) is a Linux native multipath tool, which allows you to configure multiple I/O paths between server nodes and storage arrays into a single device. These I/O paths are physical SAN connections that can include separate cables, switches, and controllers. Multipathing aggregates the I/O paths, creating a new device that consists of the aggregated paths.
Create partitions and file system on DM-Multipath devices
The DM-Multipath devices will be created as /dev/mapper/mpathN, where N is the multipath group number. Use command fdisk to create partitions on /dev/mapper/mpathN:
# fdisk /dev/mapper/mpath0
Command (m for help): n
p primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-1017, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1017, default 1017):
Using default value 1017
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Important Notes to use DM-Multipath devices in your storage configurations:
The DM-Multipath tool uses three different sets of file names:
NEVER use /dev/dm-N devices, as they are only intended to be used by the DM-Multipath tool.
NEVER use /dev/mpath/mpathNdevices, because when multipath devices are mounted at boot time , the UDEV subsystem may not create the device nodes soon enough.
ALWAYS use /dev/mapper/mpathN devices, as they are persistent and they are automatically created by device-mapper early in the boot process. Therefore these are the device names that should be used to access the multipathed devices. But in a RAC (Real Application Clustrer) configuration, although /dev/mapper/mpathN names may be persistent across reboots on a single machine, there is no guarantee that other cluster nodes will use the same name for this disk. If this is desired, then we should use the UDEV facility to get cluster-wide persistent names.
- Additional Reference to work with Linux Storage with Multipath- San Storage Migration in Linux
Register multipath partitions in /dev/mapper:
# kpartx -a /dev/mapper/mpath0
List all partitions on this device:
# kpartx -l /dev/mapper/mpath0
mpath0p1 : 0 2295308 /dev/mapper/mpath0 61
Create a file system on partitions:
# mkfs -t ext3 /dev/mapper/mpath0p1
mke2fs 1.35 (28-Feb-2004)
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
143712 inodes, 286913 blocks
14345 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=297795584
9 block groups
32768 blocks per group, 32768 fragments per group
15968 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Mount the partition on the mount point:
# mkdir /datafile
# mount /dev/mapper/mpath0p1 /datafile
Additional References –