Linux Basics: Convert IMG Files To VDI Format For Oracle VirtualBox

Today, we will see quick tip, yet useful one, about how to convert IMG Files to VDI format for Oracle VirtualBox.

What is .VDI Files?

As you may know, .VDI is the default and usable format in VirtualBox. VDI file, stands for Virtual Disk Image, is a standard virtual hard drive that can be mounted as a separate hard disk while creating a new virtual machine using VirtualBox. It can be created either fixed or dynamically allocated.

A dynamically allocated hard drive file will only use space on your physical hard drive as fills up up-to a maximum fixed size, although it will not shrink again automatically when space on it is freed. This will initially be very small and not occupy any space for unused virtual disk sectors, but will grow every time a disk sector is written to for the first time, until the drive reaches the maximum capacity chosen when the drive was created.

A fixed size hard drive may take longer to create on some systems but it is often faster to use. It will be created on your host system which has roughly the same size as the virtual disk’s capacity. So, for a 10G disk, you will have a 10G file. Note that the creation of a fixed-size image can take a long time depending on the size of the image and the write performance of your hard disk.

What is .IMG Files?

The .IMG files are normally bitmap files that contain image data. The image that is contained in the IMG file can be either a graphic bitmap or an image of a disc. When an IMG file contains an image of a disc, then the file can be used to play the disc media on your computer without the need for the physical disc. It is similar to an ISO file. You can use the IMG files to play video games or gaming application without having the actual gaming disc while you are playing.

Convert .IMG Files to .VDI files for Oracle VirtualBox

Now, let me show you how to convert IMG files to VDI format and vice versa. Make sure VirtualBox is installed and started first.

Convert IMG file to VDI file:

Go to the location where you have the IMG file, and convert it to VDI format as shown below.

Syntax:

VBoxManage convertdd source_file.img destination_file file.vdi

For example:

VBoxManage convertdd console-os-dr1v2-haswell.img console-os-dr1v2-haswell.vdi

Sample output:

Converting from raw image file="console-os-dr1v2-haswell.img" to file="console-os-dr1v2-haswell.vdi"...
Creating dynamic image with size 441679872 bytes (422MB)...

That’s it. Now we can use this VDI file for VirtualBox.

Convert VDI File IMG File:

In case you want to convert VDI file to IMG, enter the following command instead. It is very similar to the above command. Just exchange the source and destination format in reverse as shown below.

VBoxManage convertdd console-os-dr1v2-haswell.vdi console-os-dr1v2-haswell.img

Sample output:

Converting from raw image file="console-os-dr1v2-haswell.vdi" to file="console-os-dr1v2-haswell.img"...
Creating dynamic image with size 439353344 bytes (419MB)...

How to use VDI File in VirtualBox?

Well, We converted IMG file to VDI format, now what? We’ll add it to the Virtual machine and play it.

To do that, open Oracle VirtualBox and create a new virtual machine. When it ask you to create virtual hard drive file, select the option Use an existing virtual hard drive file, and browse to the VDI file which we just have converted from IMG file.

Create Virtual Machine_003

That’s all. Click the Create button and play the newly created virtual machine.

Cheers!

  • bill_v523

    Ok, I created an .img file from a cloned vdi partition, then ran the vboxmanage command on it and it creates a useable vdi, however it stops at black screen. I’m assuming because I created it from a virtual machine partition, it doesn’t contain the necessary MBR? However, I have the original install disk Windows XP Home Edition 32bit and thought I could insert it and boot from it. I get the boot from CD option when I press F12 but then get a fatal message that is unable to read the disk. The reason I attempted this approach rather than a full re-install of XP. 1. because full re-install of XP is very outdated and may not be able to get the old updates loaded
    2. The original (cloned) vdi is 320GB and I want to create a new one of only 40GB (VBox doesn’t allow for shrinking the original VDI’s, only enlarging them). What is preventing the converted image from booting from a CD ROM? Also tried a Linux live disk.