Skip to content
Commitpedia
Log in Join & edit

Create a KVM virtual machine with virt-install

Use virt-install to create libvirt/KVM guests: install from an ISO, run a text-only install over the serial console, or import a cloud image with cloud-init, then manage the VM with virsh.

Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?

Edit history of Create a KVM virtual machine with virt-install: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
3 min

virt-install, part of the virt-manager project, creates a libvirt domain and starts its installation in a single command. It picks sensible device defaults, especially when it knows which OS you are installing.

Prerequisites

  • A Linux host with KVM working (virt-host-validate qemu passes) and the libvirt daemon running.
  • The virt-install package (on many distributions it comes with virt-manager or a virt-install package).
  • Permission to use qemu:///system (root, or membership in the group your distribution uses for libvirt access).

Step 1: find the OS name

--osinfo (alias --os-variant) tells virt-install which OS to optimize for, enabling devices such as virtio. Since 2022, virt-install fails by default if no OS is given and none can be detected from the media.

virt-install --osinfo list | grep -i -E 'rhel9|ubuntu24|debian12'

Step 2a: install from an ISO (graphical console)

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo virt-install \
  --connect qemu:///system \
  --name web01 \
  --memory 4096 \
  --vcpus 2 \
  --disk size=30 \
  --osinfo rhel9.4 \
  --cdrom /var/lib/libvirt/images/rhel-9.4-x86_64-dvd.iso \
  --network network=default
  • --memory is in MiB; --disk size= is in GiB. virt-install creates a new qcow2 image in the default storage location.
  • --network network=default uses libvirt’s NAT network. Use bridge=br0 to put the VM directly on your LAN through an existing host bridge.
  • By default virt-install tries to open a graphical viewer. On a remote server add --noautoconsole and connect with virt-manager or a VNC/SPICE client later.

Step 2b: text-only install over the serial console

On a headless server, use --location (which can take an install tree URL or an ISO path) so you can pass kernel arguments with --extra-args, and turn off graphics:

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo virt-install \
  --name db01 \
  --memory 8192 \
  --vcpus 4 \
  --disk size=60 \
  --osinfo rhel9.4 \
  --location /var/lib/libvirt/images/rhel-9.4-x86_64-dvd.iso \
  --graphics none \
  --extra-args 'console=ttyS0,115200n8' \
  --network network=default

The installer then appears in your terminal. Detach with Ctrl+]; reattach with virsh console db01. For unattended installs, add a kickstart or preseed file, for example --extra-args "inst.ks=https://repo.example.com/ks.cfg console=ttyS0" on Red Hat-style installers.

Step 2c: import a cloud image

Distribution cloud images are ready-made disks with locked accounts. Use --import to skip installation and --cloud-init to inject a login. Create the VM disk as a copy (or overlay) so the downloaded image stays pristine:

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo cp debian-12-genericcloud-amd64.qcow2 /var/lib/libvirt/images/app01.qcow2
sudo qemu-img resize /var/lib/libvirt/images/app01.qcow2 20G

sudo virt-install \
  --name app01 \
  --memory 2048 \
  --vcpus 2 \
  --disk /var/lib/libvirt/images/app01.qcow2 \
  --import \
  --osinfo debian12 \
  --cloud-init clouduser-ssh-key=/home/admin/.ssh/id_ed25519.pub \
  --network network=default \
  --noautoconsole

clouduser-ssh-key adds your key to the image’s default cloud user (the account name differs per distribution). Plain --cloud-init instead generates a root password and prints it once.

Step 3: check and connect

virsh list --all
virsh domifaddr app01
ssh [email protected]

On the default NAT network, guests get addresses from libvirt’s DHCP server and are reachable from the host. To reach them from other machines, use a bridged network instead.

Useful extras

  • --boot uefi: boot with UEFI firmware instead of BIOS.
  • --disk pool=default,size=30: create the disk in a named storage pool.
  • --print-xml: print the domain XML instead of creating the VM, useful for review or templates.
  • --dry-run: run through the steps without creating anything.
  • virsh autostart web01: start the VM when the host boots.

Common errors

If the VM cannot start because the default network is inactive, see the separate entry on network ‘default’ is not active. If virt-install complains it cannot detect the OS, pass --osinfo explicitly.

Official documentation

Did this work for you?

No votes yet. Be the first.

If it did not work, the report form below tells the editors what went wrong.

See also

Repos in the wild

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Dominik +4,140 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?