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 10.0.0.0 netmask 255.0.0.0 {
        authoritative;
        allow booting;
        option routers             10.0.0.1;
        option subnet-mask         255.0.0.0;
        option domain-name         "khmel.org";
        option domain-name-servers 10.0.0.1;
        option time-offset         -28800;
        option ntp-servers         10.0.0.1;
        host controller { hardware ethernet 00:19:19:55:37:df; fixed-address 10.4.4.1; next-server 10.0.0.19; filename "pxelinux.0"; }
        host compute1 { hardware ethernet 00:19:19:55:37:a5; fixed-address 10.4.4.2; next-server 10.0.0.19; filename "pxelinux.0"; }
        host block1 { hardware ethernet 00:19:19:55:33:fe; fixed-address 10.4.4.3; next-server 10.0.0.19; filename "pxelinux.0"; }
    }
}

Convert IP to HEX:

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

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=http://10.0.0.19/kickstarts/myserver.ks

Create kickstart file for minimal CentOS 7.1 installation:

/var/pxe/kickstarts/myserver.ks
text
install
url --url http://10.0.0.19/centos71/
lang en_US.UTF-8
keyboard us
network --device eth0 --onboot yes --bootproto static --ip 10.4.4.1 --netmask 255.0.0.0 --gateway 10.0.0.1 --nameserver 10.0.0.1
rootpw --iscrypted $6$TIr1aFCOTgu5AiC..a$qyU2bj.EqbZ2HppiqsgwMmWWWWWWWWWWPV2M0UPH8qcXYYYYYYYYYYYOjUlw27JJQgKU1
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Europe/Oslo
eula --agreed
reboot
ignoredisk --only-use=sda
bootloader --location=mbr
zerombr
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
@core
%end

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 127.0.0.1 10.0.0.0/8
</Directory>

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

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 *