virt-install

On this page 7

virt-install is a command-line tool for creating new virtual machines through the libvirt management API, most often on KVM and QEMU hosts running Linux. In virtualization, it turns a single command with options for CPU, memory, disks, network and installation media into a complete libvirt domain definition, then starts the guest and its operating system installer.

The tool belongs to the virt-manager project and is packaged on most distributions as virt-install or within virtinst. Because the whole machine is described in one command, virt-install is the standard choice for scripted, repeatable provisioning on servers that have no graphical desktop.

How virt-install creates a virtual machine

virt-install creates a virtual machine by translating command-line options into libvirt domain XML, defining that domain through the libvirt daemon and booting it with the selected installation method. It does not run the guest itself: QEMU performs the emulation, KVM provides hardware acceleration and libvirt manages the lifecycle.

A typical run follows these steps. virt-install connects to a hypervisor URI such as qemu:///system, applies operating system defaults from the libosinfo database, allocates or attaches storage, generates the XML, starts the guest and optionally opens a console. With --print-xml it only prints the definition, which is useful for review and version control.

The table below shows how responsibilities are divided among the components involved.

ComponentRoleExample
virt-installBuilds the definition and starts installationvirt-install --name web01
libvirtStores and manages the domainlibvirtd or virtqemud daemon
libosinfoSupplies recommended guest defaults--osinfo debian12
QEMUEmulates devices and runs the guestqemu-system-x86_64 process
KVMProvides hardware-assisted execution/dev/kvm kernel module
Components involved in a virt-install run

Essential virt-install options

The core options of virt-install describe the identity, resources, storage, network and installation source of the new guest. Most other settings receive sensible defaults, especially when the guest operating system is declared with --osinfo, which recent versions require or warn about when it cannot be detected.

The following table lists the options used in nearly every invocation, with realistic values.

OptionPurposeExample value
--nameUnique domain namedb01
--memoryGuest RAM in MiB4096
--vcpusNumber of virtual CPUs2 or sockets=1,cores=4
--diskStorage volume and bussize=40,bus=virtio,format=qcow2
--networkVirtual network or bridgebridge=br0,model=virtio
--osinfoGuest operating system identifierrhel9.4 or detect=on
--graphicsDisplay typespice or none
--bootFirmware and boot orderuefi
Frequently used virt-install options

Using Virtio devices for disks and network interfaces gives the best performance, because paravirtualized drivers avoid the overhead of emulating legacy hardware. The --cpu host-passthrough option exposes the full host CPU model to the guest, at the cost of making live migration harder between different processors.

Installation methods supported by virt-install

virt-install supports several installation sources, from interactive ISO installers to fully unattended cloud images. The right method depends on whether a human watches the installation and whether the guest must be built from scratch.

MethodOptionBest suited for
Local ISO image--cdrom /path/image.isoInteractive desktop or server installs
Network tree--location URLText installs with kernel arguments
Kickstart or preseed--initrd-inject with --extra-argsUnattended Fedora, RHEL or Debian installs
Existing disk image--importPrebuilt or cloned images
Cloud image--cloud-initFast provisioning with user data
Network boot--pxeData centers with PXE servers
Built-in unattended--unattendedlibosinfo-driven automatic installs
virt-install installation methods

The --location method is especially valuable on headless servers because it allows --extra-args 'console=ttyS0', which sends the installer output to a serial console reachable through virsh console. The --cdrom method cannot pass kernel arguments in this way.

virt-install is a creation tool, while its neighbors in the libvirt ecosystem focus on management, disk handling or graphical interaction. Understanding the division prevents misuse, such as expecting virt-install to start or stop existing guests.

ToolInterfaceMain task
virt-installCommand lineDefining and installing new guests
virshCommand line shellManaging existing domains and networks
virt-managerGraphical desktopCreating and operating guests visually
qemu-imgCommand lineCreating and converting disk images
GNOME BoxesGraphical desktopSimple personal virtual machines
QuickemuShell scriptsQuick desktop guests without libvirt
virt-install and neighboring tools

After creation, day-to-day operations move to virsh or virt-manager. A related utility, virt-clone, duplicates an existing guest, and virt-xml edits the definition of an existing domain with the same option syntax as virt-install.

Common mistakes when using virt-install

Most virt-install failures come from permissions, missing virtualization support or mismatched URIs rather than from the tool itself. The table below links frequent symptoms to their causes and fixes.

SymptomLikely causeFix
Guest runs very slowlyKVM unavailable, pure emulationEnable VT-x or AMD-V and load kvm modules
Guest missing in virt-managerCreated under qemu:///sessionUse --connect qemu:///system
Permission denied on ISOQEMU user cannot read the fileMove image to /var/lib/libvirt/images
No console outputInstaller uses graphical displayUse --location with serial arguments
Warning about missing OSNo --osinfo value givenSpecify the libosinfo short ID
Troubleshooting virt-install

A further risk is overcommitting host resources. virt-install does not prevent assigning more memory or vCPUs than the host can sustain, so administrators should plan capacity and consider features such as Kernel same-page merging only after measuring their effect.

In everyday language

virt-install is like an order form for a new computer that exists only in software. You write down the name, the memory and the storage it needs. You add the network and the installation disc. Then the tool builds the machine and switches it on.

The whole order fits in one line of text. You can save it and repeat it whenever you need an identical machine. Administrators who manage servers remotely like this. They prefer typing a command to clicking through windows.

Seen in the real world

A systems administrator at a regional hospital must provide twelve identical test servers for a new records application on a single KVM host with 128 GB of RAM. Clicking through a graphical wizard twelve times would be slow and error-prone.

The administrator writes one shell loop that calls virt-install with --memory 8192, --vcpus 4, a 60 GB qcow2 disk on Virtio, a bridged network interface and --location pointing to an internal RHEL mirror. A kickstart file injected with --initrd-inject answers every installer question, and --graphics none keeps all output on the serial console.

All twelve guests finish installing in about twenty-five minutes without any manual input. The same script is stored in version control, so the environment can be rebuilt exactly the same way after each test cycle.