What is mapper in linux

May 12, 2022 pm 05:29 PM
linux

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

See all articles