How to mount VirtualBox VDI image files on Linux

This describes how to mount a VDI disc image file on Linux. Please note that it will only work with fixed size images, dynamic images will not work! Also your Linux system has to be able to read the used partition format (ntfs, ext3, vfat, ...).

If you want to access a newly created image, you have to create the partitions first and format them. This should be done inside the virtual machine, booted with some Live-CD (e.g. grml).

As the image contains some metadata at the beginning, we have to find out the offset where the actual partition data begins. We will use the VBoxManage command that comes with VirtualBox.
user@host:~$ VBoxManage internalcommands dumphdinfo YourImage.vdi
--- Dumping VD Disk, Images=1
Dumping VD image "YourImage.vdi" (Backend=VDI)
Dumping VDI image "YourImage.vdi" mode=r/w uOpenFlags=8 File=0x007fcac4003910
Header: Version=00010001 Type=2 Flags=0 Size=8589934592
Header: cbBlock=1048576 cbBlockExtra=0 cBlocks=8192 cBlocksAllocated=8192
Header: offBlocks=4096 offData=36864
Header: Geometry: C/H/S=1024/255/63 cbSector=512
Header: uuidCreation={41a3ecbb-bf26-4c28-861d-388fd665ae6c}
Header: uuidModification={7d16caa6-f8c4-4602-bd15-ec8563c15418}
Header: uuidParent={00000000-0000-0000-0000-000000000000}
Header: uuidParentModification={00000000-0000-0000-0000-000000000000}
Image:  fFlags=00010000 offStartBlocks=4096 offStartData=36864
Image:  uBlockMask=000FFFFF cbTotalBlockData=1048576 uShiftOffset2Index=20 offStartBlockData=0

Find the offData=36864 line. Add 32256 to 36864. This gives us the final offset we need: 69120. Now (as root) mount the images with the following command:

root@host:~$ mount YourImage.vdi /mnt/ -o loop,offset=69120