Useful tool and commands

  • Add ssh support for a virtual machine
#> VBoxManage setextradata "" "VBoxInternal/Devices/e1000/0/LUN#0/Config/dienstName/Protocol" TCP
#> VBoxManage setextradata "" "VBoxInternal/Devices/e1000/0/LUN#0/Config/dienstName/GuestPort" 22

    #> VBoxManage setextradata "" "VBoxInternal/Devices/e1000/0/LUN#0/Config/dienstName/HostPort"

    e1000 is the name of the network adapter which is used
    or use this

#> VBoxManage modifyvm "" --natpf1 "guestssh,tcp,,8022,,22"
  • Resize virtual harddisk to 20GB
#> VBoxManage modifyhd .vdi --resize 20000
  • Mount vdi image
    Do it as root or with sudo

    #> modprobe nbd max_part=16

    #> qemu-nbd -c /dev/nbdX 
#> mount /dev/nbdXpY

    when you finished

#> umount /mnt/
#> qemu-nbd -d /dev/nbdXls
  • Compacting VirtualBox Disk Images
    • Windows Guests
      1. Delete Unnecessary Files
      2. Defragment the Disk
      3. Clean any free disk space
        Download sdelete:
        Start a DOS prompt:

        C:\> sdelete.exe -z c:

        -z: zero any free space.

        C:\> sdelete.exe -c c:

        -c clean any free space.

      4. Shutdown guest image
      5. Compact the Windows guest image
        VBoxManage modifyhd --compact ".vdi
    • Linux Guest
      1. Clean any free disk space
        dd if=/dev/zero of=zerofillfile bs=1M
      2. When the dd is completed, you will see a message that there is no space left on the device
        dd: writing 'zerofillfile': No space left on device
      3. Remove zerofillfile
        rm zerofillfile
      4. Shutdown the Linux Virtual Machine
      5. Compact the Linux guest image
        VBoxManage modifyhd --compact .vdi