Mounting a VirtualBox hard disk image file (.vdi) in Linux

Searching the web, I found this post about mounting a vdi file in Linux.

  • On Fedora 15, you need to install these packages:

  • # yum install nbd qemu-common

  • To mount a partition on a hard disk image file:

  • # modprobe nbd
    # qemu-nbd -c /dev/nbd0 "file.vdi"
    # kpartx -a /dev/nbd0 # creates mapped devices in /dev/mapper/
    # mount /dev/mapper/nbd0p1 /some/folder # mounts first partition of the image.

  • To unmount:

  • # umount /some/folder
    # kpartx -d /dev/nbd0
    # qemu-nbd -d /dev/nbd0