Moving from Virtual to Physical is even Easier – DD does the Magic

A few weeks ago I had a post on a process I’ve put together to move an Ubuntu installation from a virtual machine to a physical notebook. The core of the procedure was to use Clonezilla in the VM to create a backup and then to restore the backup on an empty SSD in a notebook. While this works well, I’ve now discovered another option that is even simpler: Create a raw disk image of the VM’s disk and write that to a USB attached SSD. And that’s it! In practice, that’s done with 4 shell commands:

Preparation Notes

I use Virtualbox on my notebook, but the idea of just writing a disk image in raw format will work with other hypervisors as well.

UEFI vs. BIOS

By default, Virtualbox uses a good old fashioned BIOS for booting virtual machines. The physical world, however, has long ago switched to UEFI for booting. In my case, I’ve already set-up the VM with UEFI from the beginning, as the plan was to eventually bring it into the physical world.

Creating a Disk Image Without Snapshots

In my case, I’ve created quite a number of snapshots of the VM disk image for the installation I wanted to run on a physical notebook. Virtualbox’es raw disk image ‘create‘ command does not seem to like this, so I cloned the VM, which collapses all snapshots into a single disk image for a new VM:

VBoxManage clonevm "ubuntu-original-vm" --name "ubuntu-bare-metal" --register

This command creates a new VM with the name “ubuntu-bare-metal” which contains a single .vdi disk image.

Creating a Raw Disk Image

The following command creates a raw disk image from the compressed .vdi image file. The size of the raw image file is the full size of the disk, so make sure you have enough space left on the host’s disk.

In my case, the intermediate ubuntu-bare-metal.vdi file had a size of 18 GB, and the ubuntu-vm.img raw disk image had a size of 65GB, i.e. the size I originally created the virtual disk with.

VBoxManage clonemedium disk "/home/martin/PATH-TO-VMs/ubuntu-bare-metal.vdi" "ubuntu-vm.img" --format raw

DD to the Physical Disk

And now it’s time to write the .img file to the physical disks. BEWARE, make 2x sure you write to the correct block device. Here’s an example with sdX, replace the X with the drive letter the USB attached disk has been assigned on your device. You can list available block devices with ‘lsblk -e 7‘ (-e 7 excludes loop devices):

sudo dd if=ubuntu-vm.img of=/dev/sdX bs=4M status=progress conv=fsync

sync

Finally

Once dd is finished and the drive is sync’d, it can be removed from the host and inserted into a notebook. As UUIDs are used, it doesn’t matter that the VM used /dev/vda to address the drive, while in the notebook the drive is probably identified as /dev/nvme0n1. Nothing else is required, the notebook just boots.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.