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?
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 qemupasses) and the libvirt daemon running. - The
virt-installpackage (on many distributions it comes withvirt-manageror avirt-installpackage). - 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
--memoryis in MiB;--disk size=is in GiB. virt-install creates a new qcow2 image in the default storage location.--network network=defaultuses libvirt’s NAT network. Usebridge=br0to 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
--noautoconsoleand 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
- 0098 What Proxmox VE is: KVM virtual machines, LXC containers and a web UI Proxmox VE is an open source virtualization platform based on Debian. It runs KVM virtual machines and LXC containers and is managed… Beginner · Explains an idea · Linux Article Basics · Installation & first steps 15 Oct 2026
- 0100 Create a VM and a cloud-init template with qm Create KVM virtual machines from the command line with qm, then build a reusable cloud-init template from a cloud image and clone… Intermediate · Step by step · Linux Article Basics · VMs & containers 15 Oct 2026
- 0123 KVM vs QEMU vs libvirt: how Linux virtualization fits together KVM is the Linux kernel part that uses CPU virtualization extensions, QEMU is the program that emulates a full machine around it,… Beginner · Explains an idea · Linux Article Basics 15 Oct 2026
- 0124 virsh cheat sheet: everyday libvirt commands A quick reference for virsh: list, start, stop and inspect VMs, change CPUs and memory, manage networks, storage pools and snapshots, with… Intermediate · Cheat sheet · Linux Article Basics 15 Oct 2026
- 0126 KVM snapshots and cloning with virsh and virt-clone Take, list, revert and delete libvirt snapshots with virsh, understand internal vs external and disk-only snapshots, and clone a stopped VM with… Advanced · Step by step · Linux Article Basics 15 Oct 2026
- 0127 Fix: “Requested operation is not valid: network ‘default’ is not active” A libvirt VM will not start because the virtual network it uses, usually the NAT network 'default', is stopped. Start the network… Intermediate · Fixes an error · Linux Article Basics 15 Oct 2026
Repos in the wild
- proxmox/qemu-server: the Proxmox VE virtual machine manager proxmox/qemu-server Read-only GitHub mirror of qemu-server, the Proxmox VE package that manages QEMU/KVM virtual machines and provides the qm and qmrestore commands. GitHub
- libvirt: virtualization API and daemon (GitHub mirror) libvirt/libvirt libvirt is the toolkit that manages KVM/QEMU and other hypervisors through one API, plus the virsh client. The GitHub repository is a read-only mirror; development happens on GitLab. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +4,140 chars