How Ubuntu virtualizes: KVM, namespaces and cgroups

Published on 2026-09-12 by frfrand

The three pieces of the Linux kernel that support virtualization in Ubuntu (KVM, namespaces and cgroups): what each one does and what commands show them.

How Ubuntu virtualizes: KVM, namespaces and cgroups

Short answer: Ubuntu does not virtualize with a separate application: it uses three pieces of the Linux kernel. KVM turns the kernel into a hypervisor for virtual machines with their own kernel; namespaces limit what a process sees (processes, network, mounts, users); and cgroups limit how much it consumes. Docker and LXC use namespaces and cgroups; KVM is the basis of virtual machines.

When someone says "Ubuntu can virtualize," it sounds like it comes with an application for that. It does not: the capabilities are in the Linux kernel, and they are three distinct pieces that solve different problems.

Understanding them explains how Docker, LXC, Kubernetes, and practically all modern hosting work, because they all rely on the same three.

KVM: the kernel as hypervisor

KVM (Kernel-based Virtual Machine) has been in the Linux kernel since 2007. It turns Linux itself into a type 1 hypervisor.

The idea is elegant: instead of writing a hypervisor from scratch, it takes advantage of the fact that the kernel already knows how to schedule processes, manage memory, and talk to devices. A virtual machine becomes, for Linux, just another process to which resources are assigned.

The virtual machine code runs directly on the real processor, using hardware virtualization extensions. KVM only intervenes in privileged operations.

Check if your machine can:

grep -c -E "vmx|svm" /proc/cpuinfo

If it returns a number greater than zero, the processor has the extensions. vmx is Intel, svm is AMD.

KVM usually comes accompanied by QEMU, which emulates the devices (disks, network, video), and by libvirt, which is the management layer used by higher-level tools.

Namespaces: what a process can see

A namespace limits the view that a process has of the system. There are several types, each for one aspect:

  • PID: which processes it sees. Inside its namespace, the first one is PID 1 and it sees nothing from outside.
  • NET: its own network interfaces, its routing table, its firewall rules.
  • MNT: its own mounted directory tree.
  • UTS: its own hostname.
  • USER: identifier mappings, so that root inside is not root outside.

When you are inside a container and run "ps aux" and only see two processes, that is a PID namespace in action. The other thousand processes on the host still exist: they are simply not visible.

You can see the namespaces of a process:

ls -l /proc/self/ns/

cgroups: how much it can consume

Namespaces isolate what is seen; cgroups limit what is used.

With cgroups you define how much CPU, how much memory, how much disk bandwidth a group of processes can consume. It is what prevents a container from taking over the entire machine.

And it is also what systemd does under the hood: each system service runs in its own cgroup, and that is why memory limits can be set per service.

systemctl set-property miapp.service MemoryMax=512M

Version 2 of cgroups, which is what modern distributions use, unified the hierarchy and makes this control much more coherent.

How they combine

Docker and LXC use namespaces and cgroups: they isolate and limit, but share the host kernel.

KVM is something else: it creates a machine with its own kernel.

A cloud provider usually combines both: KVM to separate customers, and inside each machine, containers to separate applications.

The interesting thing is that none of this requires additional software. It is in the kernel you already have installed. Docker, LXC and Kubernetes are convenient interfaces over functions that Linux comes with out of the box.

And that is why a command as simple as this:

systemd-detect-virt

tells you what type of environment you are running in: kvm, lxc, docker, or none if it is real hardware.

How to check application isolation

A full virtual machine and a container do not offer exactly the same level of isolation: containers share the host kernel, while hardware virtualization provides an independent kernel environment per VM. In both cases, security depends on configurations, updates, privileges, and resource limits.

At ArduMaker each VPS is an unprivileged LXD container: it uses namespaces and cgroups and shares the host kernel (systemd-detect-virt returns lxc). You can run applications with Docker, because the VPS comes with the nesting it needs, but you cannot load kernel modules. Before installing a component that requires elevated privileges or specific kernel modules, check those limits. If something works on a local VM but not in a container, check namespaces, devices, and capabilities before attributing it to an Ubuntu error.

Frequently asked questions

What is KVM? The Linux kernel module, present since 2007, that turns Linux into a hypervisor. It is usually used together with QEMU, which emulates devices, and libvirt, which manages them.

What is the difference between namespaces and cgroups? Namespaces limit what a process sees; cgroups, what it can consume.

How do I know if my processor supports virtualization? With grep -c -E "vmx|svm" /proc/cpuinfo: a number greater than zero indicates that it has the extensions (vmx on Intel, svm on AMD).

Does Docker use KVM? No on Linux: it uses namespaces and cgroups and shares the host kernel.

Related: LXC, Docker and VM · Docker in production.

  • Ubuntu
  • KVM
  • namespaces
  • cgroups
  • virtualización

Keep reading

All articles · VPS plans