virt-install Tutorial: Create Your First KVM Virtual Machine
Use virt-install to create KVM virtual machines from an ISO, a network install tree or a cloud image. Learn the key flags, os-variant and headless console.
Published November 27, 2026
virt-install is the command-line way to create a new libvirt virtual machine. One command defines CPU, memory, disks, network and install media, writes the XML, and boots the guest. This tutorial walks through the three most useful patterns: install from an ISO, a fully headless text install, and importing a ready-made cloud image.
The concept
virt-install is a translator. It takes human-friendly flags, chooses sensible defaults for the guest operating system you name with --os-variant, and produces a libvirt domain XML document. Once the VM exists, you never run virt-install for it again; day-to-day management happens with virsh.
The --os-variant flag matters more than it looks. It tells libvirt which virtual hardware the guest supports, for example virtio disks, a q35 chipset, UEFI, or a particular clock source. Run osinfo-query os to list valid names. If your exact version is missing, pick the closest one or use --os-variant detect=on.
The workflow
- Download an ISO or cloud image into /var/lib/libvirt/images
- Pick resources: --memory, --vcpus, --disk size and format
- Choose the network: default NAT or a bridge
- Choose the console: graphical VNC/SPICE or a serial text console
- Run virt-install and complete the guest installer
Anatomy of a virt-install command
Every virt-install command answers the same questions. The table below maps each flag to the question it answers so you can build commands from memory instead of copying them.
Flags you will use every time
| Flag | Example | Meaning |
|---|---|---|
| --name | web01 | Unique libvirt domain name |
| --memory | 4096 | RAM in MiB |
| --vcpus | 2 | Virtual CPUs (add --cpu host-passthrough for full CPU features) |
| --disk | size=20,format=qcow2,bus=virtio | Create a new 20 GiB disk in the default pool |
| --location / --cdrom | ubuntu.iso | Install source: a tree/ISO with --location, or a plain CD-ROM |
| --import | (no value) | Skip installation and boot an existing disk image |
| --network | network=default,model=virtio | NIC attached to a libvirt network or bridge=br0 |
| --graphics | none / vnc / spice | Console type; none means serial only |
| --os-variant | ubuntu24.04 | Optimise the virtual hardware for this OS |
Headless install over SSH
The fastest path: cloud images
Practical examples
Install from an ISO with a graphical console
Connect afterwards with virt-viewer or virt-manager.
virt-install --name win11 --memory 8192 --vcpus 4 --cpu host-passthrough \
--disk size=64,bus=virtio --cdrom /isos/Win11.iso \
--disk /isos/virtio-win.iso,device=cdrom \
--os-variant win11 --boot uefi --tpm backend.type=emulator \
--network network=default,model=virtio --graphics spiceImport an Ubuntu cloud image with cloud-init
virt-install --cloud-init injects a user and SSH key on first boot.
cd /var/lib/libvirt/images
wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
qemu-img create -f qcow2 -F qcow2 -b noble-server-cloudimg-amd64.img app01.qcow2 20G
virt-install --name app01 --memory 2048 --vcpus 2 --import \
--disk app01.qcow2,bus=virtio --os-variant ubuntu24.04 \
--cloud-init root-ssh-key=$HOME/.ssh/id_ed25519.pub \
--network network=default,model=virtio --graphics none --noautoconsoleFind the IP and log in
The default network hands out DHCP leases you can query.
virsh domifaddr app01
ssh root@192.168.122.57Common mistakes
- Using --cdrom with --extra-args. Kernel arguments only work with --location, which lets virt-install pass a kernel and initrd.
- Forgetting --os-variant: you get slow emulated IDE disks and an e1000 NIC instead of virtio.
- Pointing --disk at an ISO in your home directory: the qemu user cannot read it, so put media under /var/lib/libvirt/images.
- Exiting the serial console with Ctrl+C. That signals the installer; use Ctrl+] to detach.
Key takeaways
- virt-install builds the domain XML once; manage the VM with virsh afterwards.
- Always set --os-variant to get virtio devices and modern defaults.
- Use --graphics none plus console=ttyS0 for fully headless installs.
- Cloud images with --import and --cloud-init give you a VM in seconds.
FAQ
How do I delete a VM created by virt-install?
Run virsh destroy name (if running) and then virsh undefine name --remove-all-storage. Add --nvram for UEFI guests.
Can virt-install create a VM without starting it?
Yes. Combine --print-xml to see the XML, or --noreboot and --noautoconsole to define it without attaching to the console.
What does --boot uefi do?
It selects OVMF firmware instead of SeaBIOS, which is required for Windows 11, Secure Boot and some modern Linux images.