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

Leave a comment

About Reini Urban

user-pic Working at cPanel on B::C (the perl-compiler), p2, types, parrot, B::Generate, cygwin perl and more guts (LLVM, jit, optimizations).