mpack wrote:skoehler wrote:what's the default alignment of the data inside VDI files?
The drive image must be aligned on a 512byte boundary (1 sector), at minimum.
I hope that they are more clever than that

For the asynchronous I/O there are using, it's crucial that the I/O requests (especially writes) are aligned to full clusters of the host filesystem, which would be 4k for most filesystems.
mpack wrote:That used to be the practice as well, however I think recent VBox versions now align the internal image of new drives on a 4K boundary - but it's been a while since I checked that. Of course neither alignment of the drive image ensures that the boot partition is optimally aligned. It's impossible to guarantee the perfect alignment at drive creation time, the partitions don't exist yet!
Well, let's assume a reasonable installer (like the one of Windows 7 or recent Linux distributions) which align partitions to 1Megabyte boundaries.
Also, Windows XP can be installed in a "proper" way such that the partition starts at sector 2048 instead of 63.
However, when you create a virtual machine, you actually chose the operating system. So virtualbox knows about the OS when creating the virtual harddisk - well, if you use the wizard - and they could have chosen to align the VDI data in different way. Be that as it may be, I'd like a tool to verify the alignment of the data within a VDI file, to avoid any surprises.
mpack wrote:skoehler wrote:Googling for this sort of stuff, somebody claimed that he had written a tool for aligning the data inside the VDI file such that sector 63 starts at a 4kB boundary. Which is probably a bad idea, since the second and third partitions may be badly aligned after using that tool.
That "somebody" was me, see sticky in "Windows Hosts" for the CloneVDI tool download, and I'm open to better ideas if you have any.
Aligning sector 63 of an XP drive on a 4K boundary will typically place the boot A.K.A. OS partition on a 4K alignment, which is optimal for application loads, page swaps etc, i.e. most things that really affect performance. Also, XP drives typically only have one partition. If the virtual drive contains more than one partition then it's impossible to align them
all on 4K boundaries unless the partitions happen to be spaced that way within the drive image - which is beyond the control of my tool, or indeed any tool which only tweaks the VDI header and not the image. In fact partitions on an XP drive will typically not be aligned on 4K boundaries, they will be aligned on cylinder boundaries, usually assumed to be 63 sectors for legacy reasons.
Yes, this is all correct, as long as one keeps using windows xp's partitioning tool.
However, the existence of your tool, the possibility to align the data within the VDI file in some almost arbitrary way got me a bit worried, since there is no tool to tell which alignment is actually used by a given VDI file. And I need to know that, before I start aligning the partitions within the virtual machine (the gparted guys still suck at providing an UI which makes it easy to do so, unfortunately). In fact I have aligned the partitions in my WinXP machines to 1MB boundaries.
Also, I worry about that tool you wrote. Does it allow you to chose the alignment? Or does it always align sector 63 to a 4k boundary?
mpack wrote:At the time I wrote the message which you referenced, the vast majority of VirtualBox VMs were, AFAIK, XP and Linux. The 63 sector alignment idea works well for those. True that the Linux swap partition remains randomly aligned, but that makes it no worse off than before. However Vista and Win7 VMs have become more popular since then, and I know those do use different default partition alignments, though I don't have the details to hand. From memory I think it's 128 sectors to the first partition, I don't recall how further partitions were aligned. I note that VirtualBox's new 4K image alignment should work well for Vista/Win7 if this is true. I'm not really a Linux user, so I couldn't tell you what alignments it typically uses: AFAIK the default was and still is 63 cylinders, per the PC legacy.
Recent versions of Linux tools (like fdisk, gparted, but not cfdisk I believe) and Windows 7 (and maybe Vista) align partitions in such a way, that partitions start at a sector number which is a multiple of 2048 (1MB alignment).
OSX seems to align partitions to multiple of 40 (20KB alignment, not chosing a power of two seems really dumb to me).