设备映射
Linear线型
+++++++++++++++++++++++++
512 sda7 3G +
+++++++++++++++++++++++++
+++++++++++++++++++++++++
512 sdb7 3G
+++++++++++++++++++++++++
/dev/mapper/hulk ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sda7 sdb7
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
分3个1G的分区,并将3个分区创建成PV
[root@localhost ~]# pvcreate /dev/sda[7-9]
Physical volume "/dev/sda7" successfully created
Physical volume "/dev/sda8" successfully created
Physical volume "/dev/sda9" successfully created
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda7 lvm2 a-- 953.00m 953.00m
/dev/sda8 lvm2 a-- 954.00m 954.00m
/dev/sda9 lvm2 a-- 954.00m 954.00m
创建卷组 hulk 并将 /dev/sda8的PV加入卷组
[root@localhost ~]# vgcreate hulk /dev/sda8
Volume group "hulk" successfully created
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda7 lvm2 a-- 952.00m 952.00m
/dev/sda8 hulk lvm2 a-- 952.00m 952.00m
/dev/sda9 lvm2 a-- 54.00m 954.00m
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
hulk 2 0 0 wz--n- 1.86g 1.86g
查看映射设备表
[root@localhost ~]# dmsetup table
No devices found
[root@localhost ~]# lvcreate -L 256 -n ironhulk
Logical volume "iron" created
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% MoveLog Cpy%Sync Convert
iron hulk -wi-a---- 256.00m
[root@localhost ~]# dmsetup table hulk-iron
0 524288 linear 8:8 2048
0 524288 映射设备的起始扇区和使用多少个扇区,可计算映射设备大小
[root@localhost ~]# echo $(( 524228 * 512 /1024 /1024))
255
linear 线型设备
8:8 实际对应的设备/dev/sda8
2048 偏移量,rhel6前2048是PV信息
增大LV,映射设备偏移量一会随之变化
[root@localhost ~]# lvextend -L +256M/dev/hulk/iron
Extending logical volume iron to 512.00 MiB
Logical volume iron successfully resized
[root@localhost ~]# dmsetup table hulk-iron
0 1048576 linear 8:8 2048
下面我们要增大/dev/hulk/iron 到 1.1G,但是PV /dev/sda8只有952M,所以我们要在VG中加入一个PV
[root@localhost ~]# vgextend hulk /dev/sda7
[root@localhost ~]# lvextend -L 1.1G/dev/hulk/iron
Rounding size to boundary between physical extents: 1.10 GiB
Extending logical volume iron to 1.10 GiB
Logical volume iron successfully resized
再次查看映射设备表的时候,发现 hulk-iron 有2行记录,上面一行是/dev/sda8,但是由于sda8 空间不足,所以会使用sda7的一部分空间
[root@localhost ~]# dmsetup table hulk-iron
0 1949696 linear 8:8 2048
1949696 360448 linear 8:7 2048
再创建一个LV,会发现 hulk-iron2的偏移量,与 hulk-iron 的偏移量相连接( 360448 + 2048 )
[root@localhost ~]# lvcreate -L 256M -niron2 hulk
Logical volume "iron2" created
[root@localhost ~]# dmsetup tablehulk-iron2
0 524288 linear 8:7 362496
Stripe条带
++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
+512+A + sda7 512+ B +
sdb7
++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++
/dev/mapper/hulk
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+A+B +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
创建一个LV iron1,大小256M,指定有2个stripes(2个PV)组成
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda11 lvm2 a-- 4.66g 4.66g
/dev/sda7 hulk lvm2 a-- 952.00m 824.00m
/dev/sda8 hulk lvm2 a-- 952.00m 824.00m
/dev/sda9 lvm2 a-- 954.00m 954.00m
[root@localhost ~]# lvcreate -i 2 -L 256Mhulk -n iron1
Using default stripesize 64.00 KiB
Logical volume "iron1" created
[root@localhost ~]# dmsetup table
hulk-iron1: 0 524288 striped 2 128 8:8 20488:7 2048
striped 2 条带数
128 条带的扇区数
[root@localhost ~]# echo $(( 128 * 512 /1024))
64
创建一个LV iron2,由2个stripes组成
[root@localhost ~]# lvcreate -i 3 -L 256Mhulk -n iron2
Using default stripesize 64.00 KiB
Rounding size (64 extents) up to stripe boundary size (66 extents)
Number of stripes (3) must not exceed number of physical volumes (2)
[root@localhost ~]# pvcreate /dev/sda9
Physical volume "/dev/sda9" successfully created
[root@localhost ~]# vgextend hulk /dev/sda9
Volume group "hulk" successfully extended
[root@localhost ~]# lvcreate -i 3 -L 256Mhulk -n iron2
Using default stripesize 64.00 KiB
Rounding size (64 extents) up to stripe boundary size (66 extents)
Logical volume "iron2" created
[root@localhost ~]# dmsetup table
hulk-iron2: 0 540672 striped 3 128 8:8264192 8:7 264192 8:9 2048
hulk-iron1: 0 524288 striped 2 128 8:8 20488:7 2048
向条带化设备/dev/hulk/iron1中dd数据,发现sda7、sda8同时写
[root@localhost ~]# dd if=/dev/zeroof=/dev/hulk/iron1
[root@localhost ~]# iostat 1 /dev/sda7/dev/sda8
Linux 2.6.32-358.el6.x86_64(localhost.localdomain) 08/24/2013 _x86_64_(4 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
2.14 0.00 1.90 2.11 0.00 93.85
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda7 0.66 94.70 162.52 916968 1573712
sda8 0.82 367.52 0.09 3558808 880
avg-cpu: %user %nice %system %iowait %steal %idle
10.59 0.00 5.41 2.59 0.00 81.41
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda7 0.00 0.00 0.00 0 0
sda8 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
4.36 0.00 1.28 0.00 0.00 94.36
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda7 0.00 0.00 0.00 0 0
sda8 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
1.28 0.00 1.02 6.91 0.00 90.79
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda7 352.00 2816.00 0.00 2816 0
sda8 359.00 2872.00 0.00 2872 0
avg-cpu: %user %nice %system %iowait %steal %idle
4.69 0.00 7.98 20.89 0.00 66.43
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda7 1023.00 8184.00 0.00 8184 0
sda8 1017.00 8136.00 0.00 8136 0
avg-cpu: %user %nice %system %iowait %steal %idle
9.16 0.00 6.51 28.92 0.00 55.42
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda7 468.00 3744.00 0.00 3744 0
sda8 488.00 3888.00 16.00 3888 16
avg-cpu: %user %nice %system %iowait %steal %idle
2.30 0.00 2.04 26.28 0.00 69.39
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda7 423.00 3384.00 0.00 3384 0
sda8 412.00 3304.00 0.00 3304 0
avg-cpu: %user %nice %system %iowait %steal %idle
0.77 0.00 4.59 21.68 0.00 72.96
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda7 1068.00 8544.00 0.00 8544 0
sda8 1068.00 8544.00 0.00 8544 0
mirror 镜像
创建一个mirror型设备
[root@localhost ~]# dmsetup table
No devices found
[root@localhost ~]# lvcreate -m 1 -L 256M-n iron1 hulk
Logical volume "iron1" created
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda11 lvm2a-- 4.66g 4.66g
/dev/sda7 hulk lvm2 a-- 952.00m 696.00m
/dev/sda8 hulk lvm2 a-- 952.00m 696.00m
/dev/sda9 hulk lvm2 a-- 952.00m 948.00m
[root@localhost ~]# dmsetup table
hulk-iron1_mp_w_picpath_1: 0 524288 linear 8:72048
hulk-iron1_mp_w_picpath_0: 0 524288 linear 8:82048
hulk-iron1: 0 524288 mirror disk 2 253:01024 2 253:1 0 253:2 0 1 handle_errors
hulk-iron1_mlog: 0 8192 linear 8:9 2048
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% MoveLog Cpy%Sync Convert
iron1 hulk mwi-a-m-- 256.00m iron1_mlog 100.00
将一个非mirror设备,转换成一个mirror设备
[root@localhost ~]# lvcreate -L 256M -niron2 hulk
Logical volume "iron2" created
[root@localhost ~]#
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% MoveLog Cpy%Sync Convert
iron1 hulk mwi-a-m-- 256.00m iron1_mlog 100.00
iron2 hulk -wi-a---- 256.00m
[root@localhost ~]# lvconvert -m 1/dev/hulk/iron2
hulk/iron2: Converted: 1.6%
hulk/iron2:Converted: 39.1%
hulk/iron2: Converted: 76.6%
hulk/iron2: Converted: 100.0%
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% MoveLog Cpy%Sync Convert
iron1 hulk mwi-a-m-- 256.00m iron1_mlog 100.00
iron2 hulk mwi-a-m-- 256.00m iron2_mlog 100.00
lvm-快照
创建一个LV iron1 ,iron1创建文件系统,并挂载到 /mnt/iron-real
[root@localhost ~]# dmsetup table
No devices found
[root@localhost ~]# lvcreate -L 100M -niron1 hulk
Logical volume "iron1" created
[root@localhost ~]# mkfs.ext4/dev/hulk/iron1
[root@localhost ~]# mkdir /mnt/iron-real
[root@localhost ~]# mkdir /mnt/iron-snap
[root@localhost ~]# mount /dev/hulk/iron1 /mnt/iron-real
[root@localhost ~]# dmsetup table
hulk-iron1: 0 204800 linear 8:8 2048
[root@localhost ~]# mount | grep iron1
/dev/mapper/hulk-iron1 on /mnt/iron-realtype ext4 (rw)
给 /dev/hulk/iron1 创建快照 iron1s,并将 iron1s 挂载到 /mnt/iron-snap/
[root@localhost ~]# lvcreate -L 50M -s -niron1s /dev/hulk/iron1
Rounding up size to full physical extent 52.00 MiB
Logical volume "iron1s" created
[root@localhost ~]# dmsetup table
hulk-iron1-real: 0 204800 linear 8:8 2048 #原始设备
hulk-iron1: 0 204800 snapshot-origin 253:2 #映射设备
hulk-iron1s-cow: 0 106496 linear 8:8 206848 #cow设备
hulk-iron1s: 0 204800 snapshot 253:2 253:3P 8 #快照设备
[root@localhost ~]# dmsetup ls --tree
hulk-iron1 (253:0)
└─hulk-iron1-real (253:2)
└─ (8:8)
hulk-iron1s (253:1)
├─hulk-iron1s-cow (253:3)
│└─ (8:8)
└─hulk-iron1-real (253:2)
└─ (8:8)
[root@localhost ~]# mount /dev/hulk/iron1s/mnt/iron-snap/
向映射设备写数据的时候,发现real设备会有 read。 cow设备会有write。首先会从 real设备中读取原始数据,然后将修改后的数据写入cow设备
[root@localhost ~]# while : ; do ddif=/dev/zero of=/mnt/iron-real/bigfile bs=1k count=10 ; usleep ; done
[root@localhost ~]# iostat 1 /dev/dm-2/dev/dm-3
Linux 2.6.32-358.el6.x86_64(localhost.localdomain) 08/24/2013 _x86_64_ (4CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
2.14 0.00 1.91 2.14 0.00 93.81
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 0.02 0.13 0.00 1696 2
dm-3 0.00 0.01 0.00 176 34
avg-cpu: %user %nice %system %iowait %steal %idle
0.26 0.00 0.26 0.00 0.00 99.48
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 0.00 0.00 0.00 0 0
dm-3 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
3.07 0.00 0.77 5.37 0.00 90.79
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 0.00 0.00 0.00 0 0
dm-3 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
3.11 0.00 1.81 34.97 0.00 60.10
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 358.00 604.00 562.00 604 562
dm-3 104.00 0.00 832.00 0 832
avg-cpu: %user %nice %system %iowait %steal %idle
4.08 0.00 2.30 42.09 0.00 51.53
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 288.00 464.00 460.00 464 460
dm-3 77.00 0.00 616.00 0 616
avg-cpu: %user %nice %system %iowait %steal %idle
3.51 0.00 2.51 39.60 0.00 54.39
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 213.00 344.00 340.00 344 340
dm-3 64.00 0.00 512.00 0 512
avg-cpu: %user %nice %system %iowait %steal %idle
8.45 0.00 4.59 36.71 0.00 50.24
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 313.00 504.00 500.00 504 500
dm-3 88.00 0.00 704.00 0 704
avg-cpu: %user %nice %system %iowait %steal %idle
3.65 0.00 1.30 42.97 0.00 52.08
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 326.00 512.00 524.00 512 524
dm-3 91.00 0.00 728.00 0 728
^C
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
iron1 hulk owi-aos-- 100.00m
iron1s hulk swi-aos-- 52.00m iron1 3.70
向快照设备写数据的时候,发现real设备会有 read,write。 cow设备会有write。首先会从 real设备中读取原始数据,然后将读取的原始数据写入cow设备,最后在向real设备中写入新数据
[root@localhost ~]# while : ; do ddif=/dev/zero of=/mnt/iron-snap/bigfile bs=1k count=10 ; usleep ; done
[root@localhost ~]# iostat 1 /dev/dm-2/dev/dm-3
Linux 2.6.32-358.el6.x86_64(localhost.localdomain) 08/24/2013 _x86_64_ (4CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
2.14 0.00 1.91 2.15 0.00 93.79
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 0.22 0.45 0.30 5750 3896
dm-3 0.06 0.02 0.44 206 5562
avg-cpu: %user %nice %system %iowait %steal %idle
1.53 0.00 1.79 1.53 0.00 95.15
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 0.00 0.00 0.00 0 0
dm-3 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
3.64 0.00 4.13 0.00 0.00 92.23
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 0.00 0.00 0.00 0 0
dm-3 0.00 0.00 0.00 0 0
avg-cpu: %user %nice %system %iowait %steal %idle
5.98 0.00 12.44 15.07 0.00 66.51
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 21.00 168.00 0.00 168 0
dm-3 1994.00 6.00 4162.00 6 4162
avg-cpu: %user %nice %system %iowait %steal %idle
4.05 0.00 5.32 38.23 0.00 52.41
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
dm-2 108.00 864.00 0.00 864 0
dm-3 611.00 0.00 2128.00 0 2128