最後更新: 2017-08-10
介紹
The dmsetup command is a command line wrapper for communication with the Device Mapper.
Usage
info
dmsetup info [device]
State
SUSPENDED, ACTIVE, and READ-ONLY.
When a device is suspended("dmsetup suspend"), all I/O operations to that device stop.
The "dmsetup" resume command restores a device state to ACTIVE.
Read Ahead
The number of data blocks that the system reads ahead for any open file on which read operations are ongoing
(--readahead)
Tables present
INACTIVE ( indicates that a table has been loaded which will be swapped )
LIVE
Open count
A mount command opens a device.
Event number
The current number of events received.
Number of targets
a linear device spanning 3 disks would have 3 targets.
ls
dmsetup ls
wsnap-rootfs (253:2) centos-swap (253:0) centos-root (253:1)
# tree view
dmsetup ls --tree
wsnap-rootfs (253:2) ├─ (7:2) └─ (251:0) centos-swap (253:0) └─ (252:2) centos-root (253:1) └─ (252:2)
status
dmsetup status
wsnap-rootfs: 0 17842176 snapshot 4112/204800 0 centos-swap: 0 2097152 linear centos-root: 0 17842176 linear
deps
# a list of (major, minor) pairs for devices referenced by the mapping table for the specified device.
dmsetup deps
wsnap-rootfs: 2 dependencies : (7, 2) (251, 0) centos-swap: 1 dependencies : (252, 2) centos-root: 1 dependencies : (252, 2)
table
dmsetup table centos-root
0 17842176 linear 252:2 2099200
dmsetup table centos-swap
0 2097152 linear 252:2 2048
ll /dev/vda*
brw-rw---- 1 root disk 252, 0 Jul 13 16:56 /dev/vda
brw-rw---- 1 root disk 252, 1 Jul 13 16:56 /dev/vda1
brw-rw---- 1 root disk 252, 2 Jul 13 16:56 /dev/vda2
create
# dmsetup create device_name [--table <table>|table_file]
# table is read from standard input OR "--table <table>"
# If successful a device will appear as /dev/mapper/<device-name>
echo "0 size_of_ro-device snapshot /dev/ro-device /dev/rw-device N chunk_size_in_sectors" | dmsetup create ro-snap
# Create the snapshot-origin device with no table.
dmsetup create my_data_org
table & load
# Read the table from my_data and load it into my_data_org.
dmsetup table my_data | dmsetup load my_data_org
TABLE FORMAT
linear (maps a linear range of the Device)
striped
error (Errors any I/O that goes to this area)
zero (Returns blocks of zeroes on reads. Any data written is discarded silently.)
raid (Offers an interface to the kernel's software raid driver, md.)
snapshot
linear
0 size <dev_path("major:minor")> <offset(Starting sector within the device)>
dmstats
DOC
https://www.kernel.org/doc/Documentation/device-mapper/linear.txt
https://www.kernel.org/doc/Documentation/device-mapper/snapshot.txt