Normally, the cluster size of the host partition on which VirtualBox VDI files are stored is 4KB. (That applies to NTFS and usually ext2/3/4 host partitions.)
If the position of the start of the guest partition in the VDI file is not aligned to a 4KB boundary, when the guest reads or writes a cluster (4KB) from its partition, that will require two clusters on the host partition to be read/written, since the guest cluster data spans two host clusters. The performance impact of that will vary. It will most likely be greatest in a 4KB random read/write benchmark.
When installing Windows XP, by default the partition created by the Windows installer starts at sector 63. When installing Vista however, the partition begins at the 1MB point (sector 2048).
VirtualBox does not currently allow you to specify the alignment when creating new VDI files. This post describes how to adjust a newly-created VDI so the data corresponding to the start of the guest partition starts at a 4KB boundary in the VDI file.
[For more advanced users, it's also possible to align the "used block map" part of the VDI to fall on a cluster boundary. But that will have a much lower (possibly even not noticeable) impact on performance and I won't mention it here. It's also possible to modify a VDI in which a guest OS has already been installed.]
Note that some figures here are specific to the current VirtualBox version; future versions may differ, but the adjusted VDI will still work with future versions of VirtualBox. The description below is for a dynamically-expanding VDI. ($ before a number indicates hexadecimal.)
This procedure might look a bit tricky. Unfortunately though, if you need to create several VDIs you can't simply do this once then use "VBoxManage clonehd" to clone the empty VDI, since that removes the extra padding from the cloned VDI. Maybe someone can write a little perl script to automate this?
If the exact size of the VDI file doesn't matter, you can simply create one sized so the guest partition starts at the correct alignment (like the first example below, which is aligned optimally for XP). Generally, any multiple of 4096 MB will give a correctly-aligned XP partition. Any (multiple of 4096)+3584 will give an aligned Vista partition.
First let's create a 20GB dynamically-expanding VDI file:
Code: Select all
$ VBoxManage createhd --filename 20GB_test.vdi --size 20480
VirtualBox Command Line Management Interface Version 3.0.12
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Disk image created. UUID: 64097a22-e0df-44b3-91bf-7a0692d36990
Generally, the total size of data in the VDI file before the disk data begins is (with the current version of VirtualBox):
512 + 4*(size in MB), rounded up to a multiple of 512.
In this case, because I chose a round number for the size, it turns out that the XP partition will start at a multiple of 4KB, so everything is okay. 63*512 = 32256 = $7E00. $7E00 + $14200 = $1C000.
But what if we install Vista instead? The partition created by the Vista installer will begin at sector 2048 (i.e. at position $100000). Adding $14200 to that makes $114200, which is not a multiple of 4KB. We need to add $E00 = 3584 bytes to the VDI file and modify the VDI header to align the Vista partition.
To add that number of bytes you can do this (from Linux/Unix command line):
Code: Select all
$ cd ~/.VirtualBox/HardDisks
$ dd if=/dev/zero bs=3584 count=1 | cat >>20GB_test.vdi
Code: Select all
$ echo P | dd bs=1 count=1 of=20GB_test.vdi conv=notrunc seek=345
One more example...
Code: Select all
$ VBoxManage createhd --filename 123456_test.vdi --size 123456
VirtualBox Command Line Management Interface Version 3.0.12
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Disk image created. UUID: b23f0c35-4b50-440a-a02c-9a0e7a4e48b1
Align for XP
For XP, sector 63 would start at offset $78C00 + $7E00 = $80A00. To align that on a 4KB boundary, we need to add $600 = 1536 bytes so it starts at offset $81000. So similarly to before:
Code: Select all
$ cd ~/.VirtualBox/HardDisks
$ dd if=/dev/zero bs=1536 count=1 | cat >>123456_test.vdi
Align for Vista
Sector 0 starts at offset $78C00. So we need to add $400 = 1024 bytes for the Vista partition to be aligned:
Code: Select all
$ cd ~/.VirtualBox/HardDisks
$ dd if=/dev/zero bs=1024 count=1 | cat >>123456_test.vdi
If someone wants to take the time to run some benchmarks, I'd be interested to know how much difference there is between aligned and non-aligned VDIs. Attached is an archive containing a normal 123456MB VDI, and XP- and Vista-aligned VDIs of the same size.