How do I extend a partition with a LVM and the contained physical volume and logical volume?

You can do this fairly simply. Kinda surprised there wasn't an answer for this here already.

You can do this entire process while running on the filesystem you want to resize (yes, it's safe and fully supported). There is no need for rescue CDs or alternate operating systems.

  1. Resize the partition (again, you can do this with the system running). GParted is easy to use and supports resizing.
    You can also use a lower level tool such as fdisk. But you'll have to delete the partition and recreate it. Just make sure when doing so that the new partition starts at the exact same location.
  2. Reboot. Since the partition table was modified on the running system, it won't take effect until a reboot.
  3. Run pvresize /dev/sdXY to have LVM pick up the new space.
  4. Resize the logical volume with lvextend. If you want to use the whole thing, lvextend -r -l +100%FREE /dev/VGNAME/LVNAME. The -r will resize the filesystem as well.
    Though I always recommend against using the entire volume group. You never know what you'll need in the future. You can always expand later, you can't shrink.

None of the answers make justice to the power of LVM.

(This is based on @frostchutz comment to the question above.)

Let's get the facts:

  • OP has two partitions, sdb1 and sdb2 is a physical volume for LVM.
  • sdb1 is ntfs right now, we need to give that space to home logical volume inside linuxvg volume group.

LVM steps using the "pragmatic way":

  • create physical volume on sdb1: pvcreate /dev/sdb1
  • add sdb1 to linuxvg: vgextend linuxvg /dev/sdb1
  • extend logical volume home with all free space (and resize filesystem): lvextend -r -l +100%FREE /dev/linuxvg/home

LVM allows great level of indirection. A logical volume is inside a volume group, which could be using several disks.

home --> linuxvg --> (sdb1, sdb2, sdc1)

http://tldp.org/HOWTO/LVM-HOWTO/createvgs.html


The question was solved, after reading this blog post. I will write the solution in short form:

  • boot from a live cd with
  • use gdisk (if you use GPT) otherwise you could go with good old fdisk
  • note your partition settings, in my case gdisk -l /dev/sdb
  • delete your partition with
  • create a new partition with the exact same alignment as the previous one (in my example starting at block 2048)
  • write your new partition table
  • run partprobe -s to refresh the partition table without a reboot
  • resize your physical volume with pvresize /dev/sdb1 or wherever your pv is (use pvs to determine if you don't know)
  • now resize your logical volume with lvextend -l +100%FREE /dev/file/of/your/lv, in my case sudo lvextend -l +100%FREE /dev/linuxvg/home
  • resize the filesystem sudo resize2fs /dev/linuxvg/home
  • first check the consistency sudo e2fsck -f /dev/linuxvg/home
  • enjoy :)

Tags:

Volume

Lvm

Group