This is a bit of a how-to for how to mount a VDI on a SuSE host machine.
REMEMBER: NEVER EVER DO THIS ON A LIVE VIRTUAL MACHINE YOU COULD CORRUPT THE GUEST!!!
On SuSE 11.4 I’ve tried the qemu-nbd way and have had mixed results. It seems to work best after a fresh reboot.
On Fedora I’ve successfully gotten libguestfs to work. I’ll put a link for those who might be looking for a way to accomplish this on Fedora…on a SuSE Forum. However, due to a compile error I’m not able to get it to work properly, and with this working I’m too lazy try and fix it.
You’ll see that I have rsync used in the script; that is because I wanted a backup of the virtual machine without having to send the whole VDI across the network every time.
How to mount a VDI file (as taken from my own documentation):
Download and install libguestfs-mount (libguestfs, library for accessing and modifying VM disk images) or from
Fedora’s package manager. From here, we are going to perform the following
/usr/bin/guestmount --ro -a /path/to.vdi -m /dev/sda1 /where/to/mount/it/to
This will cause to’s partation 1 (/dev/sda1) to be mounted on the host’s
Obviously, if we need the machine’s second partation or anything we simply
specify from that option.
This does use FUSE to mount, so to unmount you use fusermount -u /path
There are also several other tools that you can use to interact with the
guest operating system. A big one being guestfish, this will inspect the
the image and allow some manipulation.
IMPORTANT TO NOTE: NEVER do this on a live machine. This can cause disk
corruption for the guest.
On SuSE I had to do it another way, as libguestfs is not aviable:
zypper in nbd qemu modprobe nbd max_part=16 qemu-nbd -c /dev/nbd0 ./path/to.vdi mount /dev/nbd0p1 /media/
Let’s take this apart. First we install qemu and nbd these are the tools we
are going to use to mount the device.
We need to avtivate the kernal modues for nbd and set the maximum of
partitions to 16 (should be default)
Now, to link the vdi to a nbd node.
Finally, mount it and use just like you would with any other filesystem
Tip: Open VirtualBox VDI file using libguestfs | Richard WM Jones
libguestfs, library for accessing and modifying VM disk images
How to Mount a VirtualBox VDI Hard Drive Image in Fedora 15 – RyanRhode.com
##mounts guest hard drives
##–ro read only
##-a mount this image
/usr/bin/guestmount --ro -a /home/user/VirtualBox\ VMs/webserver-backup/webserver-backup.vdi -m /dev/sda2 /backup-webserver/
##This “syncs” the virtual image and the local copy
/sbin/modprobe nbd max_part=16
/usr/bin/qemu-nbd -c /dev/nbd0 /backup/image/webserver-backup.vdi
##give it some time
/bin/mount /dev/nbd0p2 /backup/webserver-backup
/usr/bin/rsync -avzru email@example.com.IP:/backup-webserver/ /backup/webserver-backup
/usr/bin/qemu-nbd -d /dev/nbd0