Tip: Expand a Windows virtual machine

(You will need virt-resize ≥ 1.4 for this)

My Windows VM is stored in a logical volume on the host. It is 16GB currently, and for the purposes of this example I will expand that to 18GB. virt-resize doesn’t touch the old disk image, so I have to rename the old one and create a new one like this:

# lvrename /dev/vg_pin/Win7x32 /dev/vg_pin/Win7x32old
  Renamed "Win7x32" to "Win7x32old" in volume group "vg_pin"
# lvcreate -n Win7x32 -L 18G /dev/vg_pin
  Logical volume "Win7x32" created

Let’s have a look at how the Windows VM is organized at the moment. Some versions of Windows put the C: drive on the first partition, but recent versions use a small boot partition and have the C: drive on the second partition. virt-resize is only able to resize the C: drive (but for Linux VMs virt-resize can resize any partition including the boot partition):

# virt-list-filesystems -al /dev/vg_pin/Win7x32old
/dev/sda1 ntfs                <-- boot partition
/dev/sda2 ntfs                <-- C: drive

And now we simply do the resize. In this case I’m going to ask virt-resize to expand the C: drive (/dev/sda2). Other choices would be to ask virt-resize to create an extra partition at the end of the disk or to leave the extra space unpartitioned.

# virt-resize --expand /dev/sda2 /dev/vg_pin/Win7x32old /dev/vg_pin/Win7x32
Summary of changes:
/dev/sda1: partition will be left alone
/dev/sda2: partition will be resized from 15.9G to 17.9G
/dev/sda2: content will be expanded using the 'ntfsresize' method
Copying /dev/sda1 ...
[############################################################################]
Copying /dev/sda2 ...
[############################################################################]
Expanding /dev/sda2 using the 'ntfsresize' method

Finally, check that the new copy of Windows boots! (By the way, Windows will do a chkdsk the first time it boots. This is deliberate. We tell Windows to do this so we can be sure that we haven’t damaged any of the data during the copy or resize).

If it boots, you can delete the old copy of Windows:

# lvchange -an /dev/vg_pin/Win7x32old 
# lvremove /dev/vg_pin/Win7x32old 
  Logical volume "Win7x32old" successfully removed

If it doesn’t boot, please file a bug giving all the details, then revert back to the old copy.

Leave a comment

Filed under Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s