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
Increasing CentOS LVM disk size on XenServer
Tagged on:     

18 thoughts on “Increasing CentOS LVM disk size on XenServer

  • 2013-04-24 at 15:51
    Permalink

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

    Reply
  • 2013-11-12 at 18:06
    Permalink

    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 !

    Reply
  • 2014-02-13 at 13:44
    Permalink

    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

    Reply
    • 2016-08-01 at 01:04
      Permalink

      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.

      Reply
  • 2014-09-25 at 17:03
    Permalink

    Can’t thank you enough for this! Awesome writeup

    Reply
  • 2015-05-05 at 18:32
    Permalink

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

    Reply
  • 2015-06-26 at 01:06
    Permalink

    Wow. Thanks… That was awesome.

    Reply
  • 2016-02-13 at 01:17
    Permalink

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

    Reply
  • 2016-05-26 at 12:46
    Permalink

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

    Reply
    • 2016-08-01 at 01:05
      Permalink

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

      Reply
  • 2016-08-01 at 01:07
    Permalink

    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.

    Reply
  • 2016-11-20 at 00:47
    Permalink

    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

    Reply
  • 2020-09-10 at 20:19
    Permalink

    Great article. Curious to know what the data loss risks are with this process. Will everything remain intact?

    Reply

Leave a Reply to José Renato Castro Milanez Cancel reply

Your email address will not be published. Required fields are marked *