同事打电话询问LVM故障的处理办法,其实我对LVM也是一知半解,只是恰好在用户现场解决过几次有关LVM的故障。
这次故障的发生是因为不小心,把grub的信息写入到了阵列设备上,而阵列设备是用来做LVM的,导致的结果是pvscan可以得到pv信息,lvscan也能得到lv信息,但是
vgscan却不能。 使用vgcfgrestore命令恢复后,正常了。为了重现用户的现象,我做了另外一个实验,不是vg信息找不到,而是找不到对应
uuid号的设备,过程如下:
创建pv,vg,lv
[root@lancy ~]# pvcreate /dev/mdp0 Physical volume "/dev/mdp0" successfully created [root@lancy ~]# vgcreate vg01 /dev/mdp0 Volume group "vg01" successfully created [root@lancy ~]# lvcreate -n lv01 -L+200M vg01 Logical volume "lv01" created [root@lancy ~]# mkfs.ext3 /dev/mapper/vg01-lv01 -m 0 [root@lancy ~]# mount /dev/mapper/vg01-lv01 /misc [root@lancy ~]# cp mdadm-2.5.2-1.i386.rpm /misc/ [root@lancy ~]# umount /misc
2)做一个破坏者
[root@lancy ~]# dd if=/dev/zero of=/dev/mdp0 bs=512 count=3
3+0 records in
3+0 records out
1536 bytes (1.5 kB) copied,7.6469e-05 秒,20.1 MB/秒
[root@lancy ~]# pvscan
No matching physical volumes found
[root@lancy ~]# vgscan
Reading all physical volumes. This may take a while...
No volume groups found
pv,vg,lv都找不到了,但是vg01-lv01这个设备还是存在的,而且也能mount。不过估计重启后就找不到了。于是恢复。
尝试老办法
[root@lancy ~]# vgcfgrestore -f /etc/lvm/backup/vg01 -n vg01 -t /dev/mdp0 Test mode: Metadata will NOT be updated. Couldn't find device with uuid 'fPsp4D-aaxu-YMGZ-gqGn-sbUq-fZE0-YnCbwz'. Couldn't find all physical volumes for volume group vg01. Restore failed.看来vgcfgrestore不是万能的,怎么办?
重写uuid
[root@lancy bin]# pvcreate –uuid fPsp4D-aaxu-YMGZ-gqGn-sbUq-fZE0-YnCbwz –restorefile /etc/lvm/archive/vg01_00001.vg /dev/mdp0 Couldn’t find device with uuid ‘fPsp4D-aaxu-YMGZ-gqGn-sbUq-fZE0-YnCbwz’. Physical volume “/dev/mdp1” successfully created [root@lancy bin]# vgcfgrestore vg01 Restored volume group vg01 [root@lancy bin]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% lv01 vg01 -wi— 100.00M [root@lancy bin]# vgscan Reading all physical volumes. This may take a while… Found volume group “vg01” using metadata type lvm2
哈哈,到此搞定!