> For the complete documentation index, see [llms.txt](https://kmanu225.gitbook.io/cs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kmanu225.gitbook.io/cs/software-engineering/unix-linux-on-windows-choosing-the-right-environment/virtual-machines-run-a-complete-linux-system-on-windows.md).

# Virtual Machines: Run a Complete Linux System on Windows

[Containers](/cs/software-engineering/unix-linux-on-windows-choosing-the-right-environment/docker-and-containers-reproducible-linux-environments-on-windows.md) isolate applications while sharing a kernel. A **virtual machine (VM)** goes further: it runs a complete Linux operating system with its own kernel on virtual hardware.

Conceptually:

```
Windows
    |
    +-- Hypervisor
           |
           +-- Virtual machine
                  +-- virtual CPU / memory / disk
                  +-- Linux kernel
                  +-- Linux userspace
                  +-- applications
```

From Linux's point of view, the VM behaves much like a separate computer.

## When should you use a VM?

A virtual machine is a good choice when:

> You need a complete and independent Linux system, not just a Linux development shell or an isolated application.

Typical examples include:

* testing a complete Linux distribution;
* reproducing a server installation;
* testing networking or firewall configurations;
* running system services;
* kernel or low-level development;
* testing installers, upgrades, or system configuration;
* creating environments that should be strongly separated from Windows.

For example, if you need to test how an application behaves on a fresh Ubuntu server from boot to shutdown, a VM is much closer to the real target than a container.

## A VM has its own kernel

This is the main difference from containers:

```
Container
    -> shares a Linux kernel
    -> isolates processes and userspace

Virtual machine
    -> has its own Linux kernel
    -> has its own operating system
```

A VM can therefore have its own kernel version, services, users, filesystem, network interfaces, boot process, and system configuration.

This also provides a stronger boundary between the Linux environment and the Windows host.

## The cost of that isolation

The additional independence comes with more overhead.

Each VM needs resources such as:

```
CPU
RAM
virtual disk
Linux kernel
operating system
```

A VM also needs to boot like a normal computer.

For everyday Linux command-line development, this can be unnecessary compared with WSL. For running a single application, containers are usually lighter.

VMs become attractive when the **whole operating system matters**.

## Common options on Windows

Several hypervisors can run Linux virtual machines on Windows, including:

* **Hyper-V**;
* **VMware**;
* **VirtualBox**.

Regardless of the product, the principle is similar: Windows hosts virtual hardware, and Linux runs inside it as an independent guest operating system.

VMs can also provide useful features such as snapshots, virtual networking, multiple virtual disks, and several Linux machines running side by side.

## VM or WSL?

Use **WSL** when you want Linux tightly integrated into your Windows development workflow.

Use a **VM** when you want Linux to behave like a separate machine.

For example:

```
Linux development tools
on a Windows workstation
        -> WSL

Complete Linux server
with its own system configuration
        -> VM
```

## Should you use a virtual machine?

Use a VM when your requirement is:

> **"I need a complete Linux system whose kernel, services, networking, and configuration I can control independently from Windows."**

For normal application development, WSL or containers may be simpler.

But when you need to reproduce an entire Linux machine, a VM remains one of the most flexible solutions.
