Managing VDIs


Resize (grow) a VDI

The most straight forward way to enlarge an existing VDI is described in this article, we can summarize it as follow (on a Linux based guest):

Run this while the VM is turned off:

> VBoxManage modifyhd <HARD_DISK>.vdi --resize <SIZE_IN_MB>

Using a GUI

Then launch the VM, you'll need gparted, a graphical tool to manage disk partitions, to then enlarge the file system and use the newly available space on the VDI. In case it is not yet available on your VM, go to:
Menu > Software Manager Search: gparted > Install

Right click on the /dev/sda2 (adapt to your configuration), and select Resize/Move, drag the right limit of the partition to use all additional space available. Then apply the changes.

From the CLI

To be completed….

Mount a VDI to the host system

With the VM stopped:

> apt-get install qemu-utils kpartx
> modprobe nbd
> qemu-nbd -c /dev/nbd0 /path/to/file.vdi
> kpartx -a /dev/nbd0
> mount /dev/mapper/nbd0p1 /mnt

Now we can access files on the vdi:

> nano /mnt/etc/network/interfaces

ADD:
# Static private LAN interface
auto eth1
iface eth1 inet static
   address 172.30.30.XXX
   netmask 255.255.255.0
   broadcast 172.30.30.255
   network 172.30.30.0

To UNMOUNT the vdi:

> umount /mnt
> qemu-nbd -d /dev/nbd0