Concise notes for the impatient learner

Uncategorized

Create a Ubuntu Server with VirtualBox and Vagrant on Windows

Tools

VirtualBox
Version 5.2.4 on a Windows 10 host was used for this example.

Vagrant
Version 2.0.1 was used for this example.

Steps

Test your Vagrant installation by running

vagrant --version

The Vagrant box we’re going to use can be found on the Vagrant Cloud site and it’s called trusty64. We do not need to download anything from the site at this point. The box image will be downloaded through commands.

Create a folder on your system. We’ll call it TestVM. From the command prompt, navigate to that folder and use the following command

vagrant init ubuntu/trusty64

The command generates this output that guides you to the next step

A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

The init command just downloaded a Vagrantfile from Vagrant cloud. Now run the command

vagrant up

The command will download the box image, configure it in VirtualBox, and launch it. The progress is reported as the command runs.

Bringing machine 'default' up with 'virtualbox' provider...
 ==> default: Box 'ubuntu/trusty64' could not be found. Attempting to find and install...
 default: Box Provider: virtualbox
 default: Box Version: >= 0
 ==> default: Loading metadata for box 'ubuntu/trusty64'
 default: URL: https://vagrantcloud.com/ubuntu/trusty64
 ==> default: Adding box 'ubuntu/trusty64' (v20171208.0.0) for provider: virtualbox
 default: Downloading: https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/20171208.0.0/providers/virtualbox.box
 default: Progress: 9% (Rate: 414k/s, Estimated time remaining: 0:24:12)

After the command completes, you will see that

  • a .vagrant folder was created inside the TestVM folder
  • The [userhome]\.vagrant.d\boxes folder has the compressed VM  inside the ubuntu-VAGRANTSLASH-trusty64 folder
  • [userhome]\VirtualBox VMs has a folder with the unpacked VM whose name looks like TestVM_default_1514699197045_57539

[userhome] is the home folder of the current user. The path varies depending on the OS.

Open VirtualBox and confirm that the virtual machine is running.

VirtualBox_after_Vagrant_up

To SSH into the box, you can use the command (the default user and password created by Vagrant are both “vagrant”)

vagrant ssh

Alternatively, from VirtualBox, double click on the VM to start an SSH session. This method uses RSA keys.

To install a graphical UI for the virtual machine, run the following commands

sudo apt-get update
sudo apt-get install ubuntu-desktop

Reboot the virtual machine. You can switch to the terminal with Ctrl-Alt-F1 and to Ubuntu Desktop with Ctrl-Alt-F7. You can also launch the command line inside Ubuntu Desktop with the shortcut Ctrl-Alt-T.

Recommended Reading

Pro Vagrant (ISBN: 1484200748)

Leave a Reply