Blog Moved

Thursday, July 19, 2012

How To Add to an LVM Drive

One of the great things about LVM is that you never run out of space. If it seems as if you are about to do so, you just add a new "physical volume" to your "volume group", add that to your "logical volume", and resize the file system. In effect, it's as if you have a partition that spans multiple drives.

It would of course be a good idea to back things up before you do this. But sometimes we don't have that option, do we?

I'll suppose our existing volume group is "vgroup", and our existing logical volume is "vvolume".

All of this of course needs to be done as root.

A little hint first: You can (and probably should) give the "-t" (test) option to each LVM command first, to make sure it's going to do what you want. Then I hit up arow (history) and delete the "-t" option, so I make sure I'm running that same command.
  1. Add the new disk to the machine, and format whatever space we want on it (all of it, if we wish) as type 8e (Linux LVM). I'll assume this is now /dev/sde1.
  2. Create a physical volume:
    # pvcreate /dev/sde1
  3. Add the physical volume to the volume group:
    # vgextend vgroup /dev/sde1
  4. Check your work:
    # vgdisplay vgroup
    You should now see something like:
    VG Name               vgroup
    System ID             
    Format                lvm2
    Metadata Areas        2
    Metadata Sequence No  5
    VG Access             read/write
    VG Status             resizable
    MAX LV                0
    Cur LV                1
    Open LV               0
    Max PV                0
    Cur PV                2
    Act PV                2
    VG Size               3.68 TiB
    PE Size               4.00 MiB
    Total PE              1192327
    Alloc PE / Size       476931 / 1.82 TiB
    Free  PE / Size       476931 / 1.82 TiB
    VG UUID               JitzBk-zFH0-vhzm-XhYk-V5Xi-Nt7d-87K9En
    
    Note the free space we now have.
  5. Extend the logical volume:
    # lvresize -l 100%VG /dev/vgroup/vvolume
    The "-l 100%VG" says to resize to use all of the space in the volume group assigned to this logical volume. The argument can be given many ways. See "man lvcreate".
  6. Check our work:
    # lvdisplay
  7. Now we are ready to resize the filesystem:
    # e2fsck -f /dev/vgroup/vvolume
    It made me do that first.
    # resize2fs /dev/vgroup/vvolume
The LVM HowTo covers all of this.