Connection reference:
- https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/dmsetup
- https://man7.org/linux/man-pages/man8/dmsetup.8.html
1. Introduction
The dmsetup command is a command line wrapper used to communicate with Device Mapper. You can use the info, ls, status, and deps options of the dmsetup command to view general information about LVM devices, as described in the following sections.
2. Grammar
dmsetup + <command> + <device_name> or <uuid> # Common command s include remove, ls, status, etc # device_name: can be / dev/sd *, or the name of the physical volume
3. Order
3.1 common commands
dmsetup clear device_name dmsetup create device_name [-u|--uuid uuid] [--addnodeoncreate|--addnodeonresume] [-n|--notable|--table table|table_file] [--readahead [+]sectors|auto|none] dmsetup create --concise [concise_device_specification] dmsetup deps [-o options] [device_name...] dmsetup help [-c|-C|--columns] dmsetup info [device_name...] dmsetup info -c|-C|--columns [--count count] [--interval seconds] [--nameprefixes] [--noheadings] [-o fields] [-O|--sort sort_fields] [--separator separator] [device_name] dmsetup load device_name [--table table|table_file] dmsetup ls [--target target_type] [--exec command] [--tree] [-o options] dmsetup mangle [device_name...] dmsetup message device_name sector message dmsetup mknodes [device_name...] dmsetup reload device_name [--table table|table_file] dmsetup remove [-f|--force] [--retry] [--deferred] device_name... dmsetup remove_all [-f|--force] [--deferred] dmsetup rename device_name new_name dmsetup rename device_name --setuuid uuid dmsetup resume device_name... [--addnodeoncreate|--addnodeonresume] [--noflush] [--nolockfs] [--readahead [+]sectors|auto|none] dmsetup setgeometry device_name cyl head sect start dmsetup splitname device_name [subsystem] dmsetup stats command [options] dmsetup status [--target target_type] [--noflush] [device_name...] dmsetup suspend [--nolockfs] [--noflush] device_name... dmsetup table [--concise] [--target target_type] [--showkeys] [device_name...] dmsetup targets dmsetup udevcomplete cookie dmsetup udevcomplete_all [age_in_minutes] dmsetup udevcookie dmsetup udevcreatecookie dmsetup udevflags cookie dmsetup udevreleasecookie [cookie] dmsetup version dmsetup wait [--noflush] device_name [event_nr] dmsetup wipe_table device_name... [-f|--force] [--noflush] [--nolockfs] devmap_name major minor devmap_name major:minor
3.2 dmsetup info
# dmsetup info Name: testgfsvg-testgfslv1 State: ACTIVE Read Ahead: 256 Tables present: LIVE Open count: 0 Event number: 0 Major, minor: 253, 2 Number of targets: 2 UUID: LVM-K528WUGQgPadNXYcFrrf9LnPlUMswgkCkpgPIgYzSvigM7SfeWCypddNSWtNzc2N ... Name: VolGroup00-LogVol00 State: ACTIVE Read Ahead: 256 Tables present: LIVE Open count: 1 Event number: 0 Major, minor: 253, 0 Number of targets: 1 UUID: LVM-tOcS1kqFV9drb0X1Vr8sxeYP0tqcrpdegyqj5lZxe45JMGlmvtqLmbLpBcenh2L3
The dmsetup info command provides the following classification information:
Name Equipment name. LVM Devices are represented by volume group names and logical volume names separated by small horizontal lines. The small horizontal line in the source name is converted to two small horizontal lines. In standard LVM This format should not be used during operation LVM The device name is specified directly LVM Equipment, but should be used vg/lv appoint. State Possible device states are SUSPENDED,ACTIVE and READ-ONLY. dmsetup suspend The command sets the device status to SUSPENDED. When a device is suspended, all access to the device is stopped I/O Operation. use dmsetup resume The command restores the device state to ACTIVE. Read Ahead The number of pre read data blocks of any open file being read by the system. By default, the kernel automatically selects an appropriate value. Available dmsetup Imperative --readahead Option to change this value. Tables present The possible states of this type are LIVE and INACTIVE. INACTIVE Status indicates that the table has been loaded and will be displayed in the dmsetup resume Command to restore a device state to ACTIVE Switch when, and the table status will be LIVE. For details, please refer to dmsetup man page. Open count The open reference count indicates the number of times the device was opened. mount The command opens a device. Event number Number of incidents received so far. use dmsetup wait n The command allows the user to wait for a second time n An event that blocks the call before it is received. Major, minor Main equipment number and auxiliary equipment number Number of targets The number of segments that make up a device. For example, a linear device that spans three disks will have three targets. A linear device consists of the beginning and end of a disk, not the middle. A linear device has two goals. UUID Of the device UUID.
3.3 dmsetup ls
You can use the dmsetup ls command to list the device names of the mapped devices. You can use dmsetup ls -- target_ The type command lists devices that have at least one target of the specified type. Additional options for dmsetup ls
# dmsetup ls testgfsvg-testgfslv3 (253:4) testgfsvg-testgfslv2 (253:3) testgfsvg-testgfslv1 (253:2) VolGroup00-LogVol01 (253:1) VolGroup00-LogVol00 (253:0)
# dmsetup ls --target mirror lock_stress-grant--02.1722 (253, 34) lock_stress-grant--01.1720 (253, 18) lock_stress-grant--03.1718 (253, 52) lock_stress-grant--02.1716 (253, 40) lock_stress-grant--03.1713 (253, 47) lock_stress-grant--02.1709 (253, 23) lock_stress-grant--01.1707 (253, 8) lock_stress-grant--01.1724 (253, 14) lock_stress-grant--03.1711 (253, 27)
LVM configuration files stacked in multipath or other device mapper devices may be too complex. The dmsetup ls command provides a – tree option to display the dependencies between devices in the form of a tree, as shown below.
# dmsetup ls --tree vgtest-lvmir (253:13) ├─vgtest-lvmir_mimage_1 (253:12) │ └─mpathep1 (253:8) │ └─mpathe (253:5) │ ├─ (8:112) │ └─ (8:64) ├─vgtest-lvmir_mimage_0 (253:11) │ └─mpathcp1 (253:3) │ └─mpathc (253:2) │ ├─ (8:32) │ └─ (8:16) └─vgtest-lvmir_mlog (253:4) └─mpathfp1 (253:10) └─mpathf (253:6) ├─ (8:128) └─ (8:80)
3.4 dmsetup status
The dmsetup status device command provides status information for each target in the specified device. If no device name is specified, the output result is the device information of all currently configured device mappers. You can use dmsetup status -- target target_ The type command lists devices that have at least one target of the specified type.
# dmsetup status testgfsvg-testgfslv3: 0 312352768 linear testgfsvg-testgfslv2: 0 312352768 linear testgfsvg-testgfslv1: 0 312352768 linear testgfsvg-testgfslv1: 312352768 50331648 linear VolGroup00-LogVol01: 0 4063232 linear VolGroup00-LogVol00: 0 151912448 linear
3.5 dmsetup deps
The dmsetup deps device command provides a list of (major, minor) pairs of devices referenced by the mapping list of the specified device. If no device name is specified, all currently configured device mapper device information will be output.
# dmsetup deps testgfsvg-testgfslv3: 1 dependencies : (8, 16) testgfsvg-testgfslv2: 1 dependencies : (8, 16) testgfsvg-testgfslv1: 1 dependencies : (8, 16) VolGroup00-LogVol01: 1 dependencies : (8, 2) VolGroup00-LogVol00: 1 dependencies : (8, 2)
# dmsetup deps lock_stress-grant--02.1722 3 dependencies : (253, 33) (253, 32) (253, 31)
3.6 dmsetup table
Display table information
# dmsetup table docker-253:2-8409152-pool: 0 419430400 thin-pool 7:1 7:0 128 32768 1 skip_block_zeroing docker-docker--lv: 0 16777216 linear 8:16 2048 centos-swap: 0 4194304 linear 8:2 2048 centos-root: 0 98549760 linear 8:2 4196352
3.7 dmsetup create
dmsetup create dm-name dm-table
- DM name is the name of the device to be created. If successful, a file with this name will be generated in the / dev/mapper / directory
- DM table is the mapping table that holds the map device.
The number of start sectors linearly maps the start sectors on the target device 0 1025 linear /dev/sdb2 0 1025 1025 linear /dev/sdc2 0
The sector size of a block can be obtained by blockdev --getsize /dev/sdb2.
If it is a newly partitioned disk, you need to update it with partprobe.
View the write order of linear devices
Create a file system for the newly generated device and mount it to a directory.
cd to this directory, run
dd if=/dev/zero of=test
This command will run until the disk is full.
Can run before running
watch -n 1 iostat /dev/sdb2 /dev/sdc2
To observe the reading and writing of the disk.
It can be found that the writing process is to write to / dev/sdb2 first, and then to / dev/sdc2
This process is consistent with the concept of linear.
[root@node1 ~]# blockdev --getsize /dev/sdc1 1012032 [root@node1 ~]# blockdev --getsize /dev/sdd1 1012032 [root@node1 ~]# vi linear_table 0 1012032 linear /dev/sdc1 0 1012032 1012032 linear /dev/sdd1 0 [root@node1 ~]# dmsetup create linear_test linear_table [root@node1 ~]# ls -l /dev/mapper/linear_test brw-rw---- 1 root disk 253, 0 Jan 4 10:39 /dev/mapper/linear_test