Search This Blog

Monday, September 16, 2013

Adding a physical volume to an existing LVM volume

LVM provides the flexibility of relating a logical volume to physical volumes. Using LVM, we can easily resize/extend the size of volume as well as the file system capacity (if you are using resizable file systems such as ext4).

Let's say, if you have a 11GB volume and your filesystem is almost full. Then, you may want to add one more disk and resize your file system. For this task, steps are as follows:

1. create a partition on the new hard disk, using fdisk or parted.
 fdisk /dev/xvdh (when /dev/xvdh is the name for your new hard disk.)
2.  pvcreate /dev/xvdh1
3. vgextend vg /dev/xvdh1 : then your volume group vg will include /dev/xvdh1 into it's associated physical volume.
4. lvextend -l +100%Free -r /dev/vg/lv  : lv is the name of logical volume to extend.

If you want to stripe your data across underlying n physical volumes with 4KB of stripe size, you can do
5. lvconvert --stripes <n> -I 4 /dev/vg/lv


So far, I haven't experienced with any filesystem corruption, when I execute lvconvert.