Mount VDI on physical host
Posted on 2016/12/27
Wanted to access a few files on backup of a Virtual Box vdi harddrive. So after quite a bit of Googling and prowling forums I found the following few commands that helped me mount a VDI file on my physical host:
First and foremost you'll need to install QEMU to give us a few needed tools to achieve our goals here. For quick reference just use:
sudo apt-get install qemu-kvm qemu virt-manager virt-viewer libvirt-bin
After that you'll need to enable ndb, which lets you use the NBD protocol to share the disk image on the network.
See Mounting a QEMU Image for those seeking more information about the protocol and how you might use it with QEMU
To use ndb it needs to be enabled on the system using:
modprobe nbd
Now we'll be able to mount the virtual hard drive as a "physical" device that can be read from ( and written to :) ) by the system:
qemu-nbd -c /dev/nbd0 <vdi-file>
For those looking to reduce the size of their VDI files, this is where you'll be able to run
zerofree -v /dev/nbd0p1
which will clear up quite a bit of space (Macbook AIR's rejoice !)
After which you can simply mount the harddrive as you would any other device:
mount -o remount,ro /dev/nbd0p1
And can be unmounted in the usual way as well:
umount /dev/nbd0p1
When you are finished, remember to "disconnect" the hard drive to avoid data loss:
qemu-nbd -d /dev/nbd0
What's currently keeping me busy

Testing and keeping websites safe

Tech/product of new incubating startups

Advocate and educate on the Google Cloud

Easy prescribed book management

Loadshedding being constantly updated and watched

Secret management for PAAS

National microchip database

Youtube channel of edited meetup talks

Gaming Youtube Channel