Converting physical disk to Virtualbox image

Converting physical disk to Virtualbox image

A couple of days ago my little linux router died after serving me fine for more than 13 years. Unfortunately I had not a recent backup at hand so I was in need to get access to the disk. Since I had no "old enough" hardware available, I was looking for a way to convert the physical disk into an Virtualbox image which in the end turned out be quite easy. All you need to do is to create in image of the physical disk using dd and converting that to a .vdi image file via the VBoxManage tool that is shipped with Virtualbox:
 

sudo dd if=/dev/sdb of=./debian.bin
VBoxManage convertfromraw debian.bin debian.vdi --format VDI


Replace /dev/sdb above with the device you want to convert. Be aware that that you need to convert the whole disk not just the partition that you might actually want to access. Otherwise you might not be able to boot the machine afterwards. In the end all you need to do is to create a new virtual machine in Virtualbox and add the newly created .vdi disk image to machine.

Since I could boot the image now I was able to backup all the files I needed. But as it turns out I was not able to setup the networking in the virtual machine. So I was looking for a way to access the filesystem of the virtual machine from my local linux box. There seems to be tool named virtualbox-fuse which can be used to mount a .vdi image file directly but the package seems to longer to live in the Ubuntu repo and I was not able to install the version I found on Launchpad. Luckily I came accross this blog article which shows how to achieve the same effect using qemu. In the end it all boils down to the following commands:
 

sudo apt-get install qemu
sudo rmmod nbd
sudo modprobe nbd max_part=16
sudo qemu-nbd -c /dev/nbd0 drive.vdi
# p1 is the first partition on the disk
sudo mount /dev/nbd0p1 /mnt
# unmount device when finished
sudo qemu-nbd -d /dev/nbd0


Achievement unlocked!


Eintrag von Stephan Hochdörfer am 14.12.2013

Tags: Virtualbox, Linux

Diese Webseite verwendet Cookies, um die Bedienfreundlichkeit zu erhöhen. Mit der Nutzung unserer Webseite wird das Einverständnis erklärt, dass wir Cookies verwenden. Weitere Informationen.