CentOS 7 PXE boot server and automated installation with kickstart

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=p2p1 initrd=initrd.img load_ramdisk=1 network ks=

Create kickstart file for minimal CentOS 7.1 installation:

url --url
lang en_US.UTF-8
keyboard us
network --device eth0 --onboot yes --bootproto static --ip --netmask --gateway --nameserver
rootpw --iscrypted $6$TIr1aFCOTgu5AiC..a$qyU2bj.EqbZ2HppiqsgwMmWWWWWWWWWWPV2M0UPH8qcXYYYYYYYYYYYOjUlw27JJQgKU1
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=28556 --name=swap --vgname=centos
logvol /  --fstype="xfs" --size=1 --name=root --vgname=centos --grow
%packages --nobase --ignoremissing

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.

Leave a Reply

Your email address will not be published. Required fields are marked *