Virtual Box Cheat Sheet

Exit scaled view




VM Paths

  • File -> Settings -> General -> Default path for VMs:
  • Per VM:
    • General -> Advanced -> Folder Snapshots:
    • Mass storage -> Add, select or remove disk image
      Disk images are also handled in File -> Manager for virtual media

Install guest additions in Ubuntu VM

  • sudo apt install build-essential dkms linux-headers-$(uname -r)

  • Menu -> Devices -> Insert guest additions cd image
  • Yes, download current version
  • sudo /media/myusername/VBox_GAs_X.Y.ZZ/

Shared Folders

Add a shared folder for the desired virtual machine in VirtualBox admin.

Mounting in Ubuntu Automatic

  • Create a shared folder (example) "foo" using the guest menu and select "automount, permanent"
  • Restart the virtual machine
  • The shared folder is mounted in /media/sf_foo
  • Add your user to the vboxsf group to gain access:
    • sudo adduser charly vboxsf

Mounting in Ubuntu Manual

Create a shared folder (example) "foo" using the guest menu.

In the guest OS:

  • sudo mkdir /media/foo
  • sudo mount -t vboxsf foo /media/foo


  • foo                /media/foo                         vboxsf  defaults,noatime        0       0

Mounting in Windows

  • Connect network drive
  • \\vboxsvr\foo

Shared Folders Troubleshooting

  • apt upgrade host and reboot
  • vm -> settings -> remove all shared folders
  • start vm
    • apt upgrade
    • sudo rm /media/* -r          // remove all shared folders
    • reboot
  • vm: Menu -> Devices -> Guest Extension -> Download and install
    • if errors -> cd /media/.../
    • shutdown vm
  • vm -> settings -> add shared folder (auto mount)
  • start vm
    • ls -l /media/sf_xyz/


SSH from host into virtual machine (Ubuntu)

Simple Method

In the vm

  • apt-get install openssh-server
  • vi /etc/ssh/sshd_config
    • PermitRootLogin yes
  • Shut down vm

In Virtual box

  • Edit vm -> Network settings -> Port Forwarding
  • Host port 2222, guest port 22, name ssh, other fields left blank.

Reboot host and guest

On your local compter

  • ssh -p 2222 root@localhost

With separate NIC

  • VirtualBox: File > Preferences/Global Settings > Network > Add (plus sign)
  • Virtual Machine -> Change -> Network -> Adapter 2
    • Enable
    • Host-only Adapter
  • On the host:
    • ifconfig
    • note the IP for vboxnet0 (e.g.
  • Boot the virtual machine
  • vi /etc/network/interfaces
    • auto eth1
      iface eth1 inet static
        address #choose another ip in the same network as noted above
  • sudo ifup eth1

Use Bridge Network for PXE Boot

  • Network
    • Connected to Network Bridge
    • Name: select you ethernet network card of host pc

Installing the extension pack / USB 2.0 Support

  • Reboot
  • Plug in your USB device
  • Start virtual box, edit your VM -> USB
    • Activate USB 2.0
    • Click on the second icon "Add Filter for device" and add your desired device


Make harddisk image small

Cleanup Ubuntu

  • apt-get clean;apt-get auto-clean;apt-get autoremove

Zero all empty disk space (call from within the vm)

  • apt-get install zerofree
  • reboot the vm
  • Hit "ESC" in grub menu -> Recovery -> drop to root
  • mount -o remount,ro /
  • zerofree -v /dev/sda1

shrink image

  • vboxmanage clonehd image.vmdk image_cloned.vmdk

Removing snapshots

  • Always do it from the UI, never delete files manually.
  • It may be easier and safer to do a full clone and delete the old machine

Moving disk images

  • File -> Virtual Media Manager
  • Select disk -> "Release"
  • Select disk -> "Delete" but keep on disk!
  • Move disk image file to desired location
  • Edit the virtual machine -> Storage -> add disk from new location

Create new UUID for a virtual disk image

  • VBoxManage internalcommands sethduuid /path/to/disk-image.vmdk


Virtualbox VBoxClient process uses much CPU

  • pkill VBoxClient && sleep 1 && VBoxClient --clipboard

compiz high resource utilization in virtual machine

  • apt-get install gnome-flashback gnome-session-flashback

VM-Config: 3D Acceleration on, 128MB Video RAM

Check with:

  • /usr/lib/nux/unity_support_test -p

Other tipps:

Searching for a good backup solution

I use bacula for backup with full backups every month, differential every week and daily incremental. Before the job a shell script is run that manages VM snapshots:
A full backup deletes all snapshots, so that a single base vdi is stored. For differential only daily snapshots are deleted, which consolidates the changes into a single weekly difference. Every day and week new snapshots are taken and labeled as such.

To get back an old version I restore the preceding full and differential backups and some incrementals. That gives me the base vdi and snapshots and the machine description belonging to the target state. Only the execution state gets lost if a machine was running during the backup. Or the script might shut down or save the machines. Anyway, after moving the restored files into place the machines should just work."

Check it out


apt-get install libguestfs-tools
virt-sparsify --format raw --convert qcow2 --compress vdisk1.img vdiskcopy.qcow2