Summary

You’ve probably heard phrases like “Spin up a virtual machine” or “Try it out in a virtual machine.” But what are virtual machines, and how can you make use of them?

What Is a Virtual Machine?

A virtual machine (VM) is a software-based emulation of a computer. A program called a hypervisor runs on your computer. It allows you to create virtual machines–virtual computers—and configure them with an amount of RAM, hard drive space, CPU cores, and other details that would normally be provisioned in hardware. Once you’ve configured your VM, you can turn it on and install an operating system.

The hypervisor must emulate the hardware of a physical computer, so that the operating system believes it is running on a normal, physical, computer. It must also pass requests that need to be serviced by the hardware of your actual computer (known as the host computer) through to the host. For example, if an application in your VM tries to access a web site, it interacts with the virtual network card in the VM, but the actual network requests are handled by the network card of the host.

A Fedora virtual machine running on an Ubuntu host.

Because VMs are easy to create, are disposable, and just like using a real computer, they are commonly used for testing, development, and training. you may shut down and restart VMs very quickly, and save snapshots of their current state.

And, because VMs can’t harm the host computer, you’re safe to experiment. They’re often suggested as a great way toinvestigate a Linux distributionyou’re curious about, and this is a great use case for a VM.

The USB settings in VirtualBox.

you may use VMs on macOS, Windows, and Unix-like operating systems such as Linux,BSD, and OpenIndiana. On all platforms, you’ll find free versions of once-commercial hypervisors, such asVMware Workstation, and open-source offerings such asOracle VirtualBox.

I’ve used VMs on Windows and Linux, with the majority of them being on Linux. But actually, using a VM on any platform is the same. Install your hypervisor, configure a virtual machine, and install an operating system in it. Apart from a few Linux-specific observations, everything here applies to all platforms.

Your Computer Has to Be Up to the Task

VMs might be virtual, but they require real hardware to operate. Sadly, we can’t conjure hardware out of thin air. So if your computer has 16GB of RAM you can’t allocate 32GB of RAM to a VM. Nor could you allocate all the RAM you have to a VM and leave nothing for the host to operate on.

You also need sufficient free hard drive space for the hard drives of your VMs to be stored on. Modern hypervisors let you specify amaximum sizeof hard drive for a VM. That way the VM only stores theusedportion of the VM hard drive.

If you want to store snapshots of your VMs, you’ll needhard drive spacefor this too. A snapshot captures the entire state of the virtual machine, allowing you to close it down with applications open and running, and to have it restored to the exact same state when you reactivate it.

Snapshots provide a safety net for your experiments. If you’re about to do something that could adversely affect your VM, take a snapshot first. If your experiment goes badly wrong, restore your saved snapshot and your VM will be in the state it was before your ill-fated changes.

Your CPU must support virtualization, and sometimes you have to turn on virtualization inyour BIOS. Most modern CPUs support virtualization, including the Intel VT-x and AMD AMD-V families ofCPU.

You also need enough CPU power to allow your VMs and your host to run with sufficient speed. If you ever need to set up small networks of VMs and have them running on the same host at the same time, you’ll need a fast CPU and plenty of RAM.

Virtual Machines on Linux

Since 2007, the Linux kernel has supported Kernel-based Virtual Machines (KVM). This means the kernel can behave as a hypervisor. The creation and control of KVM VMs is done with a Virtual Machine Monitor, such asQEMU.

QEMU allows you to emulate specific hardware, including CPUs of a different architecture than the physical one in your host computer. QEMU is a command line program. Beginners might feel more at home with a graphical front end such asGNOME Boxes. GNOME Boxes wraps the complications of QEMU in an accessible and intuitive graphical display.

For me, VirtualBox hits the sweet spot of having enough functionality and configurability without being too fussy and long-winded to set up.

Networking and Accessing Devices

Sometimes you may want your VM to interact with another device on your network, such as a printer. There are several ways to do this with networking, and your hypervisor will probably have a menu of options to let you choose a networking paradigm for your VM.

The default is often Network Address Translation (NAT), which allows your VM to access the internet, download files, and so on. It cannot see any of the networks your host computer is attached to. If isolating your VMs is most important to you, use this mode.

The simplest way to access one of the networks your host computer is attached to is to use bridged networking. If having access to other network devices on your physical network is important to you, configure your VM with bridged networking. This puts your VM on the same network as your host.

It can be useful to let your VM have access to USB devices that are connected to your host. This usually requires you to turn on USB functionality in your VM. You may get a choice of using USB 1.0, 2.0, or 3.0.

When you plug a USB device into your host, your VM will have the opportunity to claim it. When you do, your host computer will think the device has been unplugged. To your VM, it appears as though the physical USB device has been plugged in to one of its virtual USB ports.

The Virtues of the Virtual

A virtual machine is a fantastic way to evaluate other operating systems, as long as you understand a couple of points.

An operating system in a VM always runs slightly slower than it does on bare metal. You’ll get a good feel for its speed of performance, but it’ll not be an exact measurement. And your VM won’t be equipped with the samegraphics cardyou have in your host, so you won’t be able to test how super-duper graphics applications or high-end games will work on that operating system on a physical computer with a gaming graphics card.

But, as a way to investigate the ease of installation of a Linux distribution and to check whether a particular desktop environment or tiling window manager fits with your preferences and workflow, VMs are perfect. Run Linux but need to have access to Windows once in a while?Spin it up in a VM.

And, best of all, you may thoroughly kick the tires of a new operating system and leave your host computer untouched.