CentOS/8 Stream on libvirt/KVM with Kickstart and virt-install

This article describes using Kickstart to automate the CentOS installer and virt-install to automate the creation of a VM.

The following setup is assumed:

  • There is a libvirt hypervisor called virthost.
  • ssh to virthost as „root“ is possible.

1. Kickstart

Create a file centos8.ks with the following content:

1.1 I18N and L10N

  • Set US-English locale
  • German keyboard layout and
  • German timezone:
lang en_US.UTF-8 
keyboard --vckeymap=de --xlayouts='de' 
timezone Europe/Berlin --isUtc --ntpservers=pool.ntp.org 

1.2 root-Password

  • Note: You can generate a password hash with this command: openssl passwd -6
rootpw --iscrypted $6$...crypted hash generated with openssl passwd...

1.3 Mirror

Specify the mirror for retrieving the BaseOS stream during installation:

url --url="http://mirror.centos.org/centos/8/BaseOS/x86_64/os/" 

1.4 Boot and Service Settings

The installer should run in text mode, not graphical mode:


Mark the End-User License Agreement (EULA) as agreed:

eula --agreed

Automatically perform a reboot after the installation is complete:


The system should boot into text mode, not graphical mode:


The NTP-synchronization service „chronyd“ should be enabled:

services --enabled="chronyd"

Disable the user wizard shown after the first boot of a newly installed system:

firstboot --disable

1.5 Partitioning

Do not guess the installation disk, only use /dev/vda:

ignoredisk --only-use=vda

Create a new MBR partition table:

clearpart --all --initlabel 

Create a 1GB ext4 partition and mount it at /boot:

part /boot --fstype="ext4" --size=1024

Set up LVM with a logical volume using 100% of the space, containing an xfs and mount it on /:

part pv.01 --fstype="lvmpv" --grow
volgroup cl pv.01
logvol / --fstype="xfs" --name=root --vgname=cl --percent=100 --grow

1.6 Packages to Install

I specify one ore more sets of packages by choosing from a set of profiles called „environments“ and „optional groups“. Optional groups are not installed by default, in below example i install the environment „minimal-environment“ and the optional group „standard“ for standard system utilities. Which environments and groups are available is determined by the „Comps file“ which is part of the repodata of the CentOS installation source.

  • Open this directory: http://mirror.centos.org/centos/8/BaseOS/x86_64/os/repodata
  • Look for a huge XML file ...checksum...-comps-BaseOS.x86_64.xml
  • Search for <environment> tags.
    • The name of an environment is stated in its <id> sub-tag.
    • The names of optional groups are listed in the <optionlist> sub-tag.

2. virt-install

Use virt-install to perform the installation. At this point you will set some important properties of the new VM. In this example, i use the following settings:

  • The VM should be provisioned with libvirt on remote virthost.
  • It should be of type KVM.
  • It should have the hostname my-new-vm.
  • It should have 2 VCPUs; the CPU model should be copied from the host.
  • It should have 2048 MB of RAM.
  • It should have one virtual HDD with 15 GB at the standard location for qcow2 images.
  • It should have a network adapter connected to host bridge br0.

Boot parameters pass specific configuration to the CentOS/8 installer, they are specified using the --extra-args ... option:

  • The hostname should be set to my-new-vm. This is done with the ip=::::my-new-vm::dhcp: boot parameter which specifies that DHCP should be used to configure the network interface, with the hostname as an additional override.
virt-install \ 
    --connect qemu+ssh://root@virthost/system \
    --virt-type kvm \
    --os-variant rhel7 --autostart \
    --name my-new-vm \
    --memory memory=2048,currentMemory=2048 \
    --network bridge=br0 \
    --cpu host --vcpus 2 \
    --disk size=15 \
    --location http://mirror.centos.org/centos/8/BaseOS/x86_64/os/ \
    --initrd-inject vm.ks \
    --extra-args "inst.ks=file:/vm.ks ip=::::my-new-vm::dhcp:"

Additional Notes

The console output of the CentOS installer will be redirected to the current terminal.

After the first reboot, hit AltGr+] to exit the console, which will end the installation process.

After the installation is complete, you may not be sure about the IPv4 address of your new VM, but you can use the VM’s serial console to determine it:

virsh --connect qemu+ssh://root@virthost/system \
    console --domain my-new-vm

This will take you to a login prompt. You can log in as „root“ (using the password you set in the Kickstart file) and use ip addr show eth0 and other commands to find out details about the installation.