Virtual Box Cheat Sheet

Exit scaled view

[RIGHT CTR] + [C]

Send CRTL-ALT-F2

[CTRL RIGHT] + F2

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/autorun.sh

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

/etc/fstab

  • 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/.../autorun.sh
    • 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

http://muffinresearch.co.uk/archives/2010/02/08/howto-ssh-into-virtualbox-3-linux-guests/

  • 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. 192.168.56.1)
  • Boot the virtual machine
  • vi /etc/network/interfaces
    • auto eth1
      iface eth1 inet static
        address 192.168.56.10 #choose another ip in the same network as noted above
        netmask 255.255.255.0
  • 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

From http://zcourts.com/2013/06/02/configuring-ubuntu-for-virtualbox-to-detect-usb-devices/

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

Performance

Virtualbox VBoxClient process uses much CPU

https://askubuntu.com/questions/63420/how-to-fix-virtualboxs-copy-and-paste-to-host-machine

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

compiz high resource utilization in virtual machine

https://unix.stackexchange.com/questions/386888/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

https://forums.virtualbox.org/viewtopic.php?f=1&t=39362

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."

 

https://www.digitalocean.com/community/tutorials/how-to-install-bacula-server-on-ubuntu-14-04

 

https://github.com/bup/bup

https://github.com/egorFiNE/bigsync/

Check it out

virt-backup

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