Virtual Machine
- In Turkish
- Sanal Makine
In short
A virtual machine is a software-based computer that runs its own operating system on shared physical hardware, isolated from other machines on the same host.
What is a virtual machine?
A virtual machine (VM) is a complete computer simulated in software. It has its own virtual CPU, memory, disk, and network card, and it runs a full operating system, called the guest, just as a physical computer would. One physical server, called the host, can run many VMs side by side, each isolated from the others.
The software that makes this possible is a hypervisor, which divides the host's real hardware between the VMs and keeps them separated. Type 1 hypervisors, such as KVM and Xen, run directly on the hardware and power most data centers and cloud platforms, while type 2 hypervisors, such as VirtualBox, run as an app on a regular desktop operating system. Modern CPUs include hardware virtualization features that let VMs run at close to native speed.
If containers are like apartments that share one building's plumbing, VMs are more like detached houses built on shared land: the land (the physical hardware) is shared, but each house has its own foundation and utilities (its own operating system and kernel). When you rent a virtual server from a cloud provider, you are almost always renting a VM running on someone else's hardware.
Virtual machines are often confused with containers. A VM includes an entire guest operating system with its own kernel, so it is larger, often measured in gigabytes, and slower to boot, but it is more strongly isolated and can run a different operating system than the host, such as Windows on a Linux server. A container shares the host's kernel and packages only the application, which makes it lighter and faster, and in the cloud, containers very often run inside VMs.
Key takeaways
- A VM is a software-emulated computer with its own operating system.
- A hypervisor shares one physical host's hardware among many isolated VMs.
- A VM can run a different operating system than its host.
- Compared with containers, VMs are heavier but more strongly isolated.
- Most cloud servers are VMs running on shared physical hardware.
Example
# Check that the CPU supports hardware virtualization (a result above 0 means yes)
grep -Ec '(vmx|svm)' /proc/cpuinfo
# Create a 20 GB virtual disk for the VM
qemu-img create -f qcow2 disk.qcow2 20G
# Boot a VM with 4 GB of RAM and 2 CPUs from an installer image
qemu-system-x86_64 -enable-kvm -m 4096 -smp 2 \
-drive file=disk.qcow2,format=qcow2 \
-cdrom installer.isoReaders ask
What is the difference between a virtual machine and a container?
A virtual machine runs a full guest operating system with its own kernel on virtualized hardware, while a container shares the host's kernel and isolates only the application. VMs offer stronger isolation and can run any operating system; containers are smaller and start much faster.
What is a hypervisor?
A hypervisor is the software that creates and runs virtual machines by sharing the host's CPU, memory, storage, and network among them. Type 1 hypervisors run directly on the hardware, while type 2 hypervisors run on top of a regular operating system.
Is a cloud server a virtual machine?
Usually, yes. Most cloud compute instances are VMs running on the provider's physical servers, although many providers also offer bare-metal servers that give you an entire physical machine.
Often compared
See also
- ContainerDevOps & Cloud, p. 12A container is a lightweight, isolated package that bundles an application with its dependencies and runs it on the host's shared operating system kernel.
- DockerDevOps & Cloud, p. 17Docker is an open-source platform for packaging an application and everything it needs into a container that runs the same way on any machine.
- LinuxDevOps & Cloud, p. 33Linux is an open-source operating system kernel that powers most servers, cloud platforms, containers, and Android phones, usually packaged as a distribution.
- Infrastructure as CodeDevOps & Cloud, p. 29Infrastructure as code is the practice of defining servers, networks, and other infrastructure in version-controlled files that tools apply automatically.
- KubernetesDevOps & Cloud, p. 32Kubernetes is an open-source system that automates deploying, scaling, and managing containerized applications across a cluster of machines.
- IaaSDevOps & Cloud, p. 27IaaS (infrastructure as a service) is a cloud model where you rent virtual machines, storage and networks on demand and manage the OS and above yourself.
- JIT CompilationProgramming Fundamentals, p. 32JIT compilation turns the busiest parts of a program into machine code while it runs, combining an interpreter's quick start with compiled speed.
- HypervisorOperating Systems, p. 15A hypervisor is software that creates and runs virtual machines, sharing one physical computer's CPU, memory, and devices among several isolated guest systems.
Spotted a mistake or something missing on this page?Suggest an edit