Migrating Virtual box VM to Hyper-V

Balkrishan Nagpal
4 min readNov 2, 2020

I started using Virtual box around 4–5 years back and I got so comfortable that I refused to use any other Hypervisor be it VM ware or Hyper-V. Recently when I was trying to set up minikube (Kubernetes on local machine) cluster on my local machine using VirtualBox, I ran into many problems and after spending good amount of time I didn’t get any success. So, I decided to use Hyper-V for virtualization to setup minikube but I knew that once I enable Hyper-V, I won’t be able to use VirtualBox and then what about all my data on VMs in VirtualBox. So, I was wondering how can I migrate my VMs from VirtualBox to Hyper-V. After lots of search, I was able to successfully migrate my VirtualBox VM to Hyper-V. In this post, I will describe all the steps required to do so.

At high level, you need to perform 5 steps to migrate the VM from Virtual Box to Hyper-V

  1. Export the VM from VirtualBox into VHD format
  2. Convert VHD to VHDX
  3. Create a new VM in Hyper-V without disk
  4. Attach Hard Disk with Virtual machine
  5. Set the Boot options

1. Export the VM from VirtualBox into VHD format

Though VirtualBox has the option for this from UI but that didn’t work for me. I was using VirtualBox version 6.1.4. You may want to try with your version of VirtualBox but for me instead of VHD file it was generating a VDI file. So, I decided to use following command and it worked like charm for me

Format of command

VBoxManage clonehd <absolute-path-of-vdi-file> <vhd-destination> — format vhd

Example:

VBoxManage clonehd C:\users\myuser\VirtualBoxVMs\ubuntu.vdi D:\virtualbox-export\ubuntu.vhd — format vhd

Note 1: If your absolute path contains spaces, you will have to wrap the path in double quotes.

Note 2: VBoxManage might not be in your path, so you will to navigate to path where virtual box is installed. This happens to be following location on my machine. C:\Program Files\Oracle\VirtualBox

For those who want to try with Virtual Box UI, here are the steps:

Select the VDI you want to convert, right click and select copy

Select the location where you want to save VHD and enter a name. In Disk image file type, select VHD and click copy. This should generate the VHD

2. Convert VHD to VHDX

  1. Launch Hyper-V Manager and select server in left pane
  2. Under Actions, select Edit Disk…
  3. Click Next on the ‘Before You Begin’ screen
  4. Browse for the copied file. The file will be having a file extension of VHD. Select the file and click Next button.
  5. On the Choose Action window, select Convert and click Next button

6. Select VHDX format and click Next

7. Select Dynamically expanding and click Next

8. Select a name and location for the file and click Next

9. Click Finish and wait for the conversion process to complete

3. Create a new VM in Hyper-V without disk

From actions in top menu, select New → Virtual Machine and follow the wizard. Select the default values during different steps of wizard or change the values as per your convivence.

There is one screen in wizard which you need to take care of. It is Connect Virtual Hard Disk screen. On this screen, select “Attach a Virtual Hard disk later”.

4. Attach Hard Disk with Virtual machine

In Hyper V Manager, right click the VM and select settings. In left pane select IDE controller 0, select Hard Drive in right pane and click Add.

Browse to the path of vhdx file created in previous step and select that. Click Apply.

5. Set the Boot options

Select BOIS in left pane and in right pane move the IDE option to top and select ok.

After going through all the above steps, start the VM and connect to it and you will be able to use the VM through Hyper V. This VM will all the packages and data which you installed on it while working with Virtual box.

Hope this helps.

--

--