- Category: Xen Howtos
- Published: January 22, 2009
- Written by Grant
Scenario: In the Dom0 (Host) you have a file that you export to the DomU (Guest) and it appears as a hard drive partition and you want to make it larger.
Example- Dom0: /srv/xen/diskimage.img -> DomU: /dev/xvda1
Resize the Disk Image in Dom0
1. Shutdown the DomU
2. Create a backup of the Disk Image using the cp command
3. Add extra space to the diskimage using dd. This will add 1GB to the DomU image. Adjust count= depending on how much you want to add. If you want a sparse file use seek= to define the entire disk size.
dd if=/dev/zero bs=1M count=1024 >> ./diskimage.img
or if you want a sparse file
dd if=/dev/zero bs=1 count=0 seek=1G >> diskimage.img
4. Boot the domU
Your view /proc/partitions your disk should now be larger. You will need to use traditional tools inside the DomU to make the partitions/LVs and filesystems larger as outlined below.
Expanding DomU Partitions
In this example we're using /dev/xvda as the drive name inside the DomU. Due to limitations in the way traditional partitions work this tutorial is only useful for resizing the last partition on the DomU drive.
1. Start the DomU and log in as root
2. Run fdisk /dev/xvda
3. Note the last partitions start cylinder, then delete the last partition and recreate it with the start cylinder being the same as before and the end cylinder being the default (end of disk)
4. Save this and exit fdisk
5. Run partprobe to update the kernels partition table. View /proc/partitions to see if the last partition is now larger. If not, reboot.
5. Resize the filesystem on the partition, for example using xvda2: resize2fs /dev/xvda2
Expanding DomU Logical Volumes
If you configured your DomU to use LVM and your Logical Volume is not big enough you can resize it.
In the DomU we get the Logical Volume name by using the lvdisplay command.
[ root@vs /srv/xen ] lvdisplay
--- Logical volume ---
LV Name /dev/vgsys/lvvirt
VG Name vgsys
LV UUID XMWzWW-oZih-A5uH-91Sa-7l1y-8cqf-18KcNB
LV Write Access read/write
LV Status available
# open 1
LV Size 60.00 GB
Current LE 1920
Read ahead sectors auto
- currently set to 256
Block device 253:2
According to lvdisplay the path to our Logical Volume is /dev/vgsys/lvvirt.
Hot Resizing Logical Volume:
Resizing the Logical Volume is actually very easy, you'll be amazed.
lvresize --size +10G /dev/vgsys/lvvirt
This lvresize command specifies to add 10GB to /dev/vgsys/lvvirt. This will only take a second.
Hot Resizing the filesystem:
That's really it! You can only hot resize if the Filesystem is getting larger. If you need to shrink it then you'll have to take the Volume offline first. Isn't this easier than dealing with partitions that are too small?