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.


    1. I find this works better btw: lvextend -l +100%FREE /dev/vg/lv

    2. Thanks for that. For anyone reading, this would be in place of step (5) above. Apparently, one can also now do: lvresize -l +100%FREE /dev/vg/lv. I do not know what difference there might be between these two commands.

      1. The difference comes when there is more than one logical volume the 100%VG will fail because you cannot assign 100% (since the other lv is already using some). So you need to say that you want to add all the free space to a certain lv instead. That is what +100%FREE does. Add all the free space to certain LV.

    3. This article can help .... I can read them with new knowledge ... thank you so much for what was given to me

    4. I get the error below and I'm afraid of doing the e2fsck:
      [root@firedragon ~]# /sbin/resize2fs /dev/data/data
      resize2fs 1.39 (29-May-2006)
      /sbin/resize2fs: Filesystem has unsupported feature(s) while trying to open /dev/data/data
      Couldn't find valid filesystem superblock.
      [root@firedragon ~]# /sbin/e2fsck -f /dev/data/data
      e2fsck 1.39 (29-May-2006)
      /dev/data/data is mounted.

      WARNING!!! Running e2fsck on a mounted filesystem may cause
      SEVERE filesystem damage.

      Do you really want to continue (y/n)? no

      check aborted.
      What should I do?

    5. FIXED - I used resize4fs and it worked


    6. Yes, sorry, I should update this at some point. Especially with the introduction of EXT-4 there have been some changes in which programs you really have to use. That said, my sense, generally speaking, is that it is better to do all of this on an unmounted filesystem, if that is at all possible.


    Comments welcome, but they are expected to be civil.
    Please don't bother spamming me. I'm only going to delete it.