How to resize a NTFS qemu qcow2 image (the easy way)

There's so much bad information out there how to simply resize a NTFS qemu qcow2 (windows in kvm) image, and I need to frequently enhance my windows images, esp. on win8 (64 bit) so I'll document it here for the next time:

  • Don't use fdisk if you have gparted!
  • Don't waste space converting a qcow2 to raw
  • Shutdown the vm!

  • $ sudo su -

  • $ ls /var/lib/libvirt/images/*.qcow2
  • $ qemu-img resize /var/lib/libvirt/images/windows_x64.qcow2 +5GB

  • $ modprobe nbd max_part=63

  • $ qemu-nbd -c /dev/nbd0 /var/lib/libvirt/images/windows_x64.qcow2

  • $ # fdisk -l /dev/nbd0 # or better

  • $ kpartx /dev/nbd0 # to check the partitions and sizes
  • $ ntfsresize --info /dev/nbd0 # to check if the volumes are not dirty

  • $ gparted /dev/nbd0 # enhance the partition size to max

  • $ killall qemu-nbd

  • Start the vm and let windows do the chkdsk /f (in win8 automatically)

  • In winxp you might need to do ntfsresize -x /dev/nbd0p2 manually


# apt-get install libguestfs-tools
# virt-resize --expand /dev/sda2 /dev/vg_pin/Win7x32old /dev/vg_pin/Win7x32

"qemu-img resize" is perfect! Parted rulez! Cheers! :-)

Awesome! Been trying to find that qemu-img command. I there any reason not to use a gparted-live iso in the VM instead of mucking about with NBD?