The virt-install tool is supplied to allow new virtual machines to be created by providing a list of command-line options. The virt-install utility accepts a wide range of command-line arguments that are used to provide configuration information related to the virtual machine being created. Some of these command-line options are mandatory (specifically name, memory and disk storage must be provided) while others are optional.
At a minimum, a virt-install command will typically need the following arguments:
- –name – The name to be assigned to the virtual machine.
- –memory – The amount of memory to be allocated to the virtual machine.
- strong>–disk – The name and location of an image file to be used as storage for the virtual machine. This file will be created by virt-install during the virtual machine creation unless the –import option is specified to indicate an existing image file is to be used.
- –cdrom or –location – Specifies the local path or the URL of a remote ISO image containing the installation media for the guest operating system.
If you get the below error:
virt-install: Command Not Found
you may install the package as per your choice of distribution using below commands.
|Windows (WSL2)||sudo apt-get update sudo apt-get install virtinst|
|Debian||apt-get install virtinst|
|Ubuntu||apt-get install virtinst|
|Alpine||apk add virt-install|
|Arch Linux||pacman -S virt-install|
|Kali Linux||apt-get install virtinst|
|CentOS||yum install virt-install|
|Fedora||dnf install virt-install|
|Raspbian||apt-get install virtinst|
|Docker||docker run cmd.cat/virt-install virt-install|
virt-install Command Example
Before starting the operating system installation using the virt-install command, it is necessary to have a virtual disk created. To create a virtual disk, use the qemu-img command:
1. Create a virtual disk of the desired size. Here for example, we will create a 20 GB disk with the raw disk format:
# qemu-img create -f raw -o size=10G /var/lib/libvirt/qemu/win7.img
2. Then start virt-install by running the following command:
# virt-install \ --name Win7 \ --ram 1024 \ --disk path=./var/lib/libvirt/qemu/win7.img \ --vcpus 1 \ --os-type Windows \ --os-variant Windows7 \ --network bridge=virbr0 \ --graphics vnc,port=5999 \ --console pty,target_type=serial \ --cdrom ./win7.iso \
Similarly, you can use the virt-install –promot command for interactive installation. It will ask you to enter the above information sequentially and interactively.
3. Just like with the Virtual Machine Manager, after creating the virtual machine you have to take the console of the VM and proceed with actual guest installation. To take the virtual machine console, use the virt-viewer utility:
# virt-viewer [virtual machine name]
virt-install is an interactive command-line tool that can be used to set up the guest and then start the installation process. Execute the virt-install command as root to begin. There are many options available with virt-install that can be passed as arguments to configure the installation to meet your virtual machine creation requirements. virt-install is a scripting-friendly command. It can be easily embedded in scripts to automate virtual machine creation.