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
Thank you for an excellent article.
This saved me tons of work! 🙂
Thanx! Jørn
Great post! Works perfectly.
Yes, thanks! awesome!
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 !
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
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.
Can’t thank you enough for this! Awesome writeup
Thanks for the writeup. Worked great!
Great post ! Thanks.
Absolutely wonderful! Thank you so much! Works like a charm!!!
Wow. Thanks… That was awesome.
Thanks a lot, this was super helpful! I had to tweak a couple things but it was fairly straightforward.
I need to do the opposite, reduce the dimension of the disk. How can I do?
Build a new VM with a smaller disk, and copy the relevant data over. Reducing disk allocation is not supported in Xenserver.
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.
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
Thanks… Save my job.
Great article. Curious to know what the data loss risks are with this process. Will everything remain intact?