Setup PXE Boot using Centos and dhcpd, tftp and syslinux



This is something I often setup for clients because it's very helpful for people in datacenters, this allows custom OS installs on demand, you can customize it more by using kickstart etc.. but here's a base I use before customizing more:

This little script below will install everything you need to get booting by PXE Linux.

It also assumes you set a local IP (be sure not to overwrite your existing IP) on eth0:0 (note the :0) as 192.168.1.10 and it takes a simple iptables command to NAT/Masquerade everything so the NAT clients can get to the public internet (you could also use public IPs if they are available but I prefer not to do this).



yum -y install tftp-server syslinux dhcp

#note the /tftpboot directory this will be the base directory we work from
#this will contain syslinux files and our boot images

mkdir -p /tftpboot/images
#copy syslinux to /tftpboot
cp /usr/share/syslinux/pxelinux.0 /tftpboot
cp /usr/share/syslinux/menu.c32 /tftpboot
cp /usr/share/syslinux/memdisk /tftpboot
cp /usr/share/syslinux/mboot.c32 /tftpboot
cp /usr/share/syslinux/chain.c32 /tftpboot

#create Centos 6 basedir and others like this
#copy the /pxeboot from the mirror of Centos:
mkdir -p /tftpboot/images/centos/6.3/x64
cd /tftpboot/images/centos/6.3/x64
wget http://mirror.centos.org/centos-6/6.3/os/x86_64/images/pxeboot/initrd.img
wget http://mirror.centos.org/centos-6/6.3/os/x86_64/images/pxeboot/vmlinuz

#set /etc/dhcpd.conf for booting:
cat <<'EOF' > /etc/dhcpd.conf
allow booting;
allow bootp;
option option-128 code 128 = string;
option option-129 code 129 = text;
filename "/pxelinux.0";
#to make dhcpd happy or it won't start

#next-server 192.168.1.10;
authoritative;
ddns-update-style none;

#next, my one and only subnet

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.50 192.168.1.254;
option routers 192.168.1.10;
option domain-name-servers 208.67.222.222;
}
EOF


#
mkdir -p /tftpboot/pxelinux.cfg/

cat << 'EOF' > /tftpboot/pxelinux.cfg/default
default menu.c32
prompt 5
timeout 300

MENU TITLE Menu
LABEL Centos6.3x64
MENU Label 6364
kernel ../images/centos/6.3/x64/vmlinuz
append initrd=../images/centos/6.3/x64/initrd.img
EOF

#enable tftp

#important for tftp set the server_args to /tftpboot or it will look in the wrong spot
#you'll get errors like PXE-T01: File not found
#PXE-E3B: TFTP Error - File not found
#set the following in /etc/xinet.d/tftp
server_args = -s /tftpboot


chkconfig tftp on
#restart dhcp server
service dhcpd restart
#start xinetd
service xinetd start

#set eth0:0 IP to 192.168.1.10
#set iptables masquerade
iptables -t nat -A POSTROUTING -m iprange --src-range 192.168.1.11-192.168.1.254 -j MASQUERADE


# the issue is that in Centos 6 the config is located in /etc/dhcp/dhcpd.conf and NOT /etc/dhcpd.conf (this one is ignored and useless)!
#Dec 18 00:34:38 fs12home dhcpd: Not configured to listen on any interfaces!


Tags:

pxe, centos, dhcpd, tftp, syslinux, datacenters, allows, custom, os, installs, customize, kickstart, etc, customizing, install, booting, linux, assumes, ip, overwrite, existing, eth, iptables, nat, masquerade, ips, yum, server, dhcp, tftpboot, directory, contain, images, mkdir, cp, usr, pxelinux, memdisk, mboot, basedir, pxeboot, wget, http, org, _, initrd, img, vmlinuz, conf, eof, bootp, text, filename, quot, authoritative, ddns, update, subnet, netmask, routers, domain, servers, cfg, default, prompt, timeout, label, kernel, append, enable, server_args, ll, errors, xinet, chkconfig, restart, xinetd, postrouting, iprange, src, config, located, ignored, dec, fs, configured, interfaces,

Latest Articles

  • ImageMagick Convert PDF Not Authorized
  • ImageMagick Converted PDF to JPEG some files have a black background solution
  • Linux Mint Mate Customize the Lock screen messages and hide username and real name
  • Ubuntu/Gnome/Mint/Centos How To Take a partial screenshot
  • ssh how to verify your host key / avoid MIM attacks
  • Cisco IP Phone CP-8845 8800/8900 Series How To Reset To Factory Settings Instructions
  • ls how to list ONLY directories
  • How to encrypt your SSH private key file id_rsa
  • Linux Mint 18 Disable User Name List from showing on Login Screen
  • Firefox Cannot Hit Enter Key In Address Bar and Location History Not Working
  • Cisco Unified Communications Manager / CUCM IP 8.6,10,12 Install Error Solution
  • Ubuntu Debian Mint Linux SSHD OpenSSH Server Not Starting After Reboot Solution
  • nmap how to scan for all ports and not just the 1000 most common ports
  • Windows 7,8,10 and Server 2008, 2012, 2016, 2019 Read Only Attribute Won't Go Away
  • bind / named how to make a wildcard record and retain defined A records
  • Cisco Unified Communications Manager 12 Install Errors on Proxmox/KVM
  • Local Vs Universally Administered MAC Address NIC Refuses to come up
  • Cisco Unified Communications Manager 12 CUCM 12 - How To Enable Video Calling
  • Windows 7, 8, 10, Windows Server 2008, 2012, 2016, 2019 How To AC97 Audio Drivers and Other Unsigned Drivers
  • Cisco Unified Communications Manager / CUCM IP Telephony Definitions