How to Run Virtual Machines on a Linux Server with KVM (and Manage Them from a Browser)

Docker is right for services. Sometimes you need a whole machine: a Windows VM for one stubborn program, a test copy of your server to try an upgrade on, a separate Linux box for something you don't trust. KVM is the virtualisation built into the Linux kernel — the same technology behind most cloud providers — and Cockpit gives it a web page where creating a VM is a form.
Quick reference
| Task | What | |
|---|---|---|
| Check the CPU can do it | `egrep -c '(vmx | svm)' /proc/cpuinfo` → more than 0 |
| Install | sudo apt install qemu-kvm libvirt-daemon-system virtinst cockpit cockpit-machines -y | |
| Web page | https://server-ip:9090 → Virtual machines | |
| ISO images | /var/lib/libvirt/images/ | |
| Command line | virsh list --all · virsh start name · virsh shutdown name | |
| Snapshot | virsh snapshot-create-as name before-upgrade |
1. Check the hardware
egrep -c '(vmx|svm)' /proc/cpuinfo
Anything above 0 means the CPU supports virtualisation. If it's 0 on a machine that should, enable Intel VT-x or AMD-V (SVM) in the BIOS. A VM needs its own RAM and disk, so an 8 GB server can comfortably host one 4 GB VM alongside Docker; a 16 GB one, two or three.
2. Install KVM and Cockpit
sudo apt install qemu-kvm libvirt-daemon-system virtinst bridge-utils cockpit cockpit-machines -y
sudo usermod -aG libvirt,kvm $USER
sudo systemctl enable --now cockpit.socket libvirtd
sudo ufw allow from 192.168.1.0/24 to any port 9090
Log out and in for the groups to apply. Open https://192.168.1.50:9090, accept the self-signed certificate, and log in with your normal server username and password. Virtual machines is in the left menu.
3. Get an installer ISO onto the server
cd /var/lib/libvirt/images
sudo curl -LO https://releases.ubuntu.com/24.04/ubuntu-24.04.3-live-server-amd64.iso
For Windows, download the ISO on your PC and scp it to the same folder (tutorial 18). Also grab the virtio driver ISO from the Fedora project so Windows can see the fast virtual disk and network.
4. Create the VM in Cockpit
Virtual machines → Create VM:
- Name: testbox
- Installation type: Local install media, pick the ISO
- Operating system: start typing the name
- Storage: 40 GB (it's a growable file, it only uses what the VM writes)
- Memory: 4 GB
- Tick Immediately start VM → Create and run
The VM's screen appears in the browser. Install the OS exactly as on a real machine (tutorial 1). For Windows, when it finds no disk, Load driver from the virtio ISO.
5. Give it a real network address
By default the VM is on a private NAT network — it can reach the internet, but nothing in the house can reach it. For a VM that should behave like another computer on your LAN, create a bridge:
sudo nano /etc/netplan/50-cloud-init.yaml
network:
version: 2
ethernets:
enp3s0:
dhcp4: false
bridges:
br0:
interfaces: [enp3s0]
dhcp4: true
sudo netplan try, then in Cockpit edit the VM's network interface: Interface type: Bridge to LAN, Source: br0. The VM now gets its own IP from your router like any device.
6. Snapshots
Before a risky change inside a VM:
virsh snapshot-create-as testbox before-upgrade
virsh snapshot-list testbox
virsh snapshot-revert testbox before-upgrade
Seconds to take, seconds to roll back. (Cockpit has a Snapshots tab too.)
7. Day to day
virsh list --all
virsh start testbox
virsh shutdown testbox # polite, like pressing the power button
virsh destroy testbox # pull the plug
virsh autostart testbox # start with the server
The VM's disk is one file in /var/lib/libvirt/images/; back it up when the VM is shut down, or back up what's inside it the normal way.
VM or container?
- A service (web app, database, media server) → Docker. Lighter, faster to update, this whole series.
- A different operating system, a GUI program, something that needs its own kernel or a USB device passed through, a safe copy of a whole machine → a VM.
Troubleshooting
"KVM is not available" in Cockpit. Virtualisation off in the BIOS, or you're already inside a VM without nested virtualisation.
VM is painfully slow. It's using the emulated IDE disk and NIC. Switch to virtio (default for Linux guests; needs the driver ISO for Windows).
Bridge made the server lose its network. netplan try reverts in two minutes. Check the interface name, and that only br0 has dhcp4: true.
Can't see the VM's console. Browser blocked the self-signed certificate for the console port; open https://server-ip:9090 again and accept it.
Wrapping up
Install KVM and Cockpit, drop an ISO in the images folder, click Create VM, bridge it to the LAN if it needs to be reachable, and snapshot before anything risky. The server you already have becomes as many machines as its RAM allows.
