Tuesday, May 19, 2015

Resize qemu (.qcow2) images

Scenario:  You have a working VM (qemu) which is running out of disk space. You need to add more space without destroying its current contents.

The following steps will let you accomplish the task.
  1. Backup the image first.
  2. Check if it is in qcow2 format:
    file winxp.qcow2
  3. Boot the image and take note of the current sizes of the entire disk (use fdisk command) and partitions (use df command).
  4. Resize the image (for example add 10GB of unallocated space):
    qemu-img resize winxp.qcow2 +10GB
  5. Run qemu to boot the gparted[1] live cd:
    qemu-system-i386 -hda winxp.qcow2 -cdrom gparted-live.iso -boot d
  6. From within gparted live resize the nearly full partition to "eat" the unallocated space we added (10 GB). Apply the changes. You may need to move partitions especially if you have many. Exit from gparted live.
  7. Boot the image and check if the changes have been reflected. Again use df and fdisk commands.
[1] http://gparted.org/livecd.php

No comments: