http://blog.sleeplessbeastie.eu/2012/04/29/virtualbox-convert-raw-image-to-vdi-and-otherwise/

VirtualBox - convert RAW image to VDI and otherwise
Posted on April, 29 2012 by milosz
VirtualBox command-line interface (VBoxManage) provides an easy way to convert raw disk image to the VDI/VMDK format and otherwise.

Let's assume that we have raw image of the sdb device:

$ sudo dd if=/dev/sdb of=./sdb.raw

To use it with VirtualBox we need to convert it to the VDI format (note the
"Fixed" format -- if you don't specify this, you get a "dynamic" disk which
might not work. The input is a fixed-size image, so it makes sense to convert
it to a fixed size disk.):

$ VBoxManage convertdd sdb.raw sdb.vdi --format VDI --variant Fixed

(If this doesn't work and gives VERR_VD_INVALID_TYPE or VERR_INVALID_PARAMETER, try:
$ VBoxManage convertdd sdb.raw sdb.vdi --format VDI --variant Standard,Fixed
)

To use it with VMware we need to convert it to the VMDK format:

$ VBoxManage convertdd sdb.raw sdb.vmdk --format VMDK
Convert between VDI/VMDK formats:

$ VBoxManage clonehd sdb.vdi sdb.vmdk --format VMDK
$ VBoxManage clonehd sdb.vmdk sdb.vdi --format VDI

Convert to the RAW image:

$ VBoxManage clonehd sdb.vdi sdb.raw --format RAW

To find out the offset of the disk, in a fixed-size VDI (the "offData" field):

$ VBoxManage internalcommands dumphdinfo [NameOfImage].vdi

Alternative solution to get back raw image after applying modifications is to use qemu-img command from qemu package:

$ qemu-img convert -f vmdk sdb.vmdk -O raw sdb.raw

Now we can write image to the device:

$ sudo dd if=./sdb.raw of=/dev/sdb