FUN WITH LINUX

How to access a Virtualbox VDI-Disk

29 September 2016

Today I wanted to copy a disk-image to a Virtualbox-disk(VDI) using dd. In this article I am going to describe how I managed to access the disk from the Linux command-line, copied the image and mounted a VDI-disk-partition

Binding the disk

First of all I had to bind the disk as a block-device. I used a very handy module named “Network Block Device”. Therefore I needed to load the kernel-module:

modprobe nbd

If the nbd-module was loaded, I could connect the disk using qemu-nbd:

qemu-nbd -c /dev/nbd0 myfancydisk.VDI

Using the block-device

After binding the disk as a network-block-device, I had a disk-device to write on. So I just run dd to copy my image:

dd if=superdisk.img of=/dev/nbd0 bs=4M

Of course it would be possible to partition the disk using cfdisk:

cfdisk /dev/nbd0

Mounting a partition

I could also mount one of the partitions of my VDI-Disk:

mount /dev/nbd0p1 /mnt/tmp

Or umount it again:

umount /mnt/tmp

Disconnecting the VDI-Disk

To disconnect the VDI-disk, I ran qemo-nbd with the following parameter:

qemu-nbd -d /dev/nbd0
[ Linux  Tricks  Shell  Virtualization  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti