Automating Linux installations in virtual environments saves time and ensures all your systems are built consistently. Kickstart is Red Hat’s proven technology for unattended installations. This guide shows how to use Kickstart for RHEL 9 and CentOS Stream 9 VM deployment on a KVM (Kernel-based Virtual Machine) hypervisor, using practical, hands-on steps.
1. Prerequisites
- KVM & libvirt installed on your Linux host (with
qemu-kvm
,libvirt
, andvirt-install
packages). - RHEL 9 or CentOS Stream 9 ISO available locally.
- Root or sudo privileges for virtualization commands.
- Kickstart configuration file ready for use (explained below).
- Basic networking (using libvirt’s
virbr0
NAT or a bridged setup).
2. Understanding Kickstart
Kickstart is a plain-text file containing answers for every installer prompt: language, disk layout, users, packages, network, and more. By supplying a Kickstart file, you allow RHEL or CentOS to install without any human interaction.
Kickstart is highly customizable, supporting advanced configuration and scripting, making it popular for data center automation and DevOps workflows.
3. Creating a Kickstart File
Start by creating a ks.cfg
file on your KVM host. Use your favorite text editor, e.g.:
vim ~/ks.cfg
Sections of a Kickstart file:
- Installation source & mode: Use
cdrom
andtext
for headless automation. - Localization: Set language, keyboard, timezone.
- License: For RHEL, use
eula --agreed
. - Network: Define network interface (DHCP/static), hostname.
- Disk partitioning: Use
autopart
for auto-LVM, or detailed manual partitioning. - Users: Set encrypted root password, create an admin user.
- Security: Set SELinux/firewall options.
- Packages: Specify base packages/groups.
- Optional scripts:
%pre
and%post
for customization.
Example:
text cdrom lang en_US.UTF-8 keyboard --vckeymap=us eula --agreed firstboot --disable reboot network --bootproto=dhcp --device=eth0 --ipv6=off --activate network --hostname=example-vm.local selinux --enforcing firewall --enabled --ssh bootloader --location=mbr --boot-drive=vda --append="net.ifnames=0 biosdevname=0" clearpart --all --initlabel autopart --type=lvm rootpw --iscrypted $6$YOURHASH user --name=devops --groups=wheel --password=$6$USERHASH --iscrypted --gecos="DevOps User" timezone UTC --utc %packages @^minimal-environment @core openssh-server vim bash-completion %end
Generate password hashes with: openssl passwd -6 "YourPassword"
.
4. Hosting the Kickstart File
The VM needs network access to fetch the Kickstart. The simplest way is to serve ks.cfg
via HTTP using Python:
cd ~ python3 -m http.server 8000
From your VM, the host can usually be reached as 192.168.122.1
(with libvirt default NAT).
Test access locally:
curl http://192.168.122.1:8000/ks.cfg
5. Running Automated Install with virt-install
Use the virt-install
tool to create a VM and pass the Kickstart URL as a boot argument.
Sample command:
sudo virt-install \ --name centos9-auto \ --ram 2048 \ --vcpus 2 \ --disk size=20 \ --os-variant centos-stream9 \ --network network=default \ --location /var/lib/libvirt/images/CentOS-Stream-9-latest-x86_64-dvd1.iso \ --graphics none \ --console pty,target_type=serial \ --extra-args "inst.ks=http://192.168.122.1:8000/ks.cfg console=ttyS0,115200n8" Starting install... Retrieving file vmlinuz... | 10 MB 00:00:01 Retrieving file initrd.img... | 72 MB 00:00:03 Allocating 'centos9-auto.qcow2' | 20 GB 00:00:01 Connected to domain 'centos9-auto' Escape character is ^] (Ctrl + ]) [ 0.000000] Linux version 5.14.0-366.el9.x86_64 ([email protected]) (gcc (GCC) 11.3.1 20220421 (Red Hat 11.3.1-2), GNU ld version 2.35.2-24.el9) #1 SMP Thu Aug 10 14:04:00 UTC 2023 [ 0.000000] Command line: BOOT_IMAGE=(hd0,msdos1)/images/pxeboot/vmlinuz inst.stage2=hd:LABEL=CentOS-Stream-9-x86_64-dvd inst.ks=http://192.168.122.1:8000/ks.cfg console=ttyS0,115200n8 ... [ 1.946908] dracut: dracut-057-13.git20230510.el9 [ 2.020312] systemd[1]: Detected architecture x86-64. CentOS Stream 9 installer booting Starting language support... Starting network... Starting installation process... ... [ OK ] Started Network Manager Script Dispatcher Service. [ OK ] Reached target Network. [ OK ] Started Network Manager Wait Online. ... anaconda 23.10.1-2.el9 starting ... * Setting language to en_US.UTF-8 * Setting keyboard layout to us * Setting time zone to UTC * Enabling SELinux (enforcing) * Enabling firewall and allowing SSH * Starting automated installation with Kickstart: http://192.168.122.1:8000/ks.cfg * Using CDROM as installation source * Configuring network interface eth0 (DHCP) * Setting hostname to example-vm.local * Partitioning disk /dev/vda - Removing all partitions - Creating LVM volumes - Formatting /boot and / - Setting up swap * Creating user account 'devops' * Setting root password * Installing packages: @^minimal-environment, @core, openssh-server, vim, bash-completion ... Installing : glibc-2.34-50.el9.x86_64 1/100 Installing : systemd-249-37.el9.x86_64 2/100 ... Installing : openssh-server-8.7p1-36.el9.x86_64 70/100 ... Post-installation setup tasks: * Enabling chronyd service * Writing bootloader configuration * Finalizing SELinux context labels ... Complete! * Installation complete. Rebooting system. [ OK ] Reached target Reboot. [ 240.342112] systemd-shutdown[1]: Syncing filesystems and block devices. [ 241.187761] Restarting system. Connection to domain 'centos9-auto' closed by the guest.
- Adjust
--os-variant
and ISO path as needed. --extra-args
passes the Kickstart URL and directs output to serial console.- The install will run non-interactively and reboot when done.
6. Post-Installation
- Use
virsh list --all
to see your VM. - Access the console with
virsh console <vm-name>
. - Log in with the admin user or root password you set in Kickstart.
You can now SSH into the VM, update packages, or further configure it as needed.
7. Troubleshooting
- Kickstart not found: Confirm Python HTTP server is running; verify the correct IP and port.
- Syntax errors: Validate your Kickstart with
ksvalidator
. - Network issues: Ensure
--activate
is set for the network in Kickstart and check your VM’s NIC config after install. - Installer prompts: If installation isn’t fully automated, re-check required directives (e.g., password, eula).
- Logs: Check Anaconda logs in the VM’s
/tmp
directory during install for errors.
8. Advanced Topics
- Custom partitions: Use
part
/logvol
directives. - Static IP: Change
--bootproto=static
and set IP, gateway, nameserver. - Automate at scale: Integrate with Cobbler, Foreman, or Ansible for mass deployment.
- Pre/Post scripts: Add scripts to
%pre
or%post
sections for custom automation. - Security: Store Kickstart files securely; use encrypted passwords, avoid plaintext secrets.
9. Conclusion
Kickstart allows you to deploy RHEL 9 and CentOS Stream 9 VMs on KVM rapidly and consistently. By automating the OS installation, you reduce manual work, minimize configuration drift, and prepare your infrastructure for rapid scaling and CI/CD. The process is extensible for more complex production requirements—feel free to customize the Kickstart file for your exact needs.
Leave a Comment
Your email address will not be published. Required fields are marked with *