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 [OPTIONS]

PARAMETERS

--name VM_NAME
    Name of the virtual machine.

--memory MEMORY
    Memory to allocate to the VM, in MB.

--vcpus VCPUS
    Number of virtual CPUs for the VM.

--os-type OS_TYPE
    Type of operating system being installed (e.g., linux, windows).

--os-variant OS_VARIANT
    More specific operating system variant (e.g., fedora38, win10).

--disk PATH,size=SIZE
    Create a disk image at PATH with the specified SIZE (in GB).

--cdrom PATH
    Path to an ISO image to use as a CD-ROM drive.

--location URL
    URL of a network installation source (e.g., HTTP, FTP).

--network NETWORK_SOURCE
    Specify the network configuration for the VM.

--graphics TYPE
    Specify the graphics configuration (e.g., vnc, spice, none).

--noautoconsole
    Do not automatically connect to the VM's console.

--hvm
    Use full hardware virtualization.

--paravirt
    Use paravirtualization.

DESCRIPTION

virt-install is a command-line tool for creating new virtual machines using the libvirt virtualization management library. It supports various virtualization technologies like KVM, Xen, and QEMU.

The command takes parameters specifying the virtual machine's name, the installation source (ISO image, network URL, etc.), the amount of memory, number of virtual CPUs, and disk configuration. It provides a flexible way to automate virtual machine creation and configure their resources according to specific needs.

virt-install can be used to create VMs interactively or as part of scripts for automated deployment and provisioning. It uses the libvirt API to manage the VM lifecycle, including creating, starting, stopping, and deleting virtual machines. This versatility makes it a powerful tool for virtualization administrators and developers.

CAVEATS

Requires root privileges or appropriate libvirt permissions to create virtual machines. Ensure the host system has sufficient resources (CPU, memory, disk space) before creating a VM. Network configuration can be complex and requires understanding of bridging and virtual networking.

INSTALLATION SOURCES

virt-install supports several installation sources.
--location downloads the installation tree from the URL.
--cdrom use a local ISO image for installation.

NETWORKING

virt-install provides flexible networking options. You can use a bridged network (--network bridge=br0), a NAT network (--network network=default) or even configure a private network.

HISTORY

virt-install was created as part of the libvirt project to simplify the process of creating virtual machines from the command line. It evolved alongside libvirt, gaining support for new virtualization technologies and operating systems. Its early versions focused on basic VM creation, while later versions introduced more advanced features such as network configuration, storage management, and graphical console integration. It is a core part of the virtualization ecosystem and is widely used for both interactive VM creation and automated deployments.

SEE ALSO

virsh(1), qemu(1), virt-manager(1)

Copied to clipboard