VirtualBox Disk Images (VDIs) store all of the information & data for a VM. It is the virtualised hard disk drive for running the contained OS.

A while back at work we were migrating to XenServer from VirtualBox to get a stronger virtualisation platform working, as part of this, we had to move the VMs from VirtualBox to XenServer which required the images to be in a format that is compatible with XenServer.

The below instructions describe how to convert the VDI image to IMG format on a Linux system as well as how to check that the converted image works properly.

  • Clone VDI file to IMG [Note: For most VMs there are 2 disks (name.vdi & name-disk1.vdi), use the name.vdi disk]
VBoxManage internalcommands converttoraw /ROUTE/TO/disk.vdi /ROUTE/TO/output.img
  • Check that there are partitions on the img
fdisk -lu /ROUTE/TO/output.img
  • Mount LVM partition for editing/checking files
losetup /dev/loop0 /ROUTE/TO/output.img  # Note: /dev/loop0 doesn't need to exist for this command to work]
kpartx -a /dev/loop0
vgscan 
vgchange -a y VG_NAME  # Note: Output of vgscan will show VG_NAME
mount /dev/VG_NAME/lv_root /mnt/
  • Undo mounting
umount /mnt/
vgchange -a n VG_NAME
kpartx -d /dev/loop0
losetup -d /dev/loop0