Monday, August 3, 2009

More fun with Linux RAID and LVM

In an earlier post, I performed a test RAID5 + LVM set up using files instead of disks. Now I'm going to fail a 'disk', replace it in the array, and then expand the LVM logical volume to include a second RAID5 array.

In this example, I'll replace out /dev/loop2 as the faulty member. So, mark it as faulty, and remove it from the array. I'll also delete the loopback device.
mdadm /dev/md0 --fail /dev/loop2
mdadm /dev/md0 --remove /dev/loop2
rm /var/tmp/hdc.img
losetup -d /dev/loop2
Next, create a new disk, and add it to the array:
dd if=/dev/zero of=/var/tmp/hdc.img bs=1024 count=1048576
losetup /dev/loop2 /var/tmp/hdc.img
fdisk /dev/loop2
partprobe
mdadm /dev/md0 --add /dev/loop2
And the rebuild will begin. Check its progress with:
mdadm --detail /dev/md0
Now follow the steps in my previous post to build a second RAID5 array and call it md1; we'll be using using it to extend our original LVM volume group.
[root@canard ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg_media" using metadata type lvm2
pvcreate /dev/md1
vgextend vg_media /dev/md1
Find the total number of extents you have available, resize the LV to that new number and grow the EXT3 filesystem for the free space on your device:
[root@canard ~]# vgdisplay vg_media | grep "Total PE"
Total PE 1010
So we'll extend to 1010 physical extents.
lvextend -l 1010 /dev/mapper/vg_media-lv_media 
resize2fs /dev/mapper/vg_media-lv_media
If all went according to plan, you should now have a ~4GB LV with no remounting required.
[root@canard ~]# lvdisplay /dev/vg_media/lv_media
--- Logical volume ---
LV Name /dev/vg_media/lv_media
VG Name vg_media
LV UUID iS01Vt-Hyo7-GIiA-Sxlu-rc5J-bX5g-Trd9Ln
LV Write Access read/write
LV Status available
# open 1
LV Size 3.95 GB
Current LE 1010
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

0 comments:

Post a Comment