Automate RHEL and CentOS Installation on KVM with Kickstart

Cpanel/Whm License $3/mo Plesk License $10/mo Cloudlinux License $5/mo

(: April 19, 2019)

Hello all. This is my first tutorial on KVM Virtualization prepared as a reference and to help you automate boring GUI-based installation questions. We’re using Kickstart on KVM to deploy VMs. If you have a good hands-on knowledge of Linux and Virtualization, my bet is you have already worked with KVM and Kickstart.

In case this is the first time you are giving KVM a shot, worry less since you don’t need a deep understanding of KVM virtualization internals to use this guide. Just know that Virtualization enables rapid deployment by isolating the application in a known controlled environment and adds a layer of abstraction between the virtual machine and underlying physical hardware. The easiest way to get many VMs running on KVM is by using templates and Kickstart on KVM deployment model.

Major Advantages of Virtualization

  • Service Isolation : Application isolation and elimination of compatibility issues
  • Improved system security and reliability : Abstraction between the virtual machine and the underlying physical hardware
  • Faster server provisioning : Use of snapshots and templates.
  • Quicker disaster recovery : Keeping up-to-date snapshots of virtual machines – easy to redeploy
  • Dynamic load balancing : Live migration of overload to underutilized servers

What is Kickstart?

A tool created by Red Hat for system administrators to help them automate installation of Red Hat Linux family of Distributions. A single file containing the answers to all the questions that would normally be asked during a typical installation has to be created. Kickstart files can be kept on a single server system and read by individual computers during the installation, ready for Kickstart on KVM.

.td_uid_2_5d908971e11dd_rand.td-a-rec-img{text-align:left}.td_uid_2_5d908971e11dd_rand.td-a-rec-img img{margin:0 auto 0 0}

How to Perform Kickstart on KVM Installation?

Kickstart installations can be performed using a local CD-ROM, a local hard drive, or via NFS, FTP, or HTTP.

To use kickstart, you must:

  • Create a kickstart file.
  • Create a boot media with the kickstart file or make the kickstart file available on the network.
  • Make the installation tree available.
  • Start the kickstart installation.

In this post, I’ll provide you with basic kickstart file for quickstart; you can modify and advance it to suite your use case and environment setup. Used virt-install commands are provided as well. To save you quite some time, i wrote a simple bash script that makes the process of spinning new virtual machine easy and less tiresome.

kickstart file

This is a kickstart file to help you get started. With penchant goal, edit and save it as ks.cfg under your web server root directory.

###############################################################
#
# Environment setup
#
###############################################################

# url --url="http://192.168.122.1:8090/cent7"
text
cdrom
auth --enableshadow --passalgo=sha512
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
eula --agreed
reboot

###############################################################
#
# network configuration
#
###############################################################

network --bootproto=static --ip=192.168.122.100 --gateway=192.168.122.1  --netmask=255.255.255.0  --noipv6 --device=eth0 --nameserver=192.168.122.1,8.8.8.8 --activate
#network  --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network  --hostname=server1.example.com
timezone Africa/Nairobi --isUtc




###############################################################
#
# partitioning
#
###############################################################

ignoredisk --only-use=vda
bootloader --location=mbr --boot-drive=vda
zerombr
clearpart --none --initlabel
autopart --type=lvm

# part swap --asprimary --fstype="swap" --size=1024
# part /boot --fstype xfs --size=200
# part pv.01 --size=1 --grow
# volgroup rootvg01 pv.01
# logvol / --fstype xfs --name=lv01 --vgname=rootvg01 --size=1 --grow


###########################################################################################
# 
# User Accounts
# Generate encrypted password: python -c 'import crypt; print(crypt.crypt("My Password"))'
# Or  openssl passwd -1 password
#
###########################################################################################

rootpw password 
# user --groups=wheel --name=josepy --password=password --gecos="Mutai Josphat"

###############################################################
#
# SELinux and Firewalld
#
###############################################################

 selinux --enforcing
 #selinux --permissive
 #selinux --disabled
 
# firewall --enabled --http --ssh --ftp --port=https:tcp --port=ipp:tcp
# firewall --disabled

 
###############################################################
#
# Software Packages
#
###############################################################

%packages --nobase --ignoremissing
@core
@base
vim 
bash-completion

%end

Few parameters are to be changed, maybe the IP address and hostname. Below bash script is used to install a new vm – will ask you few questions

#!/usr/bin/env bash

# Update kickstart file
echo -en "Enter Hostname: "
read HOST_NAME
echo -en "Enter IP Address: "
read IP_ADDRESS
sudo sed -i 's/server1/'$HOST_NAME'/g' /srv/http/ks.cfg
sudo sed -i 's/192.168.122.100/'$IP_ADDRESS'/g' /srv/http/ks.cfg
 
## Pre-defined variables
echo ""
MEM_SIZE=1024
VCPUS=1
OS_VARIANT="rhel7"
ISO_FILE="$HOME/iso/CentOS-7-x86_64-Everything-1611.iso"

echo -en "Enter vm name: "
read VM_NAME
OS_TYPE="linux"
echo -en "Enter virtual disk size : "
read DISK_SIZE
 
sudo virt-install 
     --name ${VM_NAME} 
     --memory=${MEM_SIZE} 
     --vcpus=${VCPUS} 
     --os-type ${OS_TYPE} 
     --location ${ISO_FILE} 
     --disk size=${DISK_SIZE}  
     --network bridge=virbr0 --network bridge=docker0 
     --graphics=none 
     --os-variant=${OS_VARIANT} 
     --console pty,target_type=serial 
     -x 'console=ttyS0,115200n8 serial' 
     -x "ks=http://192.168.122.1:8090/ks.cfg" 

Replace $HOME/iso/CentOS-7-x86_64-Everything-1611.iso with the path to your ISO file, 192.168.122.1:8090 with your web server ip address hosting ks.cfg file.

You can modify other parameters like VCPU,RAM and Bridge to fit your use.

For virtual disk size, just enter number, e.g 10 for 10 GB

Save the script to a file called create_vm.sh. Make it executable and run it

$ chmod +x create_vm.sh
$ ./create_vm.sh

Also check:

How to Provision VMs on KVM with Terraform

Configure virt-manager as a non-root user on Linux

Further reading:

Mastering KVM Virtualization

Virtualization Essentials, 2nd Edition

.td_uid_4_5d908971e13ef_rand.td-a-rec-img{text-align:left}.td_uid_4_5d908971e13ef_rand.td-a-rec-img img{margin:0 auto 0 0}

Related posts

How to enable KVM virsh console access for Ubuntu Linux VM

SXI ADMIN

Denial, Outrage and Acceptance: Reactions to Satoshi Nakamoto’s ‘Unmasking’

SXI ADMIN

Atomic Capital Makes Crypto’s Most Aggressive Lending Offer Yet

SXI ADMIN

US Judge Denies SEC Push for Injunction Against Crypto Startup

SXI ADMIN

Linux delete user command

SXI ADMIN

$7.5K Ahead? Bitcoin Price Charts Hint at Bull Move

SXI ADMIN

Mizuho to Conduct Blockchain Payments Trial With Ripple

SXI ADMIN

Bitcoin’s Price is Inching Back Up Toward its 2016 High

SXI ADMIN

3 Common Mistakes New Crypto Traders Make

SXI ADMIN

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More