16 September 2022

Using Virtualbox to Set Up a Virtual Environment

When looking to create a lab, one option would be to obtain physical machines. However, it is possible to install virtual machines on a single computer using virtualization technology such as Virtualbox. This requires that your host computer has sufficient resources, such as memory and storage, with the amount of resources that you allocate to the virtual machine being shared by your host computer. This post will cover how to set up a virtual machine which will run the Ubuntu operating system.

Downloading and Installing Virtualbox

Start by downloading Virtualbox from here. Once downloaded, the setup can be run by accepting the defaults for each step. After this has been done, an operating system also needs to be downloaded. This demonstration will be using Ubuntu 22.04.1.

Creating a Virtual Machine

  • With Virtualbox open, select "New":

New VM

  • Enter the details for the virtual machine you are creating:

VM details

  • Specify the amount of memory for the virtual machine:

VM memory

  • Select "Create" to create a hard disk and continue to select "Next" while accepting the "VDI" and "Dynamically allocated" options:

VM hard disk

VM hard disk type

VM storage

  • You will then need to specify the hard disk size then click "Create":

VM size

  • Set the processor to use 2 CPUs under Machine > Settings > System > Processor:

VM processor

Installing Ubuntu on the Virtual Machine

  • Select Optical Drive > Choose a disk file and select the Ubuntu iso file to insert it into the virtual machine

VM optical drive

  • Start the virtual machine:

Start VM

  • Select "Try or install Ubuntu":

Try or install Ubuntu

  • Select "Install Ubuntu":

Install Ubuntu

  • Continue until "Updates and other software" - this setup will be using a minimal installation:

  • Next, select "Erase disk" and continue with the installation:

Installation type

  • Enter the user details and password:

Ubuntu user

  • The installation will begin and once finished, the virtual machine will need to be restarted. Below is the virtual machine once this process is complete:

Ubuntu desktop

Installing Guest Additions

In this section, we will be installing the Guest Additions software that comes with Virtualbox. This will allow us to use the virtual machine with an increased resolution in full screen and enable a shared clipboard for copying text between the virtual machine and the host computer.

  • Select Devices > Insert Guest Additions CD image:

Inserting Guest Additions

  • Open a terminal by right-clicking and selecting "Open in Terminal"
  • Run sudo apt update to update the package lists:

Updating package lists

  • Run the below to install pre-requisite packages:

sudo apt install gcc make linux-headers-$(uname -r)

Installing packages

  • We can then install Guest Additions by running:

cd /media/lab/VBox_GAs_6.1.38/
sudo ./VBoxLinuxAdditions.run

Installing Guest Additions

  • Once that's done, the virtual machine will need to be restarted
  • The shared clipboard can be enabled by navigating to Settings > General > Advanced and setting it to "Bidirectional":

Enabling shared clipboard

tags: virtualbox virtualization