Floating Octothorpe

Kickstarting a CentOS VM

Automating Fedora based distributions is pretty straightforward. This post is quickly going to go through using a kickstart file to build a CentOS virtual machine.

Although it doesn't take too long to run through Anaconda's installation screens, it's nice to be able to automate installations for a few reasons:


The steps below use the following software:

Note: the sha256 checksum of the CentOS iso should be:


The kickstart file

A kickstart file is a single text file with all the information Anaconda needs to carry out an installation. The example below is fairly simple, however the Red Hat documentation has more detail on additional commands and options:

# System authorization information and root password hash
auth --enableshadow --passalgo=sha512
rootpw --iscrypted $6$g418WpDO$MK2rgLiYkx4BwtX/ssid4HKGMEG05wqO52b.mYIvjrSHXC/HauCgh4FLO2zg3poar/4tNBsieO8tdwPunI6jE.

# Use CDROM installation media and perform a text install

# Use GB for keyboard layout and system language
keyboard --vckeymap=gb --xlayouts='gb'
lang en_GB.UTF-8

# Set timezone
timezone Europe/London --isUtc

# Network information
network  --bootproto=dhcp --device=enp0s3 --onboot=on --ipv6=auto
network  --hostname=localhost.localdomain

# Clear any existing partitions and use autopart on the first disk
clearpart --all --initlabel
autopart --type=lvm
bootloader --location=mbr --boot-drive=sda

# Reboot after installation completes
reboot --eject

# Install the core package group and vim, but exclude wifi firmware packages

# Disable kdump
%addon com_redhat_kdump --disable --reserve-mb='auto'

# Copy the kernel parameters using during installation for future reference
cp /proc/cmdline /root/ks_cmdline

Note: the root password being set above is "example". If you use this kickstart file, make sure you change the password hash.

Installation steps

Create a virtual machine

In Virtual Box create a new virtual machine. For this example I gave the virtual machine the following specs:

Start a web server

During the build process the virtual machine will need to download the kickstart file. Switch to the directory containing the kickstart file and run python -m http.server:

$ python -m http.server
Serving HTTP on port 8000 ...

Note: if you are using python 2.x run python -m SimpleHTTPServer instead.

Starting the installation

Boot the virtual machine from the CentOS iso (CentOS-7-x86_64-Everything-1511.iso). After a few seconds you should see a grub menu similar to the following:

A CentOS virtual machine showing the grub boot menu during

Select the Install CentOS 7 option and press tab. Add inst.ks=<kickstart url> to the end of the kernel parameters. The full line should look something like this:

vmlinuz initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet inst.ks=

The exact URL you use for the kickstart file will depend on your VirtualBox network config. If you're unsure check the URL in a web browser.

Finally hit enter and wait for the system to build. If everything goes well you should have a new CentOS VM after five minutes or so.