Updated at Feb 2, 2017

Here are some tips on effective use of Virtual Box in your development.

Resource

Give enough resource to your virtual machine by setting cpu cores and memory size. The default setting is always too conservative.

And also, the disk can be dynamically allocated so don’t be afraid to give it more space.

headless mode

If you are just using your Linux VM like a server, you can launch it in headless mode, so you don’t have to open Virtual Box application to use your virtual machine. You can open it like this: VBoxManage startvm --type headless [your-vm-name], then it will run at the background. (If it is a Linux server, the resource usage can be very low).

Using VBoxManage instead of GUI can be convenient sometimes. You might want to explore other features of this CLI tool as well.

Network

NAT and Port Forward

The default network setup in Virtual Box 5.0 is NAT (Network Address Translation). It will probably be the adaptor eth0 with internal IP 10.X.X.X. You can do port forward as followed to ssh into your machine.

Like this: . And add the following to your ~/.ssh/config:

Host [your-vm-name-or-whatever-you-want]
    HostName 127.0.0.1
    Port 3030
    User root

Then simply ssh-copy-id [your-vm-name-or-whatever-you-want] and have fun.

Beyond ssh, you can also forward other ports, such as 80 for http access.

Internal Network

If you want to communicate between VMs, you can add another network adaptor and select it as “Internal Network”.

See this post for details.

Snapshots

One of the best things about virtualization is easy snapshot.

If you are playing with a very fragile development environment, and want to prevent yourself from messing everything up inreversibly, you need snapshots.

For example, a snapshot tree can look like this:

  • Fresh VM installed
    • Environment Deployed
      • Git source cloned
        • Compiled
          • First stage development done

You can restart from any stage, or forming different branches.

Vagrant

The Vagrant is a tool that “create and configure lightweight, reproducible, and portable development environments”.

You can download boxes and get a fresh VM instantly with ssh etc. well configured. Besides, by combining with HashiCorp’s other services, you can scale up easily.