How to use the command virt-install (with examples)

How to use the command virt-install (with examples)

The virt-install command is a powerful tool used in conjunction with libvirt to create and manage virtual machines. It allows users to specify various parameters such as memory, storage, architecture, and installation media, enabling the creation of customized virtual machines tailored to specific needs.

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

Code:

virt-install --name vm_name --memory 1024 --disk path=path/to/image.qcow2,size=12 --cdrom path/to/debian.iso

Motivation: This use case is ideal for someone who wants to create a virtual machine running the Debian operating system. By allocating 1 GB of RAM and 12 GB of storage, the machine will have enough resources to run efficiently.

Explanation:

  • --name vm_name: Specifies the name of the virtual machine.
  • --memory 1024: Sets the amount of memory allocated to the virtual machine to 1 GB (1024 MB).
  • --disk path=path/to/image.qcow2,size=12: Specifies the path and size (in GB) of the storage disk for the virtual machine.
  • --cdrom path/to/debian.iso: Specifies the path to the installation CD/DVD image for the Debian operating system.

Example output: The virt-install command will create a virtual machine named “vm_name” with the specified parameters. It will start the Debian installation process using the provided ISO image.

Use case 2: 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

Code:

virt-install --name vm_name --arch x86_64 --virt-type kvm --machine q35 --boot uefi --memory 4096 --disk path=path/to/image.raw,size=16 --cdrom path/to/fedora.iso

Motivation: This use case is suitable for someone who wants to create a virtual machine with specific hardware configurations and install the Fedora operating system. The x86-64 architecture, KVM acceleration, UEFI booting, and the Q35 chipset ensure optimal performance and compatibility.

Explanation:

  • --arch x86_64: Specifies the architecture of the virtual machine as x86-64.
  • --virt-type kvm: Sets the virtualization type to KVM (Kernel-based Virtual Machine).
  • --machine q35: Specifies the Q35 chipset for the virtual machine.
  • --boot uefi: Enables UEFI booting for the virtual machine.
  • --memory 4096: Allocates 4 GB (4096 MB) of memory to the virtual machine.
  • --disk path=path/to/image.raw,size=16: Specifies the path and size (in GB) of the storage disk for the virtual machine using the RAW format.
  • --cdrom path/to/fedora.iso: Specifies the path to the installation CD/DVD image for the Fedora operating system.

Example output: The virt-install command will create a virtual machine named “vm_name” with the specified configurations. It will start the Fedora installation process using the provided ISO image.

Use case 3: Create a diskless live virtual machine without an emulated sound device or a USB controller, attach a cdrom (e.g., Tails live CD)

Code:

virt-install --name vm_name --memory 512 --disk none --controller type=usb,model=none --sound none --autoconsole none --install no_install=yes --cdrom path/to/tails.iso

Motivation: This use case is suitable for someone who wants to create a diskless live virtual machine without any unnecessary emulated devices, such as sound or USB controllers. The option to attach a CDROM (can be used to boot live CDs like Tails) is preserved.

Explanation:

  • --name vm_name: Specifies the name of the virtual machine.
  • --memory 512: Allocates 512 MB of memory to the virtual machine.
  • --disk none: Disables the creation of a disk for the virtual machine (diskless).
  • --controller type=usb,model=none: Configures the USB controller to be of type “usb” and model “none” (no emulation).
  • --sound none: Disables the emulated sound device.
  • --autoconsole none: Disables the automatic connection to the console.
  • --install no_install=yes: Disables the auto-installation process.
  • --cdrom path/to/tails.iso: Specifies the path to the Tails live CD ISO image.

Example output: The virt-install command will create a diskless live virtual machine named “vm_name” with the specified configurations. It will attach the Tails live CD image, allowing the user to boot the virtual machine from the CD.

Use case 4: 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

Code:

virt-install --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 --cdrom path/to/debian.iso

Motivation: This use case is suitable for someone who wants to create a powerful virtual machine with specific CPU features, memory, and storage capacity. The option to use the host’s CPU model ensures compatibility and consistent performance.

Explanation:

  • --name vm_name: Specifies the name of the virtual machine.
  • --cpu host-model,topology.sockets=1,topology.cores=4,topology.threads=2: Uses the host’s CPU model and configures the CPU topology with 1 socket, 4 cores, and 2 threads per core.
  • --memory 16384: Allocates 16 GB (16384 MB) of memory to the virtual machine.
  • --disk path=path/to/image.qcow2,size=250: Specifies the path and size (in GB) of the storage disk for the virtual machine.
  • --cdrom path/to/debian.iso: Specifies the path to the installation CD/DVD image for the Debian operating system.

Example output: The virt-install command will create a virtual machine named “vm_name” with the specified configurations. It will allocate the specified memory and storage, and configure the CPU to match the host’s CPU model.

Use case 5: Create a virtual machine and kickstart an automated deployment based on Fedora 35 using only remote resources (no ISO required)

Code:

virt-install --name vm_name --memory 2048 --disk path=path/to/image.qcow2,size=20 --location=https://download.fedoraproject.org/pub/fedora/linux/releases/35/Everything/x86_64/os/ --extra-args="inst.ks=https://path/to/valid/kickstart.org"

Motivation: This use case is suitable for someone who wants to deploy a Fedora 35-based virtual machine using a kickstart file for streamlined and automated installation. The use of remote resources eliminates the need to download and mount an ISO image.

Explanation:

  • --name vm_name: Specifies the name of the virtual machine.
  • --memory 2048: Allocates 2 GB (2048 MB) of memory to the virtual machine.
  • --disk path=path/to/image.qcow2,size=20: Specifies the path and size (in GB) of the storage disk for the virtual machine.
  • --location=https://download.fedoraproject.org/pub/fedora/linux/releases/35/Everything/x86_64/os/: Specifies the location of the Fedora 35 installation repository.
  • --extra-args="inst.ks=https://path/to/valid/kickstart.org": Provides additional arguments to the installer, in this case, specifying the kickstart file’s location.

Example output: The virt-install command will create a virtual machine named “vm_name” with the specified configurations. It will start the automated deployment based on the Fedora 35 kickstart file provided via the specified URL.

Conclusion:

The virt-install command is a versatile and powerful tool for creating and managing virtual machines with libvirt. Its flexibility allows for the creation of virtual machines with specific hardware configurations, installation media, and automated deployment options. By understanding the various parameters, users can tailor virtual machines to meet their specific needs in both simple and complex use cases.

Related Posts

How to use the command "siege" (with examples)

How to use the command "siege" (with examples)

Siege is an HTTP loadtesting and benchmarking tool that allows users to test the performance of web servers by simulating multiple concurrent connections.

Read More
aapt Examples (with examples)

aapt Examples (with examples)

Use Case 1: List files contained in an APK archive Code: aapt list path/to/app.

Read More
How to use the command 'phive' (with examples)

How to use the command 'phive' (with examples)

The command ‘phive’ is the Phar Installation and Verification Environment for secure PHP application deployment.

Read More