Creating a basic Ubuntu Virtual Machine

Virtual Box setup

I don’t set up a virtual machine often enough to remember which options I want, or maybe I just have a poor memory. Either way, here are steps to create a simple Ubuntu virtual machine with networking.

Basic Frame

In Oracle VirtualBox, select “New” and answer the prompts as described below.

  • Name: Suggest “xxx-os-version”. Ex:ample “vb2-ubuntu-16-04-01” or “vm1-ubuntu-16041”
    graphic of VirtualBox setup dialog

  • Memory Size: Suggest 8192 MB (8 GB) of RAM, or something less that the host machine has.
    graphic of VirtualBox setup dialog

  • Hard disk: create a virtual hard disk now
    graphic of VirtualBox setup dialog

  • Hard disk file type: VDI
    graphic of VirtualBox setup dialog

  • Disk storage: Dynamically allocated
    graphic of VirtualBox setup dialog

  • File location & size: Size by need, and note that Ubuntu needs at least 25 GB. Suggest creating a directory for all things virtual machine and putting the disk file there.
    graphic of VirtualBox setup dialog

The first time you fire up the virtual machine you will be asked for an operating system file (iso). Download this first and be ready! You can get Ubuntu desktop from http://www.ubuntu.com/download/desktop.
Follow installation instructions. Select download updates while installing ubuntu.
graphic of VirtualBox OS installation dialog graphic of VirtualBox OS installation dialog

For the hostname, suggest “user-vmX”, then you know by the name what user is defined. Example: “carolyn-vm4”
graphic of VirtualBox OS installation dialog

Guest Extensions

These enable cut and paste between host and virtual machine and folder sharing. See http://virtualboxes.org/doc/installing-guest-additions-on-ubuntu/

Open a terminal window and issue the commands:

	sudo apt-get update
	sudo apt-get upgrade #(y to prompt or use -y flag; takes a while)
	sudo apt-get install  build-essential  module-assistant #(y to prompt)
	sudo m-a prepare

From the running VM window select:

  • Devices
  • Insert guest additions CD image
  • run
  • enter root password

Setup Copy-Paste

From the running VM window select: Devices - Shared Clipboard - Bi-directional

Setup a shared folder

  • Select settings on virtualBox dialog or Devices on current VB window.
  • Select shared folders from the left pane.
  • Add a share by selecting the folder with plus sign icon on the right.
  • On the Edit Share dialog:
    • Folder Path is a host directory path; ex: “C:\Users\COwnby\Documents\VBShare”.
    • Folder Name is the name of the share on the VM, ex: “VBShare”.
    • Check boxes for auto mount and make permanent
    • Select OK.
  • Select OK to close the settings dialog.
  • Then from command line issue the command sudo usermod -a -G vboxsf <username>

Completion

Restart the virtual machine.

Nice things to have

Java

Seems that java is required for just about everything. Go ahead and install it now.

sudo apt-get update
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
sudo apt-get install -y oracle-java8-installer

Python

sudo apt install python-pip

Docker

Follow instructions from the Docker store


Networking

I am running VirtualBox from Windows 10, and setting up networking so my machine is outside accessible has been tricky. This can be done with a bridged adapter or NAT networking

Bridged Adapter

With bridged networking, your virtual machine is seen externally as a normal network device. For more information, see Virtual Box Bridged Networking

Under your VM settings, go to the network tab.

  • Attached To: Bridged Adapter
    graphic of Virtual Box Network setup dialog
  • Name: is the device showing connectivity from Control Panel\Network and Internet\Network Connections
    graphic of Wondows Network setup dialog

NAT Networking

An alternative is to use NAT Network with port mapping. A port on the host PC is mapped to each virtual machine, so your VM is externally addressable via the host PC’s IP and a port number. For more information, see Virtual Box NAT Networking

You’ll first need to get the ip address of your virtual machine with ip a. Under your virtual machine settings network tab, set:

  • Attached To: NAT Network
    graphic of Virtual Box Network setup dialog

Then, in Oracle VM VirtualBox Manager

  • select File - Preferences
    graphic of Virtual Box Network setup dialog

  • go to Network tab
  • select the screwdriver
    graphic of Virtual Box Network setup dialog

  • select “port forwarding”
    graphic of Virtual Box Network setup dialog graphic of Virtual Box Network setup dialog

To enable ssh access, for example, you might set:

  • Host Port = 2222
  • Guest IP = virtual machine’s IP address from ip a
  • Guest Port = 22

Then to ssh to the virtual machine, you use

ssh user@host-ip:2222