How To Set Up Virtual Machines with VirtualBox

Virtual Machines with VirtualBox
(Image credit: Tom's Hardware)

Virtual Machines, aka VMs, provide a wonderful means to explore the world of Linux or other operating systems, without making them your primary environment. Our Windows PC can play host to a plethora of guest operating systems. We can try out the latest Ubuntu, Fedora, Manjaro or Linux Mint safe in the knowledge that we don’t need to spend a penny on extra equipment. Virtual machines aren’t just limited to Linux, we can also install Windows 11 and even macOS on top of our host. 

One of the easiest means to create a VM is Oracle’s VirtualBox, a free app, which provides an easy to use interface and lots of extra features that blend the host and guest OS into one smooth running machine.

In this how to we will download a Linux distro, and create a virtual machine on which to run the Linux OS.

Downloading a Linux Operating System

For a virtual machine it is best to keep the OS choice light. Our preference is Ubuntu so we downloaded the current Long Term Support release, 22.04 and the latest beta of 22.10. The installation for 22.10 worked, but it failed to boot, so we reinstalled using 22.04 and everything went well.

The Linux OS choice is entirely yours, but do consider how much processing power you have to spare. The more powerful the host machine, the more resources we can spare for the VM and its guest OS.

How To Install Linux in a Virtualbox Virtual Machine

1. Download and install Virtualbox to your Windows machine. Accept the default install options which include network interfaces and USB.

2. Click Finish to close the installer and open Virtualbox.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

Setting up a Virtual Machine

1. Click on New to create a new virtual machine.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

2. Name the Virtual Machine and click Next. Virtualbox will automatically suggest the Type and Version of the OS used in the virtual machine by using the name. In our example we are using Ubuntu 22.10 so Virtualbox set the Type to Linux, and Version to Ubuntu.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

3. Set the VM’s available memory and click Next. This will vary depending on your system. We have 32GB of RAM, so we can assign 8GB (8192MB) to the VM.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

4. Select a new virtual hard disk for the VM and click Create. This will start the process of creating a file that will hold the VM’s operating system.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

5. Select a VDI (VirtualBox Disk Image) and click Next.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

6. Select a dynamically allocated disk size and click Next. If you require a specific size, select Fixed size and allocate the space accordingly. Dynamically allocated files will grow with the OS as files are created and applications are installed.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

7. Set the location of the VDI hard disk and set the size of the file. Then click Create. We set the size to 20GB, large enough for an Ubuntu 22.10 install. The size is the maximum that the VM can use so make sure to set a reasonable amount of space.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

Configuring a Virtual Machine

1. Select the VM and then click on Settings.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

2. Select System and click on the Processor tab. Allocate as many cores as you can comfortably allow. If you have a multi-core system, you can allocate multiple cores to the VM. Extended features such as VT-x and AMD-V can also be enabled, should your CPU support them.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

3. Select Display, allocate sufficient video memory and enable 3D acceleration. 16MB Should be enough for a basic install, but if you want a smoother experience, allocate as much as you can. Adding 3D acceleration isn’t essential, but it can help speed-up applications that rely on 3D acceleration.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

4. Select Storage, and under Storage Devices, click on Controller IDE >> Empty and then click on the CD icon and select Choose a disk file.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

5. Select the Linux ISO and click Open

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

6. Click on Network and create a bridged adapter to your physical network connection.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

7. Click Ok to save all of the changes.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

Running the VM in VirtualBox

With the installation complete we can now power up the virtual machine and run the guest OS in VirtualBox.

1. Ensure the correct VM is selected and click on Start. This will boot the VM as if it were a real computer.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

2. Choose Try or Install Ubuntu from the Live CD boot menu and press Enter to start. This will load the OS into the VM’s RAM and enable us to test that the VM works before installation.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

3.Try out the Live Linux OS to make sure that everything works as expected. The screen resolution may be incorrect, at this time we will have to work with it. Later in the process we will install additional drivers to enable more resolutions.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

4. Install the OS to the VM.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

5. Restart once installation is complete.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

Tweaking the VirtualBox VM Installation

Our guest machine can be further tweaked, and helpfully there is a useful Guest Additions ISO image, available inside VirtualBox which adds extra features such as

  • Mouse pointer integration: We can easily move between the host and our guest VM.
  • Shared clipboard: Clipboard items can be shared between host and guest.
  • File Drag and Drop: Copy files to and from the machines.
  • Shared Folders: Share volumes and directories with ease.
  • Better Graphics Support: Accelerated video performance.

To install the Guest Additions we need to take the following steps.

1. Open a terminal and update the list of repositories for your operating system and then run the next command to install packages necessary for the Guest Additions installer.

sudo apt install build-essential dkms linux-headers-generic 

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

2. Click on Devices and select Insert Guest Additions CD image. This is an ISO image that contains extra drivers and features for our VM.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

3. Open the File Manager and click on the CD Drive.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

4. Right click on autorun.sh and select “Run as program”.

(Image credit: Tom's Hardware)

5. Enter your password to run the script with sudo privileges. Sudo will give our user the privileges necessary to install software and make changes to the operating system.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

6. When prompted, press Enter to end the installation.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

7. Reboot the VM for the changes to take effect.

Changing the VM Display Resolution in VirtualBox

The guest OS is not limited to a poor resolution; we can freely change the resolution using the View menu.

1. Click on View >> Auto-resize Guest Display to alter the VM’s resolution on the fly. Drag the cursor on the VM window and set the display size.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

2. To set a specific resolution, go to View >> Virtual Screen 1 and select your desired resolution.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

Connecting a USB Device to Your VirtualBox VM

Adding a USB device, a USB drive, security key or even a Raspberry Pi Pico is possible via the Devices menu. Here we can add audio devices, virtual CD / DVD drives, USB and additional network interfaces. 

Adding a USB device is simple.

1. Insert the USB device into the host machine.

2. Click on Devices >> USB and select the device from the list. The device will now be ready for use.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

3. To prove that the device is connected, open a Terminal and use “lsusb” to list the USB devices connected to the guest OS.

lsusb

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

Powering / Rebooting the Guest OS in VirtualBox

VirtualBox has the ability to control the state of the VM. It can pause a running machine, send a reset signal or even send an ACPI shutdown request to the guest OS.

1. Click on Machine and select Pause.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

2. The screen will grey out, indicating the VM running the guest OS has been paused. Click on Pause to resume the VM. Here we are running the ping command to show that the OS was paused.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

3. Click on Machine >> Reset to forcibly reset the machine. Note that any unsaved work will be lost. This is as if we have pressed the reset button on a PC.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

4. Click Reset to confirm that you wish to forcibly reset.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

5. Click Machine >> ACPI Shutdown to send a shutdown signal to the OS.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

Powering down, reboot , and logout are also accessible via the guest OS menu. This works as if the machine were real hardware.

Virtual Machines with VirtualBox

(Image credit: Tom's Hardware)

Les Pounder is an associate editor at Tom's Hardware. He is a creative technologist and for seven years has created projects to educate and inspire minds both young and old. He has worked with the Raspberry Pi Foundation to write and deliver their teacher training program "Picademy".