Ok, there's another note about this subject - Resize Xen image files - ; but this time, things gets complicated :
- The loopback file attached to the virtual machine does not stand for an unique partition anymore. Now, the file contains the whole disk device : MBR, partition table, etc.
- The filesystem is NTFS
Before going futher, you have to make sure to have fdisk/cfdisk, kpartx, losetup and ntfsresize programs. Use your distribution packaging system to get them.
- Create additionnal space : unlike the old note, this time a sparse file is used. It just means the whole space will not being allocated until really used
$ dd if=/dev/zero of=additional-10G.img bs=1 count=0 seek=10G 0+0 records in 0+0 records out 0 bytes (0 B) copied, 5.0898e-05 s, 0.0 kB/s
- Then, the old image and the additionnal space image will be both concatenes together :
$ cat root.img additional-10G.img > new.img
- From now, new.img file is a disk with 10G additionnal space but with the same partition table. Most tools being able to manipulate the partition table needs a block device. losetup will be used to made new.img file accessible as a block device.
$ sudo losetup -f /dev/loop3
$ sudo losetup /dev/loop3 new.img
- Our new.img is now available as a block device through /dev/loop3. Unix standard tools can now be used to operate on the partition table
- fdisk? cfdisk? You have the choose. But be carefull of the following :
- These tools can barely not resize a partition. You have to delete the partition first and then create it again. This partition has to start at the same cylinder of the old one and to end at least at the old last cylinder + 1.
- Make sure to set to NTFS (07) type to this partition. If not, your partition will not be available from Windows.
- Resizing is done. Now you have to work at the filesystem level. kpartx will be used to access directly to the file underlining partition.
$ kpartx -a /dev/loop3
- Now, the partition is accessible via /dev/mapper/loop3p1 (p1 for first partition). Just use ntfsresize and here we are.
$ ntfsresize /dev/mapper/loop3p1
- Cleaning and it's done.i
$ kpartx -d /dev/loop3
$ losetup -d /dev/loop3 $ mv root.img old.img $ mv new.img root.img
At the next bootup, Windows will check your disk.

Comments
parted better than fdisk...
Hi,
I tried that and it works fine, but not with fdisk to delete/create the partition
I had to use parted because other tools broke the boot sector...
# file windowsvista.img
windowsvista.img: x86 boot sector; partition 1: ID=0x7, active, starthead 32, startsector 2048, 41445652 sectors
parted better than fdisk...
Hi,
I tried that and it works fine, but not with fdisk to delete/create the partition
I had to use parted because other tools broke the boot sector...
# file windowsvista.img
windowsvista.img: x86 boot sector; partition 1: ID=0x7, active, starthead 32, startsector 2048, 41445652 sectors
seevickentiek
TypeReree
rwgg
Steesibrera
yppg
Post new comment