Introduction

VirtualBox is a popular open-source virtualization software that allows you to run operating systems in virtual machines on your physical hardware. With VirtualBox, you can test out different operating systems like Windows, macOS, Linux distributions without having to install them directly on your machine.

In this comprehensive guide, we will cover everything you need to know about getting started with VirtualBox on an Ubuntu 20.04 host, including:

  • Benefits of using VirtualBox
  • Downloading and installing VirtualBox
  • Creating your first virtual machine
  • Installing guest additions
  • Configuring shared folders
  • Setting up networking
  • Managing snapshots
  • Best practices and optimization tips

Whether you‘re a developer looking to test applications across platforms, an IT professional prototyping infrastructure, or just someone curious about different operating systems, VirtualBox is an excellent tool. So let‘s get started!

Benefits of Using VirtualBox

Before we dive into the installation and setup, let‘s first go over some of the key benefits of using VirtualBox:

Isolation: Virtual machines are completely isolated from the host operating system. This means if something crashes inside the VM, it won‘t affect your physical Ubuntu setup at all.

Compatibility: VirtualBox has support for a wide range of guest operating systems including Linux, Windows, macOS, Solaris and others. It also keeps improving compatibility with newer OS versions.

Portability: You can package a VM with a specific software stack or environment into an .ova file and easily import it on any other system running VirtualBox.

Cost: As an open source solution, VirtualBox is completely free to download and use. This makes it much more accessible compared to paid solutions like VMWare Workstation.

Customization: You have a high degree of control over all aspects of the VMs – system resources allocated, storage, networking, graphics memory and more.

These capabilities make VirtualBox excellent for testing software, running older apps that may not work on newer OS versions, learning new skills and much more without impacting our main system.

Downloading and Installing VirtualBox

The first step is to download and install VirtualBox on your Ubuntu 20.04 system. There are a couple of different ways we can do this.

Install from Standard Ubuntu Repositories

The easiest way is to use the standard Ubuntu repositories. However, this version may not always be the latest.

To install, simply search for VirtualBox in the Ubuntu software center or run:

sudo apt update
sudo apt install virtualbox virtualbox-ext-pack

This will install the latest available VirtualBox version in the repositories along with the extension pack which adds some additional capabilities.

One downside of using the standard repositories is that you will only receive security updates, not major version upgrades. So eventually the version installed this way may become outdated.

Install Latest Version from Oracle Repository

If you want the newest features and keep VirtualBox updated to the latest releases, you can setup the Oracle repository instead:

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add - 

sudo add-apt-repository "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib"

sudo apt update
sudo apt install virtualbox-6.1

This will always keep VirtualBox updated to the latest stable version as Oracle pushes out new releases. The only downside is you‘ll have to re-run the last 3 commands whenever you want to upgrade to a newer release.

So in summary:

  • Use standard Ubuntu repos for a simpler install process but outdated software
  • Setup Oracle repo to always have the latest VirtualBox release

The choice depends on your specific needs. As a beginner, the version from default Ubuntu repositories should be sufficient to get started.

Install from Downloaded Package

You can also manually download and install VirtualBox from Oracle‘s website if you want a specific older release or build. The package will be in the form of a .deb file for Debian/Ubuntu.

To install a manually downloaded .deb:

sudo dpkg -i virtualbox-6.0_6.0.14-133895~Ubuntu~bionic_amd64.deb 

Just replace the filename with whatever you downloaded.

The tradeoff here is that you‘ll have to manually upgrade VirtualBox yourself going forward when new versions release.

So in most cases, setting up the Oracle repository is the best approach. But the choice ultimately depends on your specific preferences.

Creating a Virtual Machine

Once VirtualBox is installed, open up the application. You‘ll be greeted with a blank interface since we haven‘t created any VMs yet:

VirtualBox empty

Click on "New" to kickstart a new virtual machine. This launches the create VM wizard.

It will request the following details:

  • Name – A descriptive name for your VM.
  • Machine Folder – Where the VM files will be stored on your file system.
  • Type – The OS that will run inside this VM.
  • Version – Specific version of the OS.

For example, if you‘re setting up an Ubuntu 20.04 VM, choose type as Linux and version as Ubuntu (64-bit):

Configure new VirtualBox VM

Next, allocate memory (RAM) for the VM. This memory will be unavailable to the host OS when the VM is running.

A good starting point is to assign half of your system RAM if you have 4 GB or more. Otherwise assign 1 to 2 GB depending on how much you can spare on the host.

For hard disk, keep the default option to "Create a virtual hard disk now" and click Create.

On the next screen, the recommended hard disk file type is VDI (VirtualBox Disk Image). Then select "Dynamically allocated" which allows the disk image file size to grow as needed.

Finally, specify a max size for the disk – 10 to 20 GB is usually plenty for most Linux VMs. The location can just be the default on your home folder.

After completing the wizard, your new VM should now show up in the VirtualBox main window.

We‘re now ready to install the guest operating system.

Installing the Guest OS

With the new VM created, the next step is installing an OS in it.

Select the VM and click "Start" at the top. This will launch a startup wizard the first time around.

First choose the ISO file you want to boot and install from. This would either be:

  • Downloaded Ubuntu 20.04 installer ISO
  • Image file of another Linux distro or OS
  • Disk image copied from an existing installation

For Ubuntu and other OS installers, mount the ISO and select it under the optical drive.

Next, pay attention to the boot order. Move "Optical" to the top so that our VM boots from the virtual CD drive first.

With these options set, now hit "Start" to power on the VM!

It should automatically boot straight into the OS installer which will guide you through partitioning disks, creating user accounts etc. The exact steps will depend on which operating system ISO you downloaded.

Follow the on-screen prompts to complete the guest OS installation inside your new VM.

Be sure to remove the ISO from the virtual optical drive once done or else your VM will just loop back into the installer every time!

The process up till now should look something like this:

VM Install Demo

And that‘s it! You now have Ubuntu (or another OS) running smoothly inside VirtualBox.

Installing Guest Additions

One of the first things you should do once your guest OS is up, is install "Guest Additions" for that VM.

This is basically a set of modules and drivers that enhance integration and performance between host and guest.

Some key highlights of what Guest Additions enables:

  • Shared folders – Easily share folders bi-directionally between guest and host
  • Seamless windows – VM windows blend cleanly into host desktop
  • Clipboard sharing – Copy/paste text between host and guest OS
  • Audio support
  • Performance and graphics boost – Video and mouse drivers improve speed

As you can imagine, these add a lot of convenience for daily usage of VMs.

To install Guest Additions, go to the VirtualBox "Devices" menu while VM is running and choose the option to insert guest additions ISO:

Mount Guest Additions ISO

This will connect a virtual CD-ROM with the executable to install drivers.

You may get a popup asking if you want to auto-run software from the drive. Check "Do this automatically" box before hitting Run.

The Guest Additions installer will launch. Follow the on-screen instructions to complete installation and reboot the VM.

That‘s it! You can now benefit from all the additional integration features mentioned before.

Configuring Shared Folders

One of the handiest capabilities unlocked by Guest Additions is bi-directional folder sharing between host and guest OS.

For example, you can access files from your Ubuntu host filesystem while inside the VM. And anything saved to the shared folder in the VM will show up under your Ubuntu home folder.

Let‘s set this up:

On VirtualBox host, go to Machine > Settings > Shared Folders

Click the icon with green "+" to add a new share.

Under "Folder Path" choose a host folder you want to share. Give it an easy "Folder Name". Toggle "Auto-mount" and "Make Permanent" on.

shared_folders_setting

Over in the guest OS, the folder should now be available under /media/sf_[folder-name].

So if I share a vbshare folder on my host, it‘ll mount to /media/sf_vbshare in the Ubuntu 20.04 VM.

Anything you now copy into this folder either inside the VM or on host, will automatically show up in the other side!

Of course there‘s other network based mechanisms like SFTP to transfer files across systems. But Shared Folders make it dead simple with native OS integration.

Setting up Networking

There‘s a few different networking modes to enable guest VMs access your local network or internet connection.

NAT is the easiest and works out the box without any configuration. This routes traffic from VM through host interface which does port forwarding and DHCP assignment.

So VMs get online access and looks like any other device in your LAN from a routing standpoint. Only downside is you cannot directly initiate connections into the VMs from your LAN through NAT configuration.

Bridged makes your VM show up with its own unique MAC address in the network as if it were a physical system. You have to configure IP and network options manually in this case. But bridging eliminates the connectivity constraints of NAT and guest VMs are directly visible to other local devices.

For typical use, especially if you need internet access in VMs, stick with the default NAT configuration.

But for advanced networking with other devices, play around with bridged mode or even Host-only or Internal modes.

Managing Snapshots

Before making substantial changes to a production guest VM, you should create a snapshot.

Think of snapshots like system restore points or "checkpoints" you can roll back to in case something goes wrong. They capture the complete state of a VM at any point.

To create one, make sure VM is powered off first. Then right-click on VM > Snapshots > Take. Give your snapshot a name and hit OK.

You can take as many snapshots as you want which gets recorded in timeline view.

To restore to an older snapshot, select it in the list and choose "Restore snapshot" option. When done with a snapshot you can also delete it to save space.

Snapshots in VirtualBox

Snapshots let you experiment without worry of damaging an important VM. I highly recommend taking regular snapshots of your important VMs.

Best Practices

Here‘s few quick power tips:

  • Install Guest Additions to improve usability, graphics and folders sharing
  • Assign max 2 virtual CPUs to avoid performance issues
  • Disable 3D acceleration if you don‘t need it
  • Limit video memory to 128MB unless you assign large resolutions
  • Use bridged networks for direct LAN access from other devices
  • Take snapshots before making substantial changes
  • Stop VMs when not actively in use to conserve host resources

And as a general rule of thumb, close other demanding apps on the host before firing up VMs.

VirtualBox does eat quite some memory and CPU cycles. So manage its resource usage versus host performance depending on your usage.

With these best practices, your virtual machines should run smooth and maximizing available resources!

Closing Thoughts

There‘s clearly a whole lot more that can be done with VirtualBox – setting up networking, command line usage, scripting automation etc. But I hope this guide covered the key steps for beginners to get started.

We walked through:

  • Benefits and use cases of virtualization
  • Downloading and installing VirtualBox
  • Step-by-step virtual machine creation
  • Configuring Guest Additions for enhancement
  • Enabling handy shared folders
  • Overview of networking options
  • Effective snapshot management
  • Some optimization best practices

You now have everything you need to start experimenting with operating systems and software virtually using VirtualBox!

Similar Posts