An introduction to virtual machines (VMs)—virtualized, software representations of a computer that can offer increased portability, flexibility, and security.
What is a virtual machine (VM)?
A virtual machine (VM) is a software representation of a computer. Until VMs came along, operating systems ran directly on physical computers. You could only run one OS on a computer, meaning that if you wanted more than one OS, you had to buy multiple computers.
VMs changed all that by imitating a physical computer in software. This allows you to run several VMs on one physical computer, with each VM containing its own operating system (OS).
To learn more about virtualization technology and how it related to virtual machines, see our essential guide on virtualization. You can also check out our video, "Virtualization Explained":
A VM cannot interact directly with a physical computer. Instead, it needs a lightweight software layer called a hypervisor to coordinate between it and the underlying physical hardware. The hypervisor allocates physical computing resources—such as processors, memory, and storage—to each VM. It keeps each VM separate from others so they don’t interfere with each other.
Advantages and benefits
VMs offer several benefits over traditional physical hardware:
- Lower hardware costs and improved ROI: Because multiple VMs run on a single physical computer, customers don’t have to buy a new server every time they want to run another OS, and they can get more return from each piece of hardware they already own.
- Portability: VMs can be relocated as needed among the physical computers in a network. This makes it possible to allocate workloads to servers that have spare computing power. VMs can even move between on-premises and hosted cloud environments, making them useful for hybrid cloud scenarios in which you share computing resources between your data center and a cloud service provider.
- Flexibility: Creating a VM is faster and easier than installing an OS on a physical server because you can clone a VM with the OS already installed. Developers and software testers can create new environments on demand to handle new tasks as they arise.
- Security: VMs improve security in several ways when compared to operating systems running directly on hardware. A VM is a file that can be scanned for malicious software by an external program. You can create an entire snapshot of the VM at any point in time and then restore it to that state if it becomes infected with malware, effectively taking the VM back in time. The fast, easy creation of VMs also makes it possible to completely delete a compromised VM and then recreate it quickly, hastening recovery from malware infections.
VMs aren’t just a way to save money. Cloud computing environments developed from virtualization technology, and they rely entirely on the use of virtual machines to implement cloud-based operating systems.
To use a VM, you must first install a hypervisor. There are two types of hypervisors.
Type 1 hypervisors
Type 1 hypervisors run directly on the physical hardware (usually a server), taking the place of the OS. Typically, you use a separate software product to create and manipulate VMs on the hypervisor. Some management tools, like VMware’s vSphere, let you select a guest OS to install in the VM.
You can use one VM as a template for others, duplicating it to create new ones. Depending on your needs, you might create multiple VM templates for different purposes, such as software testing, production databases, and development environments.
Type 2 hypervisors
Type 2 hypervisors run as an application within a host OS and usually target single-user desktop or notebook platforms. With a Type 2 hypervisor, you manually create a VM and then install a guest OS in it. You can use the hypervisor to allocate physical resources to your VM, manually setting the amount of processor cores and memory it can use. Depending on the hypervisor’s capabilities, you can also set options like 3D acceleration for graphics.
For a full overview of hypervisors, check out “Hypervisors: A Complete Guide.”
Types of VMs
This section goes through some of the different types of virtual machines:
- Windows virtual machines
- Android virtual machines
- Mac virtual machines
- iOS virtual machines
- Java virtual machines
- Python virtual machines
- Linux virtual machines
- VMware virtual machines
- Ubuntu virtual machines
Windows virtual machines
Most hypervisors support VMs running the Windows OS as a guest. Microsoft’s Hyper-V hypervisor comes as part of the Windows operating system. When installed, it creates a parent partition containing both itself and the primary Windows OS, each of which gets privileged access to the hardware. Other operating systems, including Windows guests, run in child partitions that communicate with the hardware via the parent partition.
Android virtual machines
Google’s open-source Android OS is common on mobile devices and connected home devices such as home entertainment devices. The Android OS runs only on the ARM processor architecture that is common to these devices, but enthusiasts, Android gamers, or software developers might want to run it on PCs.
This is problematic because PCs run on an entirely different x86 processor architecture and a hardware virtualization hypervisor only passes instructions between the VM and the CPU. It doesn’t translate them for processors with different instruction sets. There are various projects to address this problem.
Some projects, such as Shashlik or Genymotion, use an emulator that re-creates the ARM architecture in software. One alternative, the Android-x86 project, ports Android to the x86 architecture instead. To run it, you must install the Android-x86 program as a virtual machine using the VirtualBox type 2 hypervisor. Another alternative, Anbox, runs the Android operating system on the kernel of a host Linux OS.
Mac virtual machines
Apple only allows its macOS system to run on Apple hardware, prohibiting people from running it on non-Apple hardware as a VM or otherwise under its end user license agreement. You can use Type 2 hypervisors on Mac hardware to create VMs with a macOS guest.
iOS virtual machines
It is not possible to run iOS in a VM today because Apple strictly controls its iOS OS and doesn’t allow it to run on anything other than iOS devices.
The closest thing to an iOS VM is the iPhone simulator that ships with the Xcode integrated development environment, which simulates the entire iPhone system in software.
Java virtual machines
The Java platform is an execution environment for programs written in the Java software development language. Java’s promise was “write once, run anywhere” functionality. This meant that any Java program could run on any hardware running the Java platform. To achieve that, the Java platform includes a Java virtual machine (JVM).
Java programs contain bytecode, which are instructions intended for the JVM. The JVM compiles this bytecode to machine code, which is the lowest-level language used by the host computer. The JVM in one computing platform’s Java platform will create a different set of machine code instructions to the JVM in another’s, based on the machine code that the processor expects.
The JVM, therefore, doesn’t run an entire OS and doesn’t use a hypervisor as other VMs do. Instead, it translates application-level software programs to run on particular hardware.
For more information on Java, check out “Java: A Complete Guide.”
Python virtual machines
Like the JVM, the Python VM doesn’t run on a hypervisor, and it doesn’t contain a guest OS. It is a tool that enables programs written in the Python programming language to run on a variety of CPUs.
Similar to Java, Python translates its programs into an intermediate format called bytecode, storing it in a file ready for execution. When the program runs, the Python VM translates the bytecode into machine code for fast execution.
Linux virtual machines
Linux is a common guest OS used in many VMs. It is also a common host OS used to run VMs and even has its own hypervisor called the kernel-based virtual machine (KVM). The mainstream Linux kernel has included the KVM since 2007. Although it is an open source project, Red Hat now owns the original company that developed the KVM.
VMware virtual machines
VMware was an early virtualization software vendor and is now a popular provider of both Type 1 and Type 2 hypervisor and VM software to enterprise customers.
“VMware: A Complete Guide” provides a comprehensive overview of all things VMware.
Cloning a VMware virtual machine
Cloning a VMware VM makes a copy of it configured with the same virtual hardware, installed software, and other properties at the time of duplication. It is different from a VMware template, which is a master image which never runs and a state that never changes.
You can clone VMware virtual machines in several ways. You can use the vSphere Web Client, which connects to vCenter server, or you can use VMware Instant Cloning feature.
Backing up a VMware virtual machine
Backing up a VMware VM is different than making a snapshot. A snapshot only captures the changes made to the VM since the last snapshot, and you cannot restore a snapshot without having all the snapshots produced before it along with the original VM’s disk file.
VMware used to offer its own backup option called VMware vSphere Data Protection but discontinued this after vSphere 6.5. Instead, it works with its third-party solution providers, giving them access to the vSphere system via its application programming interface (API). If you want to back up your VMware VMs, you’ll need a third-party service. One option is EMC’s Avamar service that was the foundation for vSphere Data Protection.
Ubuntu virtual machines
Ubuntu is a Linux distribution produced by Canonical. It is available in desktop and server versions, either of which you can install as a VM. Ubuntu can be deployed as a guest OS on Microsoft Hyper-V. It provides an optimized version of Ubuntu Desktop that works well in Hyper-V’s Enhanced Session Mode, providing tight integration between the Windows host and Ubuntu VM. It includes support for clipboard integration, dynamic desktop resizing, shared folders, and moving the mouse between the host and guest desktops.
VMs have several uses, both for enterprise IT administrators and users. Here are a few options:
- Support DevOps: VMs are a great way to support enterprise developers, who can configure VM templates with the settings for their software development and testing processes. They can create VMs for specific tasks such as static software tests, including these steps in an automated development workflow. This all helps streamline the DevOps toolchain.
- Test a new operating system: A VM lets you test-drive a new operating system on your desktop without affecting your primary OS.
- Investigate malware: VMs are useful for malware researchers that frequently need fresh machines on which to test malicious programs.
- Run incompatible software: Some users may prefer one OS while still needing a program that is only available in another. One good example is the Dragon range of voice dictation software. Its vendor, Nuance, has discontinued the macOS version of its product. However, running a desktop-focused hypervisor—such as VMware Fusion or Parallels—enables you to run Windows in a VM, giving you access to that version of the software.
- Browse securely: Using a virtual machine for browsing enables you to visit sites without worrying about infection. You can take a snapshot of your machine and then roll back to it after each browsing session. This is something that a user could set up themselves, using a Type 2 desktop hypervisor. Alternatively, an admin could provide a temporary virtual desktop located on the server.
How to set up and use
The specific steps for installing a VM will differ depending on which hypervisor you are using.
Installation on a desktop-based Type 2 hypervisor involves creating a VM using the program’s application menu. Some systems, such as Parallels, use an installation assistant that will download an OS like Windows 10 or a range of Linux systems and set up the VM for you behind the scenes. Others—like VirtualBox—immediately expose you to settings like choosing or creating a virtual hard disk and then setting options such as memory and CPU allocation and hard disk sizes.
Server-based hypervisors usually feature a management console that helps you create a VM. For example, VMware vSphere includes a “Create New Virtual Machine” wizard that lets you select which host or cluster to install the VM on and set configuration options such as the guest OS, the number of CPUs, and the memory size.
Use and host in the cloud
VMs support cloud operation—their portability enables you to run them on a variety of hosted cloud services just as easily as on your on-premises systems.
You can set up VMs easily using an individual account with a cloud provider. Alternatively, you can use a cloud enterprise management system like vSphere Cloud Foundation, which is an integrated software suite enabling you to use the company’s vSphere management tools in a cloud environment.
Virtual machines as a server
When using a full-featured enterprise VM management system, you can move VM servers between different physical hosts to help balance physical resources with computing demand. It is even possible to move VMs between on-premises physical servers and cloud-based servers to take advantage of the extra computing and storage resources in the cloud when necessary.
Because VMs can run a variety of guest operating systems, they are the perfect venue for open source software. An open-source OS like Linux or FreeBSD will be at home in a VM, even if it runs on a proprietary hypervisor like Hyper-V.
One use for a VM is to run a LAMP (Linux, Apache, MySQL, and PHP) stack of open-source products. You can also install more modern open-source technology stacks such as MEAN (MongoDB, Express.js, AngularJS, and Node.js) by installing these products in their own VMs and running multiple stacks alongside each other.
For more information on LAMP stacks, check out “LAMP Stack: A Complete Guide.”
For a deep dive in MEAN stacks, see “MEAN Stack: A Complete Guide.”
VMs vs. ...
VMs vs. containers
VMs became commercially popular in the early 2000s as cloud computing gained traction. Since then, containers have appeared. Like VMs, containers enable you to run many applications on a single physical server. The difference is that they don’t virtualize an entire computer, and they don’t contain an entire guest OS. Neither do they use a hypervisor, as VMs do.
Containers are an evolution of virtual machines. While the two technologies are different, they can coexist, offering complementary properties. For example, you can create a virtual machine and run containers on top of it. Or you can deploy certain apps on containers (such as those that benefit from bare-metal access without the use of a hypervisor) and others on VMs.
All containers share the core services of a single underlying OS. They contain only the application they need to run, along with its specific software dependencies, such as software libraries and environment variables. This makes them lightweight, requiring less storage than a VM.
Containers have a downside, though. Sharing a single underlying OS makes them less secure than VMs because a compromise or failure in one container could affect the OS and other containers that rely on it. Running containers on VMs can mitigate this danger by limiting the risk to a single VM.
In the following video, Sai Vennam breaks down the basics of containerization and how it compares to using VMs:
VMs vs. Docker
Docker is a Linux-based product framework for creating and running containers. First released in 2013 as an open source project, it originally used Linux containers (LXC)—a container execution program within the Linux kernel. It later dropped LXC in favor of its own library. Docker’s developers have since ported it to run on Windows.
Docker Engine, the program that creates and runs Docker containers, can also run on VMs running on local Windows or macOS computers or on remote VMs in the cloud.
You can use the Docker Machine tool to install and coordinate Docker Engine on VMs. Docker Machine uses its own custom lightweight Linux distribution called boot2docker when creating Docker-capable VMs on VirtualBox, which is a desktop-based hypervisor for running VMs. When creating Docker-based VMs hosted by cloud providers, Docker Machine uses Ubuntu as the guest OS.
VMs vs. Kubernetes
The most popular open source project for managing containers is Kubernetes. This toolset, initially developed by Google but now managed by the Cloud Native Computing Foundation (CNCF) open source community, offers administrators a way to define, deploy, and maintain containers in large enterprise environments.
Admins can use Kubernetes to create pods. These are groups of containers that logically go together, such as containers owned by the same department or company or containers that serve a single business application. It can decide which node (a physical or virtual server) on which to locate a pod on based on the available computing power, and it can ensure that there are enough identical containers running in a pod to take over from each other if some of them fail.
Kubernetes was designed for containers, not for virtual machines. One big use case for Kubernetes is multi-tenant environments, in which different departments or companies run their software on the same underlying hardware. Because containers share the same underlying operating system, this makes them less safe for multi-tenant systems—if an attacker compromises a container, it could affect all other containers on that physical hardware, including those used by other tenants.
One way to improve the security of a Kubernetes installation is to use containers developed from the ground up to offer the isolation of VMs while maintaining the small footprint and agile deployment of containers. Two projects—Kata and gVisor—offer this capability, setting them aside from Docker containers. They are both compatible with Kubernetes.
Many video gamers like to play games that run on operating systems other than their primary OS. One option is to run a guest OS on a VM in a Type 2 hypervisor that itself runs as an application within the host OS.
The challenge for VM-based gaming in this scenario is performance. Modern 3D video games are intense users of computing resources, making any performance lag obvious. Type 2 hypervisors usually carry some performance overhead because the guest OS cannot deal directly with the physical host.
One solution to this performance issue is graphical processing unit (GPU) pass-through. This uses dedicated Linux scripts to make the GPU available to the guest OS, but it often involves extensive configuration.
A more promising development is cloud-based gaming, which uses a specially configured virtual desktop OS in the cloud to run desktop video games. The user accesses them on any device over a high-bandwidth internet connection.
VMs’ isolation from physical hardware allows for more secure workload isolation. If a VM suffers a malware infection, this isolation prevents it from infecting the host OS. Administrators can delete the VM and use a backup or create a new one which is far faster than installing a new OS directly onto a physical host.
However, this doesn’t eliminate all risks. Researchers have discovered vulnerabilities in hypervisors that allow malicious code in the VM to affect the host. Worm malware also spreads by identifying other machines on a network, making it theoretically possible to spread between VMs if they can address each other on the network.
Administrators can improve VM security by using security tools from the hypervisor vendor or a third party. For example, VMware offers vShield, which is a suite of tools that work with its vCenter Server hypervisor management environment. Its tools can scan multiple VMs for malware from the hypervisor and can set up firewall protections between different VMs to avoid malicious traffic getting through.
The licensing strategy for VMs depends on the type and location of the hypervisor in use.
Pricing arrangements vary for enterprise VMs running on Type 1 hypervisors. For example, Microsoft provides the Hyper-V hypervisor as part of Windows Server. However, only the higher-priced Datacenter edition allows you to run the Windows operating system in an unlimited number of VMs, while the Standard edition comes with licenses for two VM-based copies of Windows.
VMware used to offer VMs on a per-processor model but has since switched to a per-VM model, using a rolling average of the highest number of VMs used over the last 12 months.
A Type 2 hypervisor like VMware Workstation or Parallels requires no per-VM license (although some proprietary operating systems like Windows might require a license). Instead, the user pays either a one-off fee to purchase the hypervisor, or a monthly license.
Virtual machines and IBM Cloud
IBM Cloud offers the opportunity to configure and run your own VMs based on different technical and pricing options. You can select technical profiles for VMs based on the required computing power, memory, local storage, and GPU capabilities, tailoring the system for your specific workload. You can also manage VMware VMs using IBM Cloud for VMware Solutions.
You can choose from public or private nodes to suit your security and compliance requirements. A private, single-tenant service can reside on a dedicated host of your choosing from over 60 IBM data centers in 19 countries around the world.
Choose from a panoply of deployment options to match your pricing needs. A public VM instance that you reserve for a set time in advance is less expensive than a non-reserved system. Alternatively, you can choose a VM based on spot market pricing to handle temporary workloads.
IBM Cloud also enables you to mix and match virtual server and bare-metal resources to suit your workload requirements.
To find out more, visit the IBM Cloud page and sign up for an IBM ID.