How to Resize/Increase the Virtual Disk “LVM” of a Xen DomU Guest Virtual Machine
In this mini post, I’ll show you how to resize/increase the size of the virtual hard disk used in a Xen DomU virtual machine “guest”. One of the challenges that comes with managing Xen domU instances is dealing with virtual machines that run out of disk space. If the initial setup was not done carefully, you may find that resizing the virtual machine is a bit more involved than it sounds, especially if the domU is backed by a disk image or single physical partition.
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. We’ll do this task in three steps, Let’s start.
Step 1: Checking the disk’s size of the DomU guest
In this step, we’ll do some checks from the guest VM itself. First we’ll show you the current disk size, run the following commands:
# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTxvda2 202:2 0 15G 0 disk /xvda1 202:1 0 2G 0 disk [SWAP]
lsblk command lists block devices, as you see, we’ve two partitions / and swap.
# df -hFilesystem Size Used Avail Use% Mounted onrootfs 15G 5.4G 8.7G 39% /udev 10M 0 10M 0% /devtmpfs 201M 64K 201M 1% /run/dev/xvda2 15G 5.4G 8.7G 39% /tmpfs 5.0M 0 5.0M 0% /run/locktmpfs 811M 0 811M 0% /run/shm
As you see, our disk is 15 GB and We need to make it 30 GB.
Now power off your DomU guest VM by running the following command:
# init 0
Step 2: Performing the resizing operation from the Dom0 “the xen host”
Now, after we powered off the guest, login to the host “Dom0” and find the disk your DomU is using “found in it’s config file in /etc/xen directory“. For our example here’s our two partitions our VM is using:
# lvstest.mimastech.com-disk storage-pool -wi-ao-- 15.00gtest.mimastech.com-swap storage-pool -wi-ao-- 2.00g
We want to increase the disk to be 30 GB, for more details we run lvdisplay against our disk as follow:
# lvdisplay /dev/storage-pool/test.mimastech.com-disk--- Logical volume ---LV Path /dev/storage-pool/test.mimastech.com-diskLV Name test.mimastech.com-diskVG Name storage-poolLV UUID Ya59cJ-wOT7-QYRz-sfB6-jEUZ-xhZk-GVLl1iLV Write Access read/writeLV Creation host, time xen.mimastech.com, 2015-01-16 18:14:09 +0200LV Status available# open 1LV Size 15.00 GiBCurrent LE 3840Segments 2Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:18
Now comes the important steps “the resizing steps”. To resize our disk we use lvextend command as follow:
# lvextend --size 30GB /dev/storage-pool/test.mimastech.com-diskExtending logical volume test.mimastech.com-disk to 30.00 GiBLogical volume test.mimastech.com-disk successfully resized
Very Good, it successfully increased without errors. Note that we used the option --size with the new size “30GB”.
For more info about lvextend command, read our post: How to Increase the size of an LVM logical volume on Linux systems
Now, we run lvdisplay again to see the new disk details:
# lvdisplay /dev/storage-pool/test.mimastech.com-disk--- Logical volume ---LV Path /dev/storage-pool/test.mimastech.com-diskLV Name test.mimastech.com-diskVG Name storage-poolLV UUID Ya59cJ-wOT7-QYRz-sfB6-jEUZ-xhZk-GVLl1iLV Write Access read/writeLV Creation host, time xen.mimastech.com, 2015-01-16 18:14:09 +0200LV Status availableLV Status available # open 1 LV Size 30.00 GiB Current LE 7680 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:18
Now, we do a filesystem check, run the following command:
# e2fsck -f /dev/storage-pool/test.mimastech.com-diske2fsck 1.42.5 (29-Jul-2012)/dev/storage-pool/test.mimastech.com-disk: recovering journalPass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary informationFree blocks count wrong (5922106, counted=8438479).Fix<y>? yesFree inodes count wrong (0, counted=655278).Fix<y>? yes/dev/storage-pool/test.mimastech.com-disk: ***** FILE SYSTEM WAS MODIFIED *****/dev/storage-pool/test.mimastech.com-disk: 1966162/2621440 files (0.0% non-contiguous), 2047281/10485760 blocks
As you see, the appeared errors are fixed.
Finally, we resize the filesystem using resize2fs command, run the following:
# resize2fs /dev/storage-pool/test.mimastech.com-diskresize2fs 1.42.5 (29-Jul-2012)Filesystem at /dev/storage-pool/test.mimastech.com-disk is mounted on /; on-line resizing requiredold_desc_blocks = 1, new_desc_blocks = 2Performing an on-line resize of /dev/storage-pool/test.mimastech.com-disk to 7864320 (4k) blocks.The filesystem on /dev/storage-pool/test.mimastech.com-disk is now 7864320 blocks long.
We finished our work on the Dom0 “xen host”, now start the DomU guest and check on the new disk size.
Step 3: Checking the new DomU disk size
To check the new disk size, simply we run df command:
# df -hFilesystem Size Used Avail Use% Mounted onrootfs 30G 13G 16G 45% /udev 10M 0 10M 0% /devtmpfs 201M 64K 201M 1% /run/dev/xvda2 30G 13G 16G 45% /tmpfs 5.0M 0 5.0M 0% /run/locktmpfs 811M 0 811M 0% /run/shm
The new root size is 30 GB, we also may use fdisk command as follow:
# fdisk -lDisk /dev/xvda2: 32.2 GB, 32212254720 bytes255 heads, 63 sectors/track, 3916 cylinders, total 62914560 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/xvda2 doesn't contain a valid partition tableDisk /dev/xvda1: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/xvda1 doesn't contain a valid partition table
Perfect, the disk increased now,
Hint: 1.what if the disk's size not changed, in this case we run the resize2fs command again from inside our DomU guest as follow:
# resize2fs /dev/xvda2resize2fs 1.42.5 (29-Jul-2012)Filesystem at /dev/xvda2 is mounted on /; on-line resizing requiredold_desc_blocks = 1, new_desc_blocks = 2Performing an on-line resize of /dev/xvda2 to 7864320 (4k) blocks.The filesystem on /dev/xvda2 is now 7864320 blocks long.
Note the difference in the disk naming in Dom0 and DomU. Again this last step NEEDED ONLY IF THE DISK SIZE NOT INCREASED AFTER DOMU STARTS.
Summary
In this article, we have explained how to increase the disk size of DomU guest VM from the Dom0 host. We used commands with details to show you the different cases we can perform this task.
I hope this article is good enough for you.
See you in other articles.

If You Appreciate What We Do Here On Mimastech, You Should Consider:
- Stay Connected to: Facebook | Twitter | Google+
- Support us via PayPal Donation
- Subscribe to our email newsletters.
- Tell other sysadmins / friends about Us - Share and Like our posts and services
We are thankful for your never ending support.



