Using Virtualbox to create VMs
Part of the Kubernetes the hard way on bare metal/VM. This is designed for beginners.
--
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 libvirtd/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
The first thing 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 a disk other than the one holding the 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. 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.
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 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.
And you’re done. You have a VM however there is a problem whereby 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.
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.
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.
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.
Storage
In this section you can attach an ISO by clicking the Empty optical drive (highlighted) and then on the right, clicking the icon next to “Optical Drive:”, this will prompt you to select or choose an ISO/Image file.
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.
Audio
It’s rare you’ll change anything here but you can adjust audio settings here as well as enabling audio input.
Network
Here you can change how the network works. 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.
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.
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.
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 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!