What is a Virtual Machine?
A virtual machine (VM) is a compute resource configured with virtualization software called a hypervisor. Once created, you can deploy software applications and run them as desired. VMs are based on the concept of virtualization. Virtualization means taking the resources (CPU, RAM, disk space) of a physical host and dividing them into one or more independent machines.
Although virtual machines run on top of a physical host, they’re independent of each other and from the physical host, meaning the resources allocated to a VM, like CPU, memory, storage, and network interface, don’t conflict with other VMs and Physical hosts, as these resources are allotted for the VM. Also, applications and processes running inside a VM have scope only within that VM and not on other VMs or the physical host.
For example, a host machine with 8 CPU cores, 32 GB of RAM, and 500 GB of hard disk space can be divided into multiple VMs—say, two VMs of required capacity using Hypervisor, which is specialized virtualization software. One virtual machine has four CPU cores, 8 GB RAM, and 60 GB hard disk capacity; the other has two CPU cores, 8 GB RAM, and 40 GB hard disk capacity. These virtual machines could have any OS installed. One might be Windows and the other MacOS or your favorite Linus distro.
Why Use Virtual Machines?
Virtual machines are used for multiple application areas, including on-premises and the cloud. With the advancement in cloud computing, cloud service providers now use virtualization technology to provide compute resources to various organizations for cost-efficient, scalable, and flexible resource utilization.
Here are some of the ways virtual machines are used and the benefits they offer:
- Experimenting with the beta releases of new software, like operating systems and anti-virus software.
- Launching a quick sandbox environment for development or testing.
- Launching an isolated environment to access corrupted data and conduct tests as desired.
- Launching an isolated environment to access malware or virus-infected applications for troubleshooting. As the virtual machine is isolated from the physical host, the virus-infected application can be tested or troubleshot without negative impacts on the host machine.
- Experimenting with using an application on an operating system that is not scoped for that application to run.
- Effectively utilizing the physical host’s capacity by splitting it into different virtual machines.
- In the cloud, virtual machines are used to carry out app design, development, testing, and release.
How Do Virtual Machines Work?
A virtual machine runs as a piece of virtual hardware, with its own operating system, called Guest OS, and software applications isolated from the underlying physical host and from other virtual machines (if any) running on the same physical host. It depends on the physical host’s capacity, but the compute and storage resources are virtualized and split across VMs. They can be reconfigured as required, making it possible to run multiple VMs simultaneously to accommodate changing workloads.
When you connect to a VM as an end-user, using a terminal application, for example, you won’t be able to guess whether you’re connecting to a virtual environment or a physical host machine. Compute resources such as CPUs/Cores, RAM, and storage disk space are displayed the same way as they would be on a physical device.
The physical host machine needs a hypervisor to create, configure, and manage a virtual machine. A hypervisor helps by creating a resource pool from a physical host’s CPU cores, RAM, disk storage, network, and other hardware resources. From these pooled resources, individual VMs allocate their capacity based on the configuration requirements.
Broadly, there are two different hypervisors:
- Type 1 Hypervisor or Bare metal Hypervisor: A hypervisor that sits directly on top of the physical host, the bare metal of the server, to virtualize the hardware resources for creating and managing VMs.
- Type 2 Hypervisor or Hosted Hypervisor: A hypervisor that sits on top of the host operating system to virtualize the hardware resources for creating and managing VMs.
Benefits of Virtual Machines
Virtual machines bring a lot of benefits, including those listed below.
Running multiple virtual machines on the same physical host means you can reduce the physical infrastructure footprint. You need not maintain as many physical servers, saving electricity, maintenance costs, and data center space.
Another benefit is increased productivity. Less time is spent taking snapshots or image backups. Once the virtual machine has been set up with the desired configuration and software, it’s the work of one or two clicks to take a backup using the hypervisor software. Then, once the backup is taken, restoring the virtual machine to the same or another physical host is easy.
This also highlights another benefit: the portability of virtual machines. Also, VMs utilize most of their computing power, whereas physical servers can sit idle when left unallotted.
Ease of Use
Launching a virtual machine with the desired operating system and applications is more straightforward than launching a new environment based on a physical host. With hypervisor software like Oracle Virtual Box or Microsoft’s Hyper-V, you can launch a virtual machine from an existing base image in moments.
Virtual machines offer more security, as each VM is an isolated environment and is completely separated from a physical host.
VMs Versus Containers
Rather than virtualizing the underlying hardware of the physical host by dealing with separate kernels to run multiple OS instances, containers virtualize the host’s operating system to execute various workloads on top of the single host operating system instance. There are no separate kernels with containers. Instead, there’s just one host OS kernel, and container workloads are run through interaction with the host OS kernel. In the case of VM, there’s a Host OS Kernel and Guest OS Kernel.
The container deals only with the containerized application, environment settings, and dependencies. Unlike a VM, containers don’t have a guest OS bundled with them, so containers are small, portable, and able to leverage the host operating system resources to run applications. That’s why containers are often used for running multiple applications on the same physical host. They’re also often used to design and develop cloud-native, distributed applications for deployment simplicity.
As containers take advantage of the virtualization of the host operating system, they have much lower overheads than VMs and boot more quickly. They also use fewer host resources than VMs, and their portability, with quick and easy image-based deployments, makes them a perfect fit for microservices development and deployment.
Virtual machines are suited for bundling and executing multiple software packages together. They’re also ideal for bundling and running legacy applications or monolithic applications that require isolated environments.
Although virtual machines and containers are different, you can benefit from both technologies by using them together. For example, by running containerized applications on top of virtual machines, the extra layer of security (an isolated OS environment is possible with virtual machines) can be achieved in a containerized application.
Though combining virtualized technologies adds overhead in terms of bulky image footprint (through guest OS involvement), you get the security and flexibility to run the containerized applications in VMs.
VM Use Cases
The following highlights some of the many use cases for VMs.
Developing on Other Platforms
With VMs, different developers on the same system can use different platforms. For example, one developer might be comfortable with Microsoft Windows, whereas another is comfortable with Ubuntu. As a VM can have its own guest OS, different from the physical host OS, each developer is free to choose.
Testing on Different Operating Systems
Once an application is developed, it can be tested on different operating systems to certify it against multiple operating systems. This is easily achieved by launching VMs of different operating systems of choice and then executing a test suite on the application running in each VM.
Cloning a System
Once an application is tested/certified in a VM, the entire VM can be taken as an image. With the latest hypervisor software in place, cloning tasks can be achieved at a greater speed and agility. The cloned image can then be used at a later point in time when required to launch a new VM.
Handling a Potentially Dangerous Application
A malware or virus-infected application can be launched as a separate VM instance for troubleshooting. As the virtual machine is isolated from the physical host, a potentially dangerous application can be handled more safely and securely.
Run Old or Incompatible Software
A VM can be used to host and execute old or incompatible software in an isolated environment of your choice. This is usually done with an experimentation/trial intent. Since the process inside VMs is isolated from other VMs running in the same host OS, it’s safer to experiment with old software in a separate VM.
- Virtual machines are compute resources that are configured using a hypervisor. VMs enable you to deploy software applications and run them as desired.
- A virtual machine, like any other application, runs as a process on the host OS of a physical machine or directly on a physical host using specialized software.
- Any number of virtual machines can be launched and managed on a physical host, and the limit is based on the capacity of the physical host.
- With VMs, an organization can save costs by decreasing electricity usage, reducing maintenance costs, reducing the need for real estate and data centers, and improving the agility and speed of infrastructure-related operations.