Increasing CentOS LVM disk size on XenServer

The disk size of a CentOS virtual machine on XenServer can be increased with the following steps. The current VM contains one disk of 8 GB which is divided into a boot partition and an LVM partition:

# fdisk -l
    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
/dev/xvda2              64        1045     7875584   8e  Linux LVM
# pvscan  
PV /dev/xvda2   VG VolGroup   lvm2 [7.51 GiB / 0    free]
Total: 1 [7.51 GiB] / in use: 1 [7.51 GiB] / in no VG: 0 [0   ]
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      3.6G  714M  2.7G  21% /
tmpfs                1000M     0 1000M   0% /dev/shm
/dev/xvda1            485M   68M  392M  15% /boot

We will boot into single user mode in the VM. Within XenCenter open the host console and type the following:

# xe vm-list | grep "Name of VM" -b1
1622-uuid ( RO)           : 573530fb-fbb5-67f8-8d45-43671faa2574
1682:     name-label ( RW): Name of VM
1715-    power-state ( RO): running

Note the UUID of the VM and use that in the following command:

xe vm-param-set uuid=573530fb-fbb5-67f8-8d45-43671faa2574 PV-args=single

Now shutdown the VM and resize the disk of the VM in XenCenter, e.g. to 12 GB. Start the VM and create a new partition of type Linux LVM:

# fdisk /dev/xvda
n
p
3
Enter
Enter
t
3
8e
w

Reboot the VM and increase the disk size in the VM:

# pvcreate /dev/xvda3
# vgextend VolGroup /dev/xvda3
# lvextend -L+3.99G /dev/VolGroup/lv_root
# resize2fs /dev/VolGroup/lv_root

Open the host console again and revert to the standard VM arguments:

xe vm-param-set uuid=573530fb-fbb5-67f8-8d45-43671faa2574 PV-args=

Finally, reboot the VM and check the new size:

# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      7.5G  715M  6.4G  10% /
tmpfs                1000M     0 1000M   0% /dev/shm
/dev/xvda1            485M   68M  392M  15% /boot

17 thoughts on “Increasing CentOS LVM disk size on XenServer

  1. Permalink  ⋅ Reply

    Jørn Klungsøyr

    April 24, 2013 at 3:51pm

    Thank you for an excellent article.
    This saved me tons of work! 🙂
    Thanx! Jørn

  2. Permalink  ⋅ Reply

    Jamie

    September 30, 2013 at 10:31pm

    Yes, thanks! awesome!

  3. Permalink  ⋅ Reply

    Ju'

    November 12, 2013 at 6:06pm

    Thank you for these instructions, t just worked perfectly.
    I had to replace the ‘.’ with a ‘,’ inside this command line :
    # lvextend -L+3.99G /dev/VolGroup/lv_root
    Probably because my locale was FR.

    Thanks again !

  4. Permalink  ⋅ Reply

    José Renato Castro Milanez

    February 13, 2014 at 1:44pm

    Great tutorial.

    I have a question to you. If I don’t have LVM partitions, what I need to do to expand the xvda1 partition? Take a look at my fdisk output:

    Device Boot Start End Blocks Id System
    /dev/xvda1 * 1 38628 310272000 83 Linux
    /dev/xvda2 38628 39163 4299776 82 Linux swap / Solaris

    • Permalink  ⋅ Reply

      Criggie

      August 1, 2016 at 1:04am

      You’re screwed. Your root partition is followed by the swap partition, so any new blocks in the VM’s disk are after swap.

      So your best option is to swapoff -a
      edit /etc/fstab and disable your swap partition line
      then use fdisk to delete the swap partition, write and reboot.
      Then expand your xvda1 with fdisk, and create a new swap partition at the end.
      Save and reboot to load partition table.
      then use xfs_growfs /dev/xvda1 or resize2fs /dev/xvda1
      Recreate your swap with mkswap /dev/xvda2
      Edit /etc/fstab and reenable the swap line, and run swapon -a
      That should sort you.

  5. Permalink  ⋅ Reply

    Dan

    September 25, 2014 at 5:03pm

    Can’t thank you enough for this! Awesome writeup

  6. Permalink  ⋅ Reply

    Ons

    April 14, 2015 at 1:35pm

    Great post ! Thanks.

  7. Permalink  ⋅ Reply

    Vann

    May 5, 2015 at 6:32pm

    Absolutely wonderful! Thank you so much! Works like a charm!!!

  8. Permalink  ⋅ Reply

    octavio narvaz

    June 26, 2015 at 1:06am

    Wow. Thanks… That was awesome.

  9. Permalink  ⋅ Reply

    Brooks Rockett

    February 13, 2016 at 1:17am

    Thanks a lot, this was super helpful! I had to tweak a couple things but it was fairly straightforward.

  10. Permalink  ⋅ Reply

    Mauro

    May 26, 2016 at 12:46pm

    I need to do the opposite, reduce the dimension of the disk. How can I do?

    • Permalink  ⋅ Reply

      Criggie

      August 1, 2016 at 1:05am

      Build a new VM with a smaller disk, and copy the relevant data over. Reducing disk allocation is not supported in Xenserver.

  11. Permalink  ⋅ Reply

    Criggie

    August 1, 2016 at 1:07am

    The CLI is not required in later versions of XenCenter – all the CLI work can be done in the Storage tab. This certainly works in 6.2, 6.5 and 7.0.

  12. Permalink  ⋅ Reply

    George

    November 20, 2016 at 12:47am

    2 things
    to extend to the maximum avaiable blocks

    lvextend -l +100%FREE /dev/volgroup/logvol

    On Centos 7 which uses xfs you cannot use resize2fs
    use this instead

    xfs_growfs /dev/centos/root

  13. Permalink  ⋅ Reply

    Ana Brenda

    August 3, 2018 at 6:12am

    Thanks… Save my job.

Leave a Reply

Your email will not be published. Name and Email fields are required.