I recently had a Windows 7 Virtual Machine stored on an undersized qcow2 file. This post steps through the simplest way that I know to produce a new, bigger disk and expand the filesystem onto it.
Empty out the empty space
Because the guest VM is stored on a QCOW2 file, we can recover un-used space on disk by zeroing it out now. Download the sdelete utility from Microsoft and run it on the system.
|
|
One this is done, power off the guest.
Assuming the host is linux, you need the `qemu-utls` and `libguestfs-tools` packages to follow these steps. On Debian-
|
|
Move the VM image to a new filename and inspect it.
|
|
The file
command indicates that the disk is about 30GB expanded.
|
|
The qemu-img
command shows that the disk is 83% full:
|
|
Check out your FS names, note that /dev/sda2
is the disk we want to up-size in this case
|
|
Make a new, bigger disk image
Create a new disk of the desired size. In my case, 50G is sufficient:
|
|
The file
command shows that this new empty disk image is larger than the old image.
|
|
Copy the old disk to the new one. The --expand
option names a partition which will be grown to fill the extra space.
|
|
The virt-resize
command shows a progress bar while it works, and zero-blocks will be reclaimed as a result of the output format:
The final line of output suggests holding on to your backup until you’ve checked it, which is wise:
“Resize operation completed with no errors. Before deleting the old disk, carefully check that the resized disk boots and works correctly.”
Check that the new disk is valid and contains partitions at the expected size:
|
|
Boot up the guest
When the machine boots up, you may get a disk check prompt. Because the console I was using triggered the ‘Press any key to cancel’ prompt, I had to reboot and leave the console disconnected in order for the check to start.
After booting, the C:\
drive should display at its new size: