When doing a standard Linux installation on a XenServer virtual machine, the installation process typically allocates all of the available virtual disk space to the Linux file system and swap partitions. The size of the virtual disk can easily be changed using the XenCenter utility, but as neither the partition table or the file systems themselves are modified by XenCenter, the guest system does not see the new virtual disk size. This article describes how to safely change the partitions.
There are two scenarios:
- the Linux system uses standard Linux partitions
- the Linux system uses Logical Volume Manager (LVM) partitions
The file system sits on top of a single block of data storage, such as a piece of the harddisk or, in the case of a XenServer virtual machine, a virtual block device. It can only be as large as this storage block, but not larger. Therefore, if the file system is to be increased, this storage block must be increased first.
After the size of the storage block has been increased, execute the resize2fs
command, which can be safely run even on a mounted filesystem.
It is very simple to increase the size of the underlying storage block if you are using LVM (and this is a good reason to always use LVM). Just add more blocks to it using the lvresize
command.
The blocks added to the storage block are taken from the current volume group. If the volume group does not have free block, new blocks must be made available by adding a new physical device such as a second harddisk, or by increasing an existing physical device.
Provide more disk space to the guest system
There are two ways to do this: you could either increase the size of the existing XenServer virtual disk, or add a second virtual disk to this guest.
Add a physical device
(todo)
Increase the size of an existing XenServer virtual device
The XenCenter administration software provides a dialog to change the size of the XenServer virtual disk. Select the new storage size by entering the value in the dialog. The virtual disk will be resized to the new value. When increasing the size, the data on the disk is preserved.
Note: do not decrease the size without decreasing the file system first. Otherwise the file system will be damaged.
Increasing the size of the XenServer virtual disk size does not change the filesystem on that disk. So the new disk space is not yet visible to the user. To use the new disk space, the partition table must be modified (which makes the new device size known to the file system) and the file system must be extended (to use the extra space).
The easiest way to do this is delete the last partition and create it again which will then use all of the remaining disk space by default. Obviously, this will work only if the last partition is in fact the partition that is to be increased.
In the example below, the XenServer virtual disk size has been resized from 10 GByte to 50 GByte. The following steps will be performed with fdisk
:
- print old partitions
- delete last partition (#2)
- create new partition using default settings (use the whole virtual disk for this partition)
- set partition type to LVM
- print partitions settings again, note increased size for partition #2
- reboot
master:~# fdisk /dev/xvda The number of cylinders for this disk is set to 6527. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): p Disk /dev/xvda: 53.6 GB, 53687091200 bytes <-- note that fdisk already sees the new device size of 53.6 GB 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x0004e475 Device Boot Start End Blocks Id System /dev/xvda1 * 1 31 248976 83 Linux /dev/xvda2 32 1305 10233405 8e Linux LVM <-- note that the existing entry is still 10 GB Command (m for help): d Partition number (1-4): 2 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (32-6527, default 32): Using default value 32 Last cylinder or +size or +sizeM or +sizeK (32-6527, default 6527): Using default value 6527 Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): p Disk /dev/xvda: 53.6 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x0004e475 Device Boot Start End Blocks Id System /dev/xvda1 * 1 31 248976 83 Linux /dev/xvda2 32 6527 52179120 8e Linux LVM <-- note that the new entry is now 50 GB Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. master:~# reboot Broadcast message from root@master (pts/0) (Fri Oct 2 08:47:05 2009): The system is going down for reboot NOW!
Tell LVM of the new resized physical volume
The partition #2 has now successfully increased in size, now let LVM use the new blocks. Note how the "Free PE" value increases after the pvresize
command.
pvdisplay --- Physical volume --- PV Name /dev/xvda2 VG Name dsk PV Size 9.76 GB / not usable 1.37 MB Allocatable yes (but full) PE Size (KByte) 4096 Total PE 2498 Free PE 0 Allocated PE 2498 PV UUID 7TyUyk-hyVf-0kdC-OCok-QdSJ-lqTE-YFJAi0 master:~# pvresize /dev/xvda2 Physical volume "/dev/xvda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized master:~# pvdisplay --- Physical volume --- PV Name /dev/xvda2 VG Name dsk PV Size 49.76 GB / not usable 3.98 MB Allocatable yes PE Size (KByte) 4096 Total PE 12738 Free PE 10240 Allocated PE 2498 PV UUID 7TyUyk-hyVf-0kdC-OCok-QdSJ-lqTE-YFJAi0
Resize logical volume
The next step is to add those new blocks to the logical volume. The volume group now has an extra 10240 free extents (each 4 KByte in size). New storage can be added to a logical volume with the lvresize
command.
# vgdisplay --- Volume group --- VG Name dsk System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 8 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 49.76 GB PE Size 4.00 MB Total PE 12738 Alloc PE / Size 2498 / 9.76 GB Free PE / Size 10240 / 40.00 GB VG UUID nCjL0f-XWps-G77Z-Oq0t-lMEc-ULsJ-2qFUnw master:~# lvdisplay --- Logical volume --- LV Name /dev/dsk/root VG Name dsk LV UUID QejNO3-8bB0-ykJ0-TUhR-56Ko-W5ed-SvF9fv LV Write Access read/write LV Status available # open 1 LV Size 7.76 GB Current LE 1986 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:0 master:~# lvresize -l +10240 /dev/dsk/root Extending logical volume root to 47.76 GB Logical volume root successfully resized master:~# vgdisplay --- Volume group --- VG Name dsk System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 11 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size 49.76 GB PE Size 4.00 MB Total PE 12738 Alloc PE / Size 12738 / 49.76 GB Free PE / Size 0 / 0 VG UUID nCjL0f-XWps-G77Z-Oq0t-lMEc-ULsJ-2qFUnw
Resize file system
The last step is to resize the file system. This can be done even when the file system is currently in use. However, a reboot is recommended as massive changes have been made to the file system. During reboot, a file system check is executed which will print out a scary warning message but that's normal. The system will reboot again and this time no messages or warnings should be sent.
master:~# resize2fs /dev/dsk/root resize2fs 1.41.3 (12-Oct-2008) Filesystem at /dev/dsk/root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 3 Performing an on-line resize of /dev/dsk/root to 12519424 (4k) blocks. The filesystem on /dev/dsk/root is now 12519424 blocks long. master:~# reboot Broadcast message from root@master (pts/0) (Fri Oct 2 08:47:05 2009): The system is going down for reboot NOW!
20 Comments
Anonymous
Thanks for this great article. Helped me a great deal.
David.
Anonymous
Great article, very accurate and thorough! Thanks!
Anonymous
How do i add some partitions in xenserver host to store my template backup of the VM?
because by default, Xen only creates 4GB of its root which is insufficient in storing backup files?
Hope you may help me....
Thanks!
Administrator
The backups should not be stored on the server anyway. In case of a disk or server crash the backups would be inaccessible.
I am using an NFS server to backup VMs:
You need of course a fast network connection to do this as the backup files tend to be very large.
Anonymous
that is cool! thanks.
Anonymous
Thanks a lot!!! :-)
Anonymous
Most Excellent documenting of the steps needed. This saved me a lot of head-scratching to figure out all the steps end-to-end in resizing a logical volume!
Michael
Anonymous
Hi,
Thanks for this excellent article.
I'm wondering. Deleting the partition table with fdisk, won't this make all the data of the partition unreadable after the resize (like a new format) ?
In my case, I've got a server with an LVM partition (210 GB). I created 2 disks (/dev/mapper/xend1; /dev/mapper/xend2) each 100 GB.
I created 2 virtual machines assigning them xend1, xend2 as hard disks (installing the virtual os on those disks).
First I extended the disk space of my LVM volume group, then, with lvextend I increased the size of xend1. But, as you explained in your article, my vm does not yet see the new disk space.
My concern is when applying the steps explained in your article, that I will have to completely reinstall my vm.
Cheers,
Christian
Administrator
When deleting a partition with fdisk, only the partition table is deleted. The actual data is still in place, but it would not be accessible by the standard OS commands. When you add a new partition right after deleting the partition, the new partition will point to the same data blocks, but will have lots of extra blocks after the end of the existing file system (note that this only works if the deleted and recreated partition is the last partition).
However, if you are using LVM anyway, the easiest solution would be to simply create a new virtual device, which will show up as
/dev/xvdb
, for example. This new virtual disk can then be used to add more blocks to a volume group, so that you can uselvesize
as described. See also How to add additional disks to XenServer host.Anonymous
Too many comlipmnets too little space, thanks!
Anonymous
Thanks - good stuff.
Anonymous
Thanks so much for taking the time to write this very helpful guide. All the best! you helped me a lot.
Just wanted to help anyone out there who might get condused - When you're resizing the logical volume, make sure you do it to the right volume! I got confused and didn't do this on the root volume. (On my Xen machine this is located under /dev/mapper/vg_vmname-lv_root) - and ran into problems when trying to resize the file system.
Thanks again! I'll bookmark this so I can return to it.
Anonymous
Thanks.. Its perfect steps..
Warm Regards
Rupesh Kumar
Anonymous
Much thanks for this article, it was step by step exactly what I needed!
Anonymous
Thank you!
This article was clear, precise and correct! Bravo!
Anonymous
Thank you for your explanation.
It's very detailled and clear, and with examples.
Anonymous
Thank you very much ! Save my day !
Anonymous
Thank you so much for sharing this information!
When I tried to use resize2fs I got a error:
I think resize2fs does not work with XFS partitions, so I had to use lvresize with -r option to "resize underlying filesystem together with the logical volume using fsadm":
Hope it helps someone, and thanks again!
Anonymous
Thanks for the information. It helped me out and worked just fine! Amazingly, I was unable to find the process documented anywhere else! Thanks again.
Anonymous
how to create a virtual machine through installation CD plugged into NFS server, on to a Xenserver on pre-existing NFS VHD. we are using citrix xencenter.