VirtualBox Administrative Details

Moving/Copying a Disk to Another Host

  • the simple answer is "grab the VDI and go"
  • BUT: that doesn't work if you have snapshots - grabbing the VDI and going will get you an older state of the machine (presumably at he point the first snapshot was made)
  • do a full clone, then grab that VDI
  • if you can't afford the space to make the clone, the alternative is to "flatten" the snapshots - delete all snapshots, and their state will be incorporated into the main image (but that's a one-way trip)
  • a better method may be to grab the entire folder (if that folder includes the original VDI - which it won't if you originally brought the VDI in from elsewhere, in which case grab that too). At the target host, put the folder in your "VirtualBox VMs" folder and use the "Machine" -> "Add" command in the graphical interface

Recompressing a .VDI disk image

  • VDI hard disk images expand to support the material in them (up to a hard limit that you set when you create it)
  • when you delete stuff, they don't shrink
  • if this is an issue, there's a fix:
  • in the Linux guest (as root): dd if=/dev/zero of=/bigemptyfile bs=4096k  && rm /bigemptyfile
  • shutdown the guest
  • run vboxmanage modifyhd /path/to/thedisk.vdi --compact
  • I had to supply a full path to VBoxManage.exe under Windows, but otherwise no problem
  • HD is compressed (although not to what "df" inside the guest shows - looks like you split the difference between that and the original size)
  • courtesy of:

Host-to-Guest (aka "Host Only") Communication

  • go to VirtualBox -> File -> Preferences -> Network -> Host-only Networks
  • default is to create one called vboxnet0 with a default of, and a DHCP server (both the name and the IP range are adjustable)
  • until you do this, you can't set "Host-only Adapter" in the per-machine Network settings
  • my SliTaz install knows about eth1 (intnet) and eth2 (vboxnet0) but doesn't bother to bring either up
  • Debian guest doesn't bring intnet or vboxnet0 up by default either, but all that was needed was dhclient eth2 in the guest to bring the interface up as
  • in the host, ssh root@ immediately connected, no further changes required
  • most of this was sourced from (thanks!)

Resizing a VDI HD

UPDATE: better (or at least different) method using the host machine

  • I went looking for this because OpenWRT's default x86 image size has a 50MB partition, and I wanted it bigger:

VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize <SIZE_IN_MB>

  • this command has has reportage of mixed results online, but worked fine in this context (make a backup)
  • I'd recommend you read the notes at - if you don't, the caveat "don't do it with snapshots" is probably most important
  • it looks like the command actually prefers to be applied to an HD image VirtualBox already "knows" about (ie. registered/usable with/in VB - I saw weird reaction trying to resize a copy of a "registered" HD)
  • of course the extra space isn't seen by the partition yet
  • there's the classic Linux method of doing this, which includes unmounting the root partition, using a command line partition editor (always scary) and then resize2fs, but I thought "what if the OpenWRT VDI can be seen as a secondary HD by a Linux virtual machine?"
  • add the VDI as a secondary disk to a virtual Debian when it's not in use
  • VirtualBox -> Settings (for Debian Stretch in my case) -> Storage -> add the OpenWRT VDI as a secondary on the SATA Controller (when I set the OpenWRT as primary on the IDE, the virtual machine tried to boot OpenWRT rather than Stretch)
  • from there it was simple to run gparted, which is a much easier way to resize the partition
  • it was at this point in the process that things failed with a different OpenWRT image: the partition you're expanding has to be something gparted understands, and it doesn't seem to know squashfs (most people wouldn't use the x86 squashfs version, I was experimenting)
  • power off the Debian Stretch (or whatever distro you used) and make sure you remove the extra VDI when done!