This is a quick guide to increasing the disk space available to your Windows virtual machine with an NTFS file system. The example is based on increasing a partition from 5GB to 6GB.
This command increases the size of the disk image in the file Windows_XP_Professional_SP_3.img by 1GB.
qemu-img resize Windows_XP_Professional_SP_3.img +1G
After this command, if you boot your virtual machine, you will see that there is an additional 1GB of free disk space available.
Loop mount the image.
losetup /dev/loop0 Windows_XP_Professional_SP_3.img
Inspect the partition table (here parted is used but fdisk or cfdisk can also be used).
parted /dev/loop0
Within parted, set the units to sectors, then print the current partition table.
(parted) unit s (parted) print
The output will look something like this:
Model: Loopback device (loopback) Disk /dev/loop0: 12582912s Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 63s 11718798s 11718736s primary ntfs boot
Note the Sector size and Start sector numbers in the output.
Now quit parted.
(parted) quit
Delete the loop device.
losetup -d /dev/loop0
Loop mount the NTFS partition to be resized, using an offset calculated from the sector size and start sector.
losetup -o$((512*63)) /dev/loop0 Windows_XP_Professional_SP_3.img
First do a dry run.
ntfsresize -n -s 6G /dev/loop0
If all is OK, do it for real.
ntfsresize -s 6G /dev/loop0
Delete the loop device.
losetup -d /dev/loop0
Loop mount the image.
losetup /dev/loop0 Windows_XP_Professional_SP_3.img
Update the partition table using parted (both fdisk and cfdisk appear to fail here).
parted /dev/loop0
This seems like a backward step, but now use parted to remove the existing partition.
(parted) rm 1
Use the parted rescue command to find the partition again, with the END option set to the size of the partition in MB.
(parted) rescue 1 6000 Information: A ntfs primary partition was found at 32.3kB -> 6000MB. Do you want to add it to the partition table? Yes/No/Cancel? Yes
Set the boot flag on the rescued partition.
(parted) set 1 boot on
The partition table is written when you quit parted.
(parted) quit
Delete the loop device.
losetup -d /dev/loop0
Boot the virtual machine and allow the Windows chkdsk program to run.
* Original source: http://cauldrondevelopment.com/blog/2009/02/26/resize-qemu-ntfs-image/