文章目錄
- 1. 介紹
- 2. 文法
- 3. 指令
- 3.1 常用指令
- 3.2 dmsetup info
- 3.3 dmsetup ls
- 3.4 dmsetup status
- 3.5 dmsetup deps
- 3.6 dmsetup table
- 3.7 dmsetup create
參考連接配接:
- 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. 介紹
dmsetup
指令是一個用來與 Device Mapper 溝通的指令行封裝器(wrapper)。可使用 dmsetup 指令的 info、ls、status 和 deps 選項檢視 LVM 裝置的正常資訊,如以下小節所述。
2. 文法
dmsetup + + or
# command 常見的有 remove 、 ls 、status 等
# device_name: 可以是/dev/sd*,或者是實體卷的名稱
3. 指令
3.1 常用指令
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
dmsetup info 指令提供以下分類資訊:
Name
裝置名稱。LVM 裝置以用小橫線分隔的卷組名稱和邏輯卷名稱表示。在源名稱中小橫線會轉換為兩個小橫線。在标準 LVM 操作過程中,不應使用這種格式的 LVM 裝置名稱直接指定 LVM 裝置,而是應該使用 vg/lv 指定。
State
可能的裝置狀态是 SUSPENDED、ACTIVE 和 READ-ONLY。dmsetup suspend 指令将裝置狀态設定為 SUSPENDED。當挂起某個裝置時,會停止對該裝置的所有 I/O 操作。使用 dmsetup resume 指令可将裝置狀态恢複到 ACTIVE。
Read Ahead
系統對正在進行讀取操作的任意打開檔案的預讀資料塊數目。預設情況下,核心會自動選擇一個合适的值。可使用 dmsetup 指令的 --readahead 選項更改這個值。
Tables present
這個類型的可能狀态為 LIVE 和 INACTIVE。INACTIVE 狀态表示已經載入了表格,且會在 dmsetup resume 指令将某個裝置狀态恢複為 ACTIVE 時進行切換,屆時表格狀态将為 LIVE。有關詳情請參考 dmsetup man page。
Open count
打開參考計數表示打開該裝置的次數。mount 指令會打開一個裝置。
Event number
目前收到的事件數目。使用 dmsetup wait n 指令允許使用者等待第 n 個事件,收到該事件前阻斷該調用。
Major, minor
主裝置号碼和副裝置号碼
Number of targets
組成某個裝置的片段數目。例如:一個跨三個磁盤的線性裝置會有三個目标。線性裝置由某個磁盤起始和結尾,而不是中間組成的線性裝置有兩個目标。
UUID
該裝置的 UUID。
3.3 dmsetup ls
可以使用
dmsetup ls
指令列出映射的裝置的裝置名稱清單。可以使用
dmsetup ls --target target_type
指令列出至少有一個指定類型目标的裝置。有關 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)
在多路徑或者其它 device mapper 裝置中堆疊的 LVM 配置檔案可能過于複雜。dmsetup ls 指令提供了一個–tree 選項,可以樹形式顯示裝置間的相依性,如下所示。
# 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
dmsetup status device
指令提供指定裝置中每個目标的狀态資訊。如果沒有指定裝置名稱,輸出結果是所有目前配置的裝置映射器裝置資訊。可以使用
dmsetup status --target target_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
dmsetup deps device
指令為指定裝置的映射清單參考的裝置提供(major,minor)對清單。如果沒有指定裝置名稱,則輸出所有目前配置的裝置映射器裝置資訊。
# 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
顯示table資訊
# 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是要建立的裝置名字。 如果成功将會在/dev/mapper/目錄下 生成這個名字的檔案
- dm-table是儲存了這個map device的 mapping table。
起始扇區 扇區個數 線性映射 目标裝置 目标裝置上的起始扇區
0 1025 linear /dev/sdb2 0
1025 1025 linear /dev/sdc2 0
某個block的sector大小,可以用
blockdev --getsize /dev/sdb2
來得到。
如果是剛分區的盤,需要用partprobe來更新一下。
檢視linear裝置的寫入順序
将新生成的裝置建立檔案系統,mount到某個目錄。
cd到這個目錄下,運作
dd if=/dev/zero of=test
watch -n 1 iostat /dev/sdb2 /dev/sdc2
[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