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

  1. Download an ISO or cloud image into /var/lib/libvirt/images
  2. Pick resources: --memory, --vcpus, --disk size and format
  3. Choose the network: default NAT or a bridge
  4. Choose the console: graphical VNC/SPICE or a serial text console
  5. Run virt-install and complete the guest installer
From image download to a running guest.

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

FlagExampleMeaning
--nameweb01Unique libvirt domain name
--memory4096RAM in MiB
--vcpus2Virtual CPUs (add --cpu host-passthrough for full CPU features)
--disksize=20,format=qcow2,bus=virtioCreate a new 20 GiB disk in the default pool
--location / --cdromubuntu.isoInstall source: a tree/ISO with --location, or a plain CD-ROM
--import(no value)Skip installation and boot an existing disk image
--networknetwork=default,model=virtioNIC attached to a libvirt network or bridge=br0
--graphicsnone / vnc / spiceConsole type; none means serial only
--os-variantubuntu24.04Optimise the virtual hardware for this OS

Headless install over SSH

virt-install --name web01 --memory 2048 --vcpus 2 \
--disk size=20 --os-variant ubuntu24.04 \
--location /var/lib/libvirt/images/ubuntu-24.04-live-server-amd64.iso,kernel=casper/vmlinuz,initrd=casper/initrd \
--graphics none --extra-args 'console=ttyS0,115200n8'
Starting install...
Allocating 'web01.qcow2' | 20 GB 00:00
Creating domain... | 00:00
Connected to domain 'web01'
Escape character is ^] (Ctrl + ])
A headless install: the installer appears right in your SSH session over the serial console.

The fastest path: cloud images

copyseedbootcloud imageqcow2cloud-inituser-datavirt-install--importrunning VM~20 s
Cloud images skip the installer entirely.

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 spice

Import 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 --noautoconsole

Find the IP and log in

The default network hands out DHCP leases you can query.

virsh domifaddr app01
ssh root@192.168.122.57

Common 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.

More Linux articles