six demon bag

Wind, fire, all that kind of thing!

2012-11-16

Loop-mount VirtualBox Disk Images

On Linux you can mount disk images via loopback devices. Partitions inside disk images can be made accessible via kpartx from the multipath-tools. Unfortunately this does not work for VirtualBox disk images (.vdi). It's possible to loop-mount those disk images as network block devices, though.


You need qemu-nbd (on Debian: apt-get install qemu-utils) and the nbd kernel module for this:

modprobe nbd max_part=16
qemu-nbd -c /dev/nbd0 /path/to/some.vdi

That will connect the file some.vdi to the device /dev/nbd0. If the disk image is partitioned, the partitions will automatically show up as /dev/nbd0p1, /dev/nbd0p2 and so on. These devices can be mounted like this:

mount -o loop /dev/nbd0p1 /mnt
# do stuff
umount /mnt

Disconnect the network block device to detach the disk image:

qemu-nbd -d /dev/nbd0
rmmod nbd

Posted 01:53 [permalink]