Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept of mapper in linux

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, the editor will share with you the relevant knowledge of what the concept of mapper is in linux. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

In linux, mapper is called "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 and so on.

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

1. What is the mapper in linux

The full name of mapper is "Device mapper", which is a mapping mechanism from logical device to physical device provided by Linux2.6 kernel. Under this mechanism, users can easily manage storage resources according to their own needs.

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

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

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

Device mapper is relatively simple in user space, including device mapper libraries and dmsetup tools.

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

Dmsetup is a command-line tool for creating and deleting device mapper devices that is directly available to users.

Features:

You can synthesize multiple physical devices into a logical device, can do ordinary merging, or achieve striping similar to raid0, can also be used to shield bad sectors in the hard disk, can also do lvm snapshots to back up the database, or through zero device files to simulate very large devices for testing functions.

Device mapper is the underlying technology of lvm and multipating.

two。 Install the package:

Device-mapper device-mapper-multipath

3. How it works:

Create logical devices (the correspondence between the physical device and each sector of the logical device) through mapping table. The contents of the table include:

The starting sector of the logical device:

Usually the number of sectors of a 0 logical device (linear, continuous combination; striped striping; error shielding bad channels; snapshot snapshots; Zero zero devices)

4. Calculation of disk sectors:

1 sector = 512 bytes b 1kb=1024b sector size kb= sector number 512 Universe 1024 for example 10G disk, sector number is:

10000000kb = number of sectors 512max 102400kb = 20000000 sectors

# blockdev-- getsize / dev/sda6 View the number of device sectors # echo "0 'blockdev-- getsize / dev/sda6' linear / dev/sda6 0" | dmsetup create mydevice

Creating a logical device 0 through table indicates that the logical device starts from sector 0, has 208782 sectors, linear indicates continuous, and / dev/sda6 0 indicates that the logical device starts from sector 0 of / dev/sda6. When a device uses the remaining space as a logical device, the sector does not start from 0. The restart will not take effect until the boot script is written below

5.linear type device properties:

The sectors of a plurality of physical partitions are sequentially combined to form a logical device. 0 20000 linear / dev/sda1 0 20000 60000 linear / dev/sdb1 0 Note:

The logic device takes 20000 sectors from 0 to sector from sda1, and the logic device starts from 20000 sectors and 60000 sectors from the 0 sector of sdb1. The logic device has 80000 sectors. Implement command

# echo "0 20000 linear / dev/sda1 0\ n20000 60000 linear / dev/sdb1 0" | dmsetup create mydevice

6.stripe striping:

Take turns writing to disk 0 1024 striped 2 256 / dev/sda1 0 / dev/sdb1 0 via chunksize Note:

The logic device starts from 0 sector to 1024 sector, and the type is striped, 2 devices. Chunksize 256kb starts from the 0 sector of / dev/sda1 and / dev/sdb1 (note that the number of sectors must be a multiple of chunksize)

# echo "0 1024 striped 2 256 / dev/sda1 0 / dev/sdb1 0" | dmsetup create mydevice

7.error:

It is realized by removing the error sector 080 linear / dev/sda1 080 100 error 181200 linear / dev/sdb1 0 command from the synthetic logic device.

# echo "0 80 linear / dev/sda1 0\ n80 100 error\ n181 200 linear / dev/sdb1 0" | dmsetup create mydevice

8.snapshot logical volume snapshot features:

After creating a snapshot, there are three devices (original device, snapshot device, cow device). If the data has not changed, the read data is read from the original device, and the changed data is written and stored in the cow area, and the snapshot device stores the data of the original device.

# echo-0 1000 snapshot / dev/sda1 / dev/vg0/realdev P 16 snapshot | dmsetup create mydevice creates a snapshot of / dev/sda1 from sector 0 to sector 1000. The name realdev,P means that the next boot is still valid, and 16 is chunksize.

9.zero Zero device characteristics:

Similar to / dev/zero, but it is a block device, can not write things, generally used for testing, to create a large file system for testing. For example, tests create 10T-sized devices that are formatted with ext3

# echo "0$ HUGESIZE zero" # the number of sectors of # export HUGESIZE=$ [100T * (2x40) / 512] 100T is 2 to the 40th power of 2 | the maximum number of 2TB per partition generated by dmsetup create zerodev is in / dev/mapper/zerodev ext3.

10. Multipath feature:

The multipath function is used to provide line redundancy, monitor each link, automatically switch links when the link fails, and automatically resume operation to prevent a single point of failure. Generated device name / dev/dm-X type:

When two paths have equal priority:

Load balancing when two paths have different priorities: redundancy

Multipath lists multipath devices. The multipathd service needs to be enabled at the backend. The priority is 0-1024. The steps are as follows:

Configure dual network cards on the storage side, configure / dev/sda6 to install device-mapper-multipath packages for iscsi devices on the server side, and connect iscsi devices

# vi / etc/multipath.conf comment out blacklist {devnode "*" different vendors have different configurations} uncomment default {udev_dir.. .. Path_grouping_policy failover (judging execution policy by failure domain)} # systemctl enable multipathd # systemctl restart multipathd generates the device location under / dev/mpath/, you can make a file system, and mount # multipath-ll to query the device status.

11.FC storage:

The storage side establishes a raid device, and the raid establishes a mapping relationship with the WWN number of the HBA card (which HBA card is connected to which disk device is used) WWN is the authorized name of the HBA card, which is used to distinguish one or a group of network connections, indicating a connection on the network.

These are all the contents of the article "what is the concept of mapper in linux". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report