Knowledge: Using virt-install for KVM Guest Installations

The most simple way to install KVM guests is to use a tool called virt-install, which wraps the installation in a single command. virt-install is being developed as a supporting tool for virt-manager. Depending on the host distribution, this program is part of a package called virt-install or virtinst, which has to be installed with the distribution’s respective packaging tools.
All examples below were tested with virt-install v1.4.3.

Installation from ISO

In our examples for regular installs, we always describe the bare minimum virtual machine configuration, i.e. consisting of a single virtual CD/DVD drive, a single virtio disk (backed by a QEMU image) and a virtio network interface attached to the libvirt default network.
Using virt-install, installation of such a KVM guest,
e.g. on Ubuntu 18.04 (aka Bionic Beaver), can be achieved in a single command as follows:
   $ virt-install --name bionic --disk size=10 --memory=2000 \
       --cdrom /var/lib/libvirt/images/bionic-server-s390x.iso
This will define and start the virtual machine, boot the ISO image (Ubuntu 18.04), and bring up the serial console with the installer up and running. Now all that is left to be done is to follow the installation instructions, let the guest reboot, and you are done!
However, note that the virtual machine is not yet configured for maximum efficiency. Fine-tuning can be done using virsh edit according to our disk performance hints & tips.

Network Installation

As seen, virt-install does not require the user to create an XML domain definition file. Besides, it can help to avoid downloading the ISO at all, at least for some distributions! This is possible due to virt-install understanding the repository structures of the most common distributions. E.g., to install an instance of Debian 9, you can use the following command:
   virt-install --name stretch --disk size=10 --memory=2000 --location \
       http://ftp.debian.org/debian/dists/stretch/main/installer-s390x/
This will fetch the necessary binaries, i.e. installer kernel and initial ramdisk, from the web server, and start the VM using these instead of an ISO image.
Another interesting feature that can be used in combination with the location-based installation is the possibility to pass additional kernel parameters to the installer system. This allows to perform an unattended installation by providing a respective configuration file:
  • kickstart file for Red Hat installs,
  • autoyast for SUSE, or
  • preseed Ubuntu, Debian, or any of its other derivatives.
It is even possible to have the configuration file inserted into the initial ramdisk on the fly:
   virt-install --name fedora --disk size=10 --memory=2000 --location \
       https://download.fedoraproject.org/pub/fedora-secondary/releases/28/Server/s390x/os/ \
       --initrd-inject=f28.ks --extra-args inst.ks=file:///f28.ks
For example, the following minimal kickstart file can be used for an unattended Fedora 28 install:
   text
   install
   ignoredisk --only-use=vda
   clearpart --all
   autopart
   bootloader --location=mbr --driveorder=vda
   rootpw super!secret:-O
   timezone Europe/Athens
   reboot
   %packages
   @Core
   %end

Distributions for IBM Z and LinuxONE

Some distributions do not offer bootable ISO images, while others do not have publicly accessible repositories. The following table contains an overview of the tested setups. Note that older Linux distribution releases may require manual tweaks to work.

Linux 
Distribution
ISO
Install
Repository Install
Alpine Linux 3.8.0 Yes -
ClefOS 7.4 or later No http://download.sinenomine.net/clefos/7.4
Debian Stretch (9.4) or later No http://ftp.debian.org/debian/dists/stretch/main/installer-s390x
Fedora 28 or later No https://download.fedoraproject.org/pub/fedora-secondary/releases/28/Server/s390x/os
openSUSE Factory Yes http://download.opensuse.org/ports/zsystems/factory/repo/oss
RHEL 7.5 Yes -
SLES 12 SP2 or later Yes -
Ubuntu
Eoan (20.04) or later
Yes http://ports.ubuntu.com/ubuntu-ports/dists/eoan/main/installer-s390x

To work around distros not offering a bootable ISO image, it is still possible to mount the image in the host and to boot the install kernel and initial ramdisk. However, it will be necessary to provide some kind of network access to the contents of the ISO or to a repository.
In case there is no publicly accessible repository for a distribution, it still may be possible to set up a local repository on-site. Check your distribution's documentation for details.
Likewise, even if a public repository exists, it may be worthwhile to set up a local mirror of that repository to speed up installations.

Summary

virt-install offers a variety of possibilities to install KVM guests easily. We have highlighted the two most common scenarios: Installing from an ISO image or a remote repository. More options exist, e.g. by directly booting install kernels, or using PXE for network installs. But they require additional setup beyond the scope of this article.

References

virt-install man page:
https://github.com/virt-manager/virt-manager/blob/master/man/virt-install.pod

virt-install examples on Ubuntu:
https://ubuntu-on-big-iron.blogspot.com/2017/11/virt-install-kvm-vm-install-options.html

2 comments:

  1. virt-install recently got mediated device support for ccw host devices. This means we can easily install directly onto a passed through dasd disk: virt-install ... --hostdev ,address.type=ccw,address.cssid=0xfe,address.ssid=0x0,address.devno=0x1111 --disk none --extra-args "rd.dasd=1111"

    https://github.com/virt-manager/virt-manager/commit/965480e8bc85caf8a4f36b4a2f07963067b63cf6

    ReplyDelete