Scenario: In the Dom0 (Host) you have an LVM Logical Volume that you export to the DomU (Guest) and it appears as an entire hard drive which you want to make larger.

Example- Dom0: /dev/VolGroup00/LogVol00 -> DomU: /dev/xvda

 

Resizing an LVM Logical Volume used as a DomU drive

A Logical Volume used as a DomU drive will appear in the DomU as /dev/xvda. A Logical Volume used as a DomU partition will appear in the DomU as /dev/xvda1. Please note the difference.

The disk line in the Xen Domain config file stored in /etc/xen on the Dom0 will look something like this.

disk = ['phy:vgsys/lvvirt,xvda,w']

Get the Logical Volume name and path in Dom0

On the Dom0 we need to expand the Logical Volume. We start by using the lvdisplay command to get the path to the Logical Volume

[ 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
Segments               2
Allocation             inherit
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.


Resizing the Logical Volume in Dom0

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.

Your virtual disk should now be larger inside the DomU. Boot the DomU and log in. You will need to use traditional tools inside the DomU to make the partitions and filesystems larger. Following are examples for Partitions and LVM.

 

Expanding DomU Partitions from within DomU

In this example we're using /dev/xvda as the example DomU device. If your DomU uses standard disk partitions this tutorial only works for resizing the last partition. This is a limitations to standard disk partitions.

1. Start the DomU and log in as root

2. Run fdisk /dev/xvda

3. note the start cylinder of the last partition. Delete the last partition and recreate it with an identical start cylinder and the ending cylinder being the default (end of disk)

4. Save and exit fdisk.

5. Run partprobe. View /proc/partitions to see if it reflects the new size. If not reboot.

5. Resize the filesystem on the partition (assuming xvda2): resize2fs /dev/xvda2

 

Expanding DomU Logical Volumes from within the DomU

We start by using the lvdisplay command inside the DomU to get the path to the Logical Volume we want to resize

[ 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
Segments               2
Allocation             inherit
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:

resize2fs /dev/mapper/vgsys-lvvirt

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?