LinuxCommandLibrary

virt-install

Create new virtual machines

TLDR

Create a virtual machine with 1 GB RAM and 12 GB storage and start a Debian installation

$ virt-install [[-n|--name]] [vm_name] --memory [1024] --disk path=[path/to/image.qcow2],size=[12] [[-c|--cdrom]] [path/to/debian.iso]
copy

Create a x86-64, KVM-accelerated, UEFI-based virtual machine with the Q35 chipset, 4 GiB RAM, 16 GiB RAW storage, and start a Fedora installation
$ virt-install [[-n|--name]] [vm_name] --arch [x86_64] --virt-type [kvm] --machine [q35] --boot [uefi] --memory [4096] --disk path=[path/to/image.raw],size=[16] [[-c|--cdrom]] [path/to/fedora.iso]
copy

Create a diskless live virtual machine without an emulated sound device or a USB controller. Don't start an installation and don't autoconnect to console but attach a cdrom to it (might be useful for when using a live CD like tails)
$ virt-install [[-n|--name]] [vm_name] --memory [512] --disk [none] --controller [type=usb,model=none] --sound [none] --autoconsole [none] --install [no_install=yes] [[-c|--cdrom]] [path/to/tails.iso]
copy

Create a virtual machine with 16 GiB RAM, 250 GiB storage, 8 cores with hyperthreading, a specific CPU topology, and a CPU model that shares most features with the host CPU
$ virt-install [[-n|--name]] [vm_name] --cpu [host-model],topology.sockets=[1],topology.cores=[4],topology.threads=[2] --memory [16384] --disk path=[path/to/image.qcow2],size=[250] [[-c|--cdrom]] [path/to/debian.iso]
copy

Create a virtual machine and kickstart an automated deployment based on Fedora 35 using only remote resources (no ISO required)
$ virt-install [[-n|--name]] [vm_name] --memory [2048] --disk path=[path/to/image.qcow2],size=[20] [[-l|--location]] [https://download.fedoraproject.org/pub/fedora/linux/releases/35/Everything/x86_64/os/] [[-x|--extra-args]] "[inst.ks=https://path/to/valid/kickstart.org]"
copy

SYNOPSIS

virt-install [OPTION]...

Common usage:
virt-install --name VM_NAME --ram RAM_MB --vcpus NUM_CPUS \
--disk path=DISK_PATH,size=DISK_GB --os-variant OS_TYPE \
--network network=default --location LOCATION_URL [ADDITIONAL_OPTIONS]

PARAMETERS

--name NAME
    Sets the name for the new virtual machine. This name must be unique on the hypervisor.

--ram MB
    Specifies the maximum memory (RAM) in MiB to allocate to the guest VM.

--vcpus NUM
    Defines the number of virtual CPUs to assign to the guest VM.

--disk [OPTIONS]
    Configures a disk device for the VM. Can specify path, size, format, bus type, etc. Example: path=/var/lib/libvirt/images/vm.qcow2,size=10

--network [OPTIONS]
    Configures a network interface for the VM. Can specify bridge, network, mac, model. Example: network=default or bridge=br0

--location URL
    Specifies the installation source, typically an HTTP/FTP/NFS URL to an installation tree or an ISO file path.

--cdrom PATH
    Uses a local CD-ROM device or ISO image as the installation source.

--pxe
    Forces the guest to boot from PXE, looking for a network boot server.

--os-variant VARIANT
    Optimizes the guest configuration for a specific operating system, like rhel8.0 or ubuntu20.04.

--graphics [OPTIONS]
    Configures the graphical console. Common types are vnc or spice. Use none for no graphical console.

--import
    Imports an existing disk image without running an installer, assuming the image is bootable.

--dry-run
    Prints the generated libvirt XML without actually creating the VM.

--connect URI
    Connects to a specific hypervisor identified by its URI, e.g., qemu:///system.

--virt-type TYPE
    Specifies the hypervisor type to use, such as kvm, qemu, or xen.

DESCRIPTION

virt-install is a command-line utility used for provisioning new virtual machines on a libvirt managed hypervisor. It simplifies the process of creating VMs by automating steps like disk image creation, network configuration, and kickstarting the installation process.

It supports various installation methods including local CD/DVD, ISO images, network locations (HTTP, FTP, NFS), and PXE boot. virt-install is a powerful tool for system administrators and developers to quickly set up virtualized environments, especially in headless servers where a graphical interface like virt-manager is not available. It can create VMs for different architectures and hypervisors, primarily KVM and Xen, and integrates seamlessly with libvirt for lifecycle management.

CAVEATS

Requires libvirt: Ensures the libvirt daemon is running and hypervisor modules (e.g., KVM) are loaded.
Resource Allocation: Verify sufficient free disk space and memory on the host system.
Disk Paths: Always use absolute paths for disk images to avoid issues.
SELinux Contexts: Critical for KVM guests; ensure correct SELinux contexts (e.g., virt_image_t) are applied to disk images.
Console Access: Initial console access may require virsh console or virt-viewer depending on graphics configuration.

LIBVIRT XML OUTPUT

virt-install internally generates a libvirt XML domain definition. This XML can be viewed with --dry-run and is the underlying configuration used by libvirt to manage the VM. Understanding this XML is key for advanced customization and troubleshooting.

POST-INSTALLATION MANAGEMENT

After a VM is successfully installed by virt-install, its lifecycle (start, stop, reboot, destroy, undefine) is managed using the virsh command-line tool. virt-manager can also be used for graphical management.

HISTORY

virt-install is an integral part of the virt-manager project, initiated by Red Hat. It was developed to provide a robust command-line interface for provisioning virtual machines utilizing the libvirt daemon. Its development has closely tracked the evolution of KVM and QEMU virtualization technologies, making it a standard and widely adopted tool in Linux virtualization environments for automated and scripting-based VM creation.

SEE ALSO

virsh(1), virt-manager(1), qemu-img(1), libvirt(7)

Copied to clipboard