• Edit
  • Delete

Virtual Box Cheat Sheet

Shared Folders

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

Mounting in Ubuntu:

Create a shared folder "foo" using the guest menu.

In the guest OS:

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

Mounting in Windows

  • Connect network drive
  • \\vboxsvr\foo

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.

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


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

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://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