What is a Virtual Machine?

Often referred to as a VM, a virtual machine is a virtual computer within a computer. A virtual machine is no different than any other physical computer – it has a CPU, memory, disks to …

what is a virtual machine

Often referred to as a VM, a virtual machine is a virtual computer within a computer. A virtual machine is no different than any other physical computer – it has a CPU, memory, disks to store data and it can also connect to the internet.

While your PC is tangible and physical, as in you can touch it and actually see it (hardware), a virtual machine is often thought of as a software-defined computer that exists only as code. Therefore it’s a virtual computer.

This article is meant to introduce you to Virtual Machines, and offer basic understandings and ideas so you can start your journey in what is one of the most awesome things ever when talking about using different operating systems for various purposes.

How does a virtual machine work?

The process of virtualization consists of creating a software-based, or virtual version of a computer. This virtual computer has a dedicated amount of CPU, memory, and storage that is actually ‘borrowed’ from the host – the management of the hardware and separation of physical resources from the virtual environments is done by the hypervisor. The host can be your computer, a remote server in a data center, etc.

A virtual machine is basically a computer file, usually called an image that behaves just like a real computer. It can even function as your entire computer experience.

The whole beauty of a virtual machine and the whole virtualization process, is that the virtual machine is partitioned from the rest of the system. This means that the software inside the VM cannot interfere with the host computer’s primary operating system.

Another great thing about virtual machines is the fact that you can have any type of operating system in your virtual machine. For example, you can have a Windows VM running on Ubuntu. Or have a Windows 10 PC run a virtual machine that runs CentOS. And so on.

The difference between the host and guest operating system

I briefly mentioned the word host above. What’s the deal?

In this context, when talking about the host and guest operating system, the host operating system is the system that runs directly on the hardware, it’s actually a hypervisor. The guest operating system runs on the virtual machine.

Think of it like this: the real world PC or server is the host. And it can have several guests (virtual machines), each running different operating systems if needed.

What is a hypervisor?

I also mentioned the hypervisor. A hypervisor is the software that creates and runs the virtual machines (VMs). Sometimes called a virtual machine monitor (VMM), it isolates the main operating system and resources from the virtual machines as well as enables the creation and management of those virtual machines.

Multiple operating systems can run alongside each other and share the same virtualized hardware resources with a hypervisor. Basically, this is the benefit of virtualization. Without virtualization, you can only run 1 operating system on the hardware.

Types of hypervisors

There are two types of hypervisors: type 1 and type 2 hypervisors. I know, sounds creative right? :-))

The type 1 hypervisor is often referred to as a bare-metal hypervisor or a native hypervisor. It runs directly on the host’s hardware to manage VMs. Usually used in enterprise data centers or other server-based environments. Examples: KVM, Microsoft Hyper-V, VMware vSphere, Proxmox, XenServer, and probably others.

The type 2 hypervisor is known as a hosted hypervisor and it runs on a conventional operating system as an application. The virtual machine’s resources are scheduled against a host OS, which is then executed against the hardware. Usually better for people who want to run multiple operating systems on a personal computer. Examples: Oracle VirtualBox, VMware Workstation, and others. I like VirtualBox because it’s free and quite feature-packed for what I use VMs.

Fun fact: some people use the type 1 hypervisor in their home labs. Pretty neat!

What can you do with a virtual machine?

So what are these virtual machines used for? What can you actually do with a virtual machine that is so great? Well, quite a lot of stuff!

Below you will find just a few things you can do with a virtual machine. This is definitely not a complete list.

Trying out a new operating system

Let’s presume your running Windows 10. Have you ever wondered how Ubuntu looks and runs? Well, a Virtual Machine allows you to test Ubuntu and use it just like you would if it was installed as your primary operating system.

And the beauty of it is that you run Ubuntu just like another application through software like VirtualBox. And your Windows 10 remains unaffected regardless of what you do.

Building and then deploying an app

The flexibility of having several virtual machines allows you to be cost effective while building stuff. It’s really awesome.

Simplifying tests for developers

Developers can spin up a new environment and quickly run a test scenario.

Another thing that I love about this, is that you can mimic another system like have the exact PHP version, MariaDB version, or anything else just as another machine has. This avoids getting mixed errors and confusion when testing something on PHP 7.4 whilst the production server runs PHP 5.6 or something antique like that.

Using older software securely

If you have some specific software, older, and maybe from an untrusted source, you can just use it inside a virtual machine. If anything goes wrong your main operating system will not be affected.

Accessing virus-infected data

Just like the point above, if your VM running Windows 10, on VirtualBox that is running on your PC gets a virus, your main operating system is still safe. Just don’t share data between the host and the guest operating system.

Running software that was not intended for your host OS

That awesome little tool that runs just on Linux? But you’re running Windows? No problem. Just set up your virtual machine with anything you need and then when you need that tool/application just start your VM and you’re ready to use that application as if you were running Linux.

Consider costs

Apart from doing all of the above, virtual machines reduce costs. Imagine having to get another PC to act as a test subject when you want to try out a dual-core CPU with 2Gb of RAM server that you want to set up as a web server. It’s very inconvenient. More so if after setting everything up you plan to move everything to a hosting provider!

Apart from the physical machine costs and the electricity costs, the whole virtualization process also saves time. And time is money.

Conclusions

So that’s about it regarding virtualization and virtual machines.

The plan is to learn the basics, then in the future, we’ll go over how to create a virtual machine, what’s the deal with containers, and a lot more! I’ll link everything together once I’m done writing everything.

I often use virtual machines and have a lot of ‘templates’ and machines ready to go based on what I’m doing at the moment. A great example would be my PHP 5.6 machine that I use to test features and work for a client that runs a ‘hard to migrate to newer standards’ app. So when I need to work something, I just spin up that VM (takes maybe 1 minutes to start everything?) and I am ready to work at that project.

Do you use virtual machines? If yes, then how?

If this article was useful, share it! Thank you!