PXE (Preboot Exceution Environment) combined with Kickstart enables fully automated, network-based operating system deployments. This guide details how to configure a CentOS 6.5 server to provision CentOS 7.3 systems without manual interaction—using HTTP for installation media delivery, DHCP for IP assignment, TFTP for boot file distribution, and a customized Kickstart configuration.
Core Components Overview
PXE is a standardized client-server interface that allows a machine to boot over the network before a OS loads. It relies on three key services:
- DHCP: Assigns an IP address and identifies the TFTP server and boot file (
pxelinux.0) - TFTP: Serves lightweight boot components: bootloader, kernel, and initramfs
- HTTP/FTP/NFS: Hosts the full OS installation tree and Kickstart script
Kickstart eliminates interactive prompts by supplying pre-defined answers—partitioning schemes, package selections, root passwords, network settings, and more—in a declarative cofniguration file (ks.cfg). When invoked during PXE boot, the installer applies these settings automatically.
Prerequisites & Environment
- Host OS: CentOS 6.5 (minimal install)
- Hypervisor: VMware Workstation (bridge networking mode)
- Server IP:
192.168.3.12 - Firewall: Disabled (
iptablesstopped) - SELinux: Set to
disabled
HTTP Repository Setup
Mount the CentOS 7.3 ISO and expose its contents via HTTP:
yum install -y httpd
mkdir -p /mnt/centos7
mount -o loop /path/to/CentOS-7-x86_64-Minimal.iso /mnt/centos7
cp -r /mnt/centos7/* /var/www/html/centos7/
service httpd start
chkconfig httpd on
TFTP Service Configuration
Install and enable TFTP through xinetd:
yum install -y tftp-server xinetd
sed -i 's/disable[[:space:]]*=[[:space:]]*yes/disable = no/' /etc/xinetd.d/tftp
service xinetd restart
chkconfig xinetd on
Populate the TFTP root directory:
yum install -y syslinux
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /var/www/html/centos7/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/
cp /var/www/html/centos7/isolinux/vesamenu.c32 /var/lib/tftpboot/
cp /var/www/html/centos7/isolinux/*.msg /var/lib/tftpboot/
mkdir -p /var/lib/tftpboot/pxelinux.cfg
cp /var/www/html/centos7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
Edit /var/lib/tftpboot/pxelinux.cfg/default to define the auto-install menu entry:
default menu.c32
prompt 0
timeout 300
menu title Automated CentOS Installer
label ks
menu label ^Deploy CentOS 7.3 (Auto)
kernel vmlinuz
append initrd=initrd.img inst.ks=http://192.168.3.12/centos7ks.cfg inst.ks.device=eth0
DHCP Server Configuration
Configure DHCP to direct PXE clients to the TFTP server and boot file:
yum install -y dhcp
cp /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
# Edit /etc/dhcp/dhcpd.conf:
subnet 192.168.3.0 netmask 255.255.255.0 {
range 192.168.3.100 192.168.3.200;
option routers 192.168.3.1;
option subnet-mask 255.255.255.0;
filename "pxelinux.0";
next-server 192.168.3.12;
default-lease-time 21600;
max-lease-time 43200;
}
Start the service:
service dhcpd start
chkconfig dhcpd on
Kickstart File Generation
For reproducibility and accuracy, derive centos7ks.cfg from an existing installation’s /root/anaconda-ks.cfg:
cp /root/anaconda-ks.cfg /var/www/html/centos7ks.cfg
chmod 644 /var/www/html/centos7ks.cfg
A minimal but functional example:
#version=RHEL7
install
url --url="http://192.168.3.12/centos7"
text
reboot
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
firewall --disabled
selinux --disabled
timezone Asia/Shanghai --isUtc
bootloader --location=mbr --boot-drive=sda --append="crashkernel=auto"
network --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto
rootpw --iscrypted $6$...truncated...
auth --enableshadow --passalgo=sha512
clearpart --all --initlabel
part /boot --fstype=xfs --size=300
part pv.100 --size=1 --grow
volgroup vg0 --pesize=4096 pv.100
logvol / --fstype=xfs --name=lv_root --vgname=vg0 --size=10240
logvol /data --fstype=xfs --name=lv_data --vgname=vg0 --size=20480
logvol swap --fstype=swap --name=lv_swap --vgname=vg0 --size=2048
%packages
@^minimal-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
Key directives:
reboot: Ensures automatic reboot post-installationclearpart --all --initlabel: Prevents manual intervention during disk formattinginst.ksin kernel args: Points the installer to the remote Kickstart file
Validation
Create a new VM with network adapter set to bridged mode and PXE boot enabled. On power-on, it will:
- Obtain an IP via DHCP
- Fetch
pxelinux.0via TFTP - Load kernel and initramfs
- Retrieve and parse
centos7ks.cfgover HTTP - Proceed unattended through partitioning, package installation, and finalization
Upon completion, verify disk layout matches the Kickstart specification using lsblk or df -h.