Using Virtualbox to create VMs

Part of the Kubernetes the hard way on bare metal/VM. This is designed for beginners.

Drew Viles
7 min readDec 14, 2021
Virtualbox Logo.

Introduction

This guide is part of the Kubernetes the hard way on bare metal/VMs series. On its own this may be useful to you however since it’s tailored for the series, it may not be completely suited to your needs.

Virtualbox is a popular system that allows you to run virtual computers (Virtual Machines — VM — guests) on a real one (Host PC). This means you can turn one PC or server into many. Many companies and open source projects provide VM services from VMWare to libvirt/KVM/QEMU.

Installing Virtualbox

To install Virtualbox you just need to download the appropriate package for your system and install it.

Once you’re done you’ll be presented with a screen like this

A fresh installation ready to go.

I recommend you do is to change the default location where you’ll store any VMs that will be created. To do this Select File -> Preferences and then under General change the Default Machine Folder to whatever you’d like. This isn’t required, just recommended if you want to store them in a different location to the default such as on a disk other than the one holding the main operating system allowing the VMs to survive OS re-installs and wipes.

In preferences you can also manage much more such as the creation of NAT Networks. This is beyond the scope of this tutorial.

Close the preferences menu.

Create a VM

Click on New or click Machine -> New. Both do the same.
Now fill out the details as shown in the image. If it looks different to what you see below, click the “Expert Mode” button.
The name of the VM can be whatever you like. It is recommended you get the type as close to the system you plan to install. You’ll be using Ubuntu in this tutorial and so should select that*. Set the amount of memory (RAM) you’d like to assign to the VM and ensure you have the option to create a new virtual hard disk checked.

*If you don’t see any 64-bit options is likely you don’t have Intel (R) Virtualization Technology or Intel (R) VT-d Feature available or enabled. If you do, then make sure Hyper-V (Windows only) is disabled as this can also cause issues with Virtualbox.

Create the VM

Now you’ll be prompted to create a new disk, you need to enter a name if it’s not already filled in with the name of the VM, or you’d like to call it something different. Set a size*, select VDI as the disk type and set it to dynamically allocated then click create.

*You can set the size to whatever you want really and it isn’t technically limited to the size of your disk. The dynamic allocation only uses what the guest OS needs and is what allows you to set a 2TB disk size for the VM on, for example, a 500GB physical disk. In reality you’d only be able to use up to the size of the disk you have, 500GB in this example, but it means you can move the VM to a larger disk later and that will allow your 2TB virtual disk to continue expanding. Obviously in a real-world scenario you would not do this as over allocating resources can lead to a system lock up but it’s definitely possible for the sake of testing. This also applies for CPU and memory allocation, just don’t over do it because if your VMs do utilise all the resources thrown at it, it’ll make your host machine hang and crash.

Create the disk

And you’re done. You have a VM.

If you press Start, it won’t actually do anything other than prompt you for a startup disk. The startup disk is the file that will be used to install an operating system. You can acquire these from various places such as from Microsoft for Windows, Apple for MacOS* and many places for Linux such as Debian, Ubuntu, CentOS, Fedora, Elementary OS and many, many more.

*Running MacOS in VMs is sketchy at best and requires some work converting the disk into Apple supported formats — HFS+.

Once you have your ISO, select it and click start, you’ll now be taken through the process to install your operating system.

Select your boot ISO and you’re ready to go

I won’t be taking you through the process of installing the OS as this is a whole tutorial of its own. See the following guide for steps on how to install Ubuntu. (You’ll need additional disks for this tutorial — see Storage below in Extra Credit)

Extra Credit

In this section you will see how to add additional disks, change the network type and some other bits. Everything you do will be within the settings of the VM you just created. Click the VM and select Settings in the top bar or right click the VM and select Settings.

General

In here you can adjust the type of system you want. You can enable one way or two way copy & paste and drag & drop from your host to the VM by setting Shared Clipboard and Drag ’n’ Drop as appropriate. I usually go for Bidirectional so that it works both ways. You can also add a description and enable disk encryption.

General

System

In here you can manage the Memory and CPU resources along with the boot order and some other aspects such as hardware virtualisation and more.

System

Display

In here you can adjust the amount of video memory that is given to your VM. You can adjust the monitor count, enable acceleration enable remote display access and enable screen recording.

Display

Storage

In this section you can attach an ISO by clicking the Empty optical drive (highlighted in image) and then on the right, clicking the icon next to Optical Drive:, this will prompt you to select or choose an ISO/Image file.

Storage

You can also add additional disks in this section by clicking on the Controller: Sata option and then clicking the plus icon on the disk (not the optical drive icon), this will prompt you to choose or create a new disk.

Add additional disk

Audio

You can adjust audio driver & controller settings as well as enabling audio input under this tab.

Network

If you want to isolate the VM on it’s own network but still have internet access from it then set Attached to to NAT.

If you want to have internet access and be able to access the VM from external networks or your local network, set Attached to to bridged adapter and set it to your hosts NIC. (I have br0 here as I have a bridge interface, you may see eth0, ens3 or something slightly different — especially on Mac and Windows). You can add multiple network adapters by clicking the other adapter tabs and enabling them.

Network — Bridged Mode

Serial Ports

In the event you need access to a serial port you can pass them through via this screen. It’s similar to how the network works, you attach it to a physical port.

USB

You can pass USB devices to the VM in this section. For example, you may need to access a USB stick or need a microphone or webcam from within the VM and so you can pass them through here.

USB

Shared Folders

You can link folders from your host PC to your VM in here. You might need to manually mount it depending on what your guest OS is.

Machine Folders

User Interface

Under this section you can enable and disable elements of the user interface by hovering over and selecting/deselecting the checkboxes as appropriate.

Conclusion

You have been through the basics of using Virtualbox today.

What you’ve learned:

  • How to change the default storage location for new VMs
  • How to create a new VM in virtualbox
  • How to adjust some settings of the VM.

Go make yourself a cup of tea and relax, you’re done!

Next: Back to tutorial

--

--