What is mapper in linux

青灯夜游
Release: 2022-05-12 17:29:59
Original
5055 people have browsed it

In Linux, the full name of mapper is "Device mapper", which is a mapping mechanism from logical devices to physical devices; under this mechanism, users can easily manage storage resources according to their own needs; It contains three important concepts: mapped device, target device, etc.

What is mapper in linux

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

1. What is mapper in linux?

The full name of mapper is "Device mapper", which is the Linux 2.6 kernel A mapping mechanism from logical devices to physical devices provided in . Under this mechanism, users can easily manage storage resources according to their own needs.

Currently popular logical volume managers under Linux such as LVM2 (Linux Volume Manager 2 version), EVMS (Enterprise Volume Management System), dmraid (Device Mapper Raid Tool), etc. are all based on this implemented by the mechanism.

The essential function of Device mapper is to forward IO requests from the logical device mapped device to the corresponding target device based on the mapping relationship and the IO processing rules described by the target driver.

Device mapper is registered in the kernel as a block device driver. It contains three important object concepts, mapped device, mapping table, and target device.

Device mapper is relatively simple in user space, mainly including the device mapper library and dmsetup tool.

The Device mapper library is an encapsulation of the necessary operations required for ioctl and user space to create and delete device mapper logical devices.

dmsetup is a command that provides users with directly available commands to create and delete device mapper devices. line tools.

Function:

You can combine multiple physical devices into one logical device. You can do ordinary merging, or implement striping similar to raid0. You can also use To shield bad sectors in the hard disk, you can also take lvm snapshots to back up the database, or simulate very large devices through zero device files for testing functions.

Device mapper is the underlying technology of lvm and multipating.

2. Installation package:

device-mapper device-mapper-multipath

3. Working principle:

Create logical devices through mapping table (the corresponding relationship between each sector of the physical device and the logical device ). The contents of the table include:
The starting sector of the logical device:
is usually 0. The sector number type of the logical device (linear linear, continuous combination; striped striped ;errorShield bad sectors;snapshotSnapshot;zeroZero device)

4. Disk sector Calculation:

1 sector = 512 bytes b 1kb = 1024b Sector size kb = number of sectors 512/1024 For example, for a 10G disk, the number of sectors is:
10000000kb=Number of sectors
512/1024=20000000 sectors

#blockdev --getsize /dev/sda6 查看设备扇区数量
#echo “0 ‘blockdev --getsize /dev/sda6’ linear /dev/sda6 0” | dmsetup create mydevice
Copy after login

Creating logical device 0 through table means that this logical device starts from sector 0 and has 208782 sectors, linear means continuous ,/dev/sda6 0 means starting from the 0th sector of /dev/sda6 as a logical device. When a device uses the remaining space as a logical device, the sectors do not start at 0. It will only take effect after restarting after writing the following boot script

5. Linear type device characteristics:

Contiguous sectors of multiple physical partitions combined to form a logical device. 0 20000 linear /dev/sda1 0 20000 60000 linear /dev/sdb1 0 Note:
The logical device is taken from sda1 from sector 0 to sector 20000, and the logical device is taken from sector 20000 to sector 20000. Starting from sector 0 of sdb1, 60,000 sectors are taken, and the logical device has 80,000 sectors. Implement command

#echo “0 20000 linear /dev/sda1 0\n20000 60000 linear /dev/sdb1 0” | dmsetup create mydevice
Copy after login

6.stripe striping:

Write to disk 0 in turn by chunksize 1024 striped 2 256 /dev/sda1 0 /dev/sdb1 0 Note:
The logical device starts from sector 0 to sector 1024, type is striped, 2 devices, chunksize 256kb from 0 of /dev/sda1 and /dev/sdb1 Each sector starts with 512 sectors (note that the number of sectors must be a multiple of chunksize). Command implementation

#echo “0 1024 striped 2 256 /dev/sda1 0 /dev/sdb1 0” | dmsetup create mydevice
Copy after login

7.error:

Remove error sectors through synthetic logical devices 0 80 linear /dev/sda1 0 80 100 error 181 200 linear /dev/sdb1 0 command to implement

#echo “0 80 linear /dev/sda1 0\n80 100 error\n181 200 linear /dev/sdb1 0” | dmsetup create mydevice
Copy after login

8.snapshot Logical volume snapshot features:

After creating a snapshot, 3 devices appear (original device, snapshot device, cow device). If the data has not changed, read the data from the original device and write the changed data storage In the cow area, the snapshot device saves the data of the original device.

#echo ―0 1000 snapshot /dev/sda1 /dev/vg0/realdev P 16 ‖ | dmsetup create mydevice从0扇区到1000扇区为/dev/sda1创建快照,名字为realdev,P表示下次启动仍然生效,16为chunksize
Copy after login

9.zero zero device characteristics:

is similar to /dev/zero, but it is a block device and cannot be written. It is generally used For testing purposes, create a large file system for testing. For example, the test creates a 10T device formatted with ext3

#export HUGESIZE=$[100 * (2**40)/512] 100T的扇区数量 2**40为2的40次方
#echo "0 $HUGESIZE zero" | dmsetup create zerodev 生成的文件在/dev/mapper/zerodev ext3每个分区最大支持2TB
Copy after login

10. Multi-path features:

多路径功能,用来提供线路冗余,监控每条链路,当链路失败时自动切换链路,而且自动恢复运行,防止单点故障。生成的设备名 /dev/dm-X 类型:
当两路径优先级相等:
负载均衡 当两路径优先级不等: 冗余

multipath列出多路径设备,后台需要开启multipathd服务,优先级大小为0-1024 实验步骤:

存储端配置双网卡,配置/dev/sda6为iscsi设备 服务器端安装device-mapper-multipath包,连接iscsi设备

#vi /etc/multipath.conf 注释掉 blacklist { devnode "*" 不同厂商的配置是不一样的 } 取消注释 default{ udev_dir .. .. path_grouping_policy failover(根据失效域来判断执行策略) }
#systemctl enable multipathd 
#systemctl restart multipathd 之后生成的设备位置在/dev/mpath/下,可制作文件系统,挂载
#multipath –ll 查询设备状态
Copy after login

11.FC存储:

存储端建立raid设备,raid建立与HBA卡WWN号的映射关系(连接哪个HBA卡则使用哪块磁盘设备) WWN为HBA卡的授权名称,用来区分一个或一组网络连接,表示网络上的一个连接

相关推荐:《Linux视频教程

The above is the detailed content of What is mapper in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template