本文转自http://luyadong.blog.51cto.com/2876653/801082
1、创建lvm的镜像
fdisk /dev/sdb 建立4个磁盘分区
partprobe
pvcreate /dev/sdb5
pvcreate /dev/sdb6
pvcreate /dev/sdb7
pvcreate /dev/sdb8
pvdisplay
vgcreate vg0 /dev/sdb5 /dev/sdb6 /dev/sdb7
创建lvm镜像/dev/vg0/mirror
lvcreate -L 2G -m1 -n mirror vg0 /dev/sdb5 /dev/sdb6 /dev/sdb7
查看/dev/vg0/mirror的信息:
[root@bogon ~]# lvdisplay /dev/vg0/mirror
--- Logical volume ---
LV Name /dev/vg0/mirror
VG Name vg0
LV UUID kHWJ34-fKma-0hKw-8lAi-zItI-VyoE-lzxWEF
LV Write Access read/write
LV Status available
# open 1
LV Size 2.00 GiB
Current LE 512
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:5
查看当前lvm中设备状态:
[root@bogon ~]# lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Convert Devices
LogVol00 VolGroup00 -wi-ao 41.78g /dev/sda2(0)
LogVol01 VolGroup00 -wi-ao 8.00g /dev/sda2(1337)
mirror vg0 mwi-ao 2.00g mirror_mlog 100.00 mirror_mimage_0(0),mirror_mimage_1(0)
[mirror_mimage_0] vg0 iwi-ao 2.00g /dev/sdb5(0)
[mirror_mimage_1] vg0 iwi-ao 2.00g /dev/sdb6(0)
[mirror_mlog] vg0 lwi-ao 4.00m /dev/sdb7(0)
对新建的镜像lv进行格式化、挂载:
mkfs.ext3 /dev/vg0/mirror
mkdir /mirror
mount /dev/vg0/mirror /mirror/
2、对镜像lvm进行破坏,破坏一块pv,看是否能正常工作,
dd if=/dev/zero of=/dev/sdb5 count=10
破坏之后可以看到镜像lv中的/dev/sdb5变成了未知:
[root@bogon ~]# lvs -a -o +devices
Couldn't find device with uuid NnJbyv-vq42-HHeM-v7YV-2c4I-I9cl-YOc00r.
LV VG Attr LSize Origin Snap% Move Log Copy% Convert Devices
LogVol00 VolGroup00 -wi-ao 41.78g /dev/sda2(0)
LogVol01 VolGroup00 -wi-ao 8.00g /dev/sda2(1337)
mirror vg0 mwi-ao 2.00g mirror_mlog 100.00 mirror_mimage_0(0),mirror_mimage_1(0)
[mirror_mimage_0] vg0 iwi-ao 2.00g unknown device(0)
[mirror_mimage_1] vg0 iwi-ao 2.00g /dev/sdb6(0)
[mirror_mlog] vg0 lwi-ao 4.00m /dev/sdb7(0)
[root@bogon ~]# lvscan
Couldn't find device with uuid NnJbyv-vq42-HHeM-v7YV-2c4I-I9cl-YOc00r.
ACTIVE '/dev/vg0/mirror' [2.00 GiB] inherit
ACTIVE '/dev/VolGroup00/LogVol00' [41.78 GiB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [8.00 GiB] inherit
重新对镜像lv进行挂载,发现正常。
umount /mirror/
mount /dev/vg0/mirror /mirror/
cd /mirror/
把坏掉的设备从vg0中移除:
vgreduce --removemissing --force vg0
移除之后发现vg0信息中Mirrored volumes选项没有了
[root@bogon ~]# vgdisplay /dev/vg0
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 22
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 4.01 GiB
PE Size 4.00 MiB
Total PE 1026
Alloc PE / Size 512 / 2.00 GiB
Free PE / Size 514 / 2.01 GiB
VG UUID nwo3S4-crKr-Lgri-X7Um-qfXv-6Mxo-XXXt2N
在vg0中新加一个pv,对数据进行恢复:
vgextend vg0 /dev/sdb8
[root@bogon ~]# lvconvert -m1 /dev/vg0/mirror /dev/sdb8 /dev/sdb6 /dev/sdb7
vg0/mirror: Converted: 0.0%
vg0/mirror: Converted: 32.0%
vg0/mirror: Converted: 64.6%
vg0/mirror: Converted: 97.7%
vg0/mirror: Converted: 100.0%
[root@bogon ~]# lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Convert Devices
LogVol00 VolGroup00 -wi-ao 41.78g /dev/sda2(0)
LogVol01 VolGroup00 -wi-ao 8.00g /dev/sda2(1337)
mirror vg0 mwi-ao 2.00g mirror_mlog 100.00 mirror_mimage_0(0),mirror_mimage_1(0)
[mirror_mimage_0] vg0 iwi-ao 2.00g /dev/sdb6(0)
[mirror_mimage_1] vg0 iwi-ao 2.00g /dev/sdb8(0)
[mirror_mlog] vg0 lwi-ao 4.00m /dev/sdb7(0)
[root@bogon ~]# lvdisplay /dev/vg0/mirror
--- Logical volume ---
LV Name /dev/vg0/mirror
VG Name vg0
LV UUID kHWJ34-fKma-0hKw-8lAi-zItI-VyoE-lzxWEF
LV Write Access read/write
LV Status available
# open 1
LV Size 2.00 GiB
Current LE 512
Mirrored volumes 2 这个选项又恢复了
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:5
本文出自 “生命不息奋斗不止” 博客,转载请与作者联系!
阅读(2516) | 评论(0) | 转发(0) |