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!