How to Resize/Increase the Virtual Disk “LVM” of a Xen DomU Guest Virtual Machine

undefined

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:

# lsblk 
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda2 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 -h
Filesystem Size Used Avail Use% Mounted on
rootfs 15G 5.4G 8.7G 39% /
udev 10M 0 10M 0% /dev
tmpfs 201M 64K 201M 1% /run
/dev/xvda2 15G 5.4G 8.7G 39% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 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:

# lvs 
 test.mimastech.com-disk storage-pool -wi-ao-- 15.00g 
 test.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-disk
 LV Name test.mimastech.com-disk
 VG Name storage-pool
 LV UUID Ya59cJ-wOT7-QYRz-sfB6-jEUZ-xhZk-GVLl1i
 LV Write Access read/write
 LV Creation host, time xen.mimastech.com, 2015-01-16 18:14:09 +0200
 LV Status available
 # open 1
 LV Size 15.00 GiB
 Current LE 3840
 Segments 2
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block 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-disk 
 Extending logical volume test.mimastech.com-disk to 30.00 GiB
 Logical 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-disk
 LV Name test.mimastech.com-disk
 VG Name storage-pool
 LV UUID Ya59cJ-wOT7-QYRz-sfB6-jEUZ-xhZk-GVLl1i
 LV Write Access read/write
 LV Creation host, time xen.mimastech.com, 2015-01-16 18:14:09 +0200
 LV Status available
 LV 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-disk 
e2fsck 1.42.5 (29-Jul-2012)
/dev/storage-pool/test.mimastech.com-disk: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong (5922106, counted=8438479).
Fix<y>? yes
Free 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-disk 
resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/storage-pool/test.mimastech.com-disk is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
Performing 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 -h
Filesystem Size Used Avail Use% Mounted on
rootfs 30G 13G 16G 45% /
udev 10M 0 10M 0% /dev
tmpfs 201M 64K 201M 1% /run
/dev/xvda2 30G 13G 16G 45% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 811M 0 811M 0% /run/shm

The new root size is 30 GB, we also may use fdisk command as follow:

# fdisk -l

Disk /dev/xvda2: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/xvda2 doesn't contain a valid partition table

Disk /dev/xvda1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /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/xvda2 
resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/xvda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
Performing 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.

undefined

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donate
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

Your email address will not be published. Required fields are marked *