CentOS 7 PXE boot server and automated installation with kickstart

Posted on Wed 17 February 2016 by Pavlo Khmel

Install packages:

yum -y install httpd xinetd syslinux tftp-server dhcp

Copy files from iso image:

mount -o loop CentOS-7-x86_64-Minimal-1503-01.iso /mnt/
cp -r /mnt /data/centos-7.1-64x-pxe
umount /mnt

Copy files for tftp:

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /data/centos-7.1-64x-pxe/images/pxeboot/vmlinuz /var/lib/tftpboot/
cp /data/centos-7.1-64x-pxe/images/pxeboot/initrd.img /var/lib/tftpboot/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
cp /usr/share/syslinux/chain.c32 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
mkdir /data/kickstarts/

DHCPD configuration:

# vi /etc/dhcp/dhcpd.conf 
shared-network MY-NET {
    subnet netmask {
        allow booting;
        option routers   ;
        option subnet-mask;
        option domain-name         "khmel.org";
        option domain-name-servers;
        option time-offset         -28800;
        option ntp-servers;
        host controller { hardware ethernet 00:19:19:55:37:df; fixed-address; next-server; filename "pxelinux.0"; }
        host compute1 { hardware ethernet 00:19:19:55:37:a5; fixed-address; next-server; filename "pxelinux.0"; }
        host block1 { hardware ethernet 00:19:19:55:33:fe; fixed-address; next-server; filename "pxelinux.0"; }

Convert IP to HEX:

# Example:
printf '%02X' 10 4 4 1 ; echo

Create boot configuration for special server.

# vi /var/lib/tftpboot/pxelinux.cfg/0A040401
default menu.c32
prompt 0
timeout 300

menu title PXE Boot Menu
label 1
   menu label ^1) Boot from local drive
   COM32 chain.c32
   APPEND hd0 0

label 2
   menu label ^2) Install CentOS 7.1 x64 minimal
   kernel vmlinuz
   append ksdevice=bootif initrd=initrd.img load_ramdisk=1 network ks= nameserver= ip=

Create kickstart file for minimal CentOS 7.1 installation:

url --url
lang en_US.UTF-8
keyboard us
rootpw --iscrypted $6$0obla.....................PFGxpgX/
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Europe/Oslo
eula --agreed
ignoredisk --only-use=sda
bootloader --location=mbr
clearpart --all --initlabel
part /boot --fstype="xfs" --ondisk=sda --size=500
part pv.01 --fstype="lvmpv" --ondisk=sda --size=1 --grow
volgroup centos pv.01
logvol swap  --fstype="swap" --size=1024 --name=swap --vgname=centos
logvol /  --fstype="xfs" --size=1 --name=root --vgname=centos --grow
%packages --nobase --ignoremissing
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EA............++MwrB root@my-host" >> /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
restorecon -R /root/.ssh/

HTTPD configuration file:

# vi /etc/httpd/conf.d/pxeboot.conf

Alias /centos71 /data/centos-7.1-64x-pxe
<Directory /data/centos-7.1-64x-pxe>
    Options Indexes FollowSymLinks
    # IP address you allow to access
    Require ip

Alias /kickstarts /data/kickstarts
<Directory /data/kickstarts>
    Options Indexes FollowSymLinks
    # IP address you allow to access
    Require ip

Enable and start services:

sed -i 's/disable\t\t\t= yes/disable = no/' /etc/xinetd.d/tftp
systemctl enable xinetd
systemctl enable httpd
systemctl enable dhcpd
systemctl restart xinetd
systemctl restart httpd
systemctl restart dhcpd

Power on server with MAC: 00:19:19:55:37:df. You'll see PXE menu on PXE boot.