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

  • How To Upgrade Debian 8,9,10 to Debian 12 Bookworm
  • Linux dhcp dhclient Mint Redhat Ubuntu Debian How To Use Local Domain DNS Server Instead of ISPs
  • Docker dockerd swarm high CPU usage cause solution
  • Docker Minimum Requirements/How Efficient is Docker? How Much Memory Does Dockerd Use?
  • qemu-nbd: Failed to set NBD socket solution qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected end-of-file before all bytes were read
  • apache2 httpd apache server will not start [pid 22449:tid 139972160445760] AH00052: child pid 23248 exit signal Aborted (6) solution Mint Debian Ubuntu Redhat
  • How to use the FTDI USB serial cable to RJ45 adapter to connect to the console on Cisco/Juniper Switch Router Firewall in Linux Ubuntu Debian Redhat
  • How To Setup Python3 in Ubuntu Docker Image for AI Deep Learning
  • How to Configure NVIDIA GPUs with Docker on Ubuntu: A Comprehensive Guide for AI Deep Learning CUDA Solution
  • Linux Ubuntu Mint how to check nameservers when /etc/resolv.conf disabled solution
  • Docker cannot work on other overlayfs filesystems such as ecryptfs won't start overlayfs: filesystem on '/home/docker/overlay2/check-overlayfs-support130645871/upper' not supported as upperdir
  • Linux How To Access Original Contents of Directory Mounted Debian Mint CentOS Redhat Solution
  • ecryptfs how to manually encrypt your existing home directory or other directory
  • How to Reset CIPC Cisco IP Communicator for CME CUCM CallManager
  • Internet Explorer Cannot Download File "Your security settings do not allow for this file to be downloaded." Security Settings Solution
  • Linux How To Upgrade To The Latest Kernel Debian Mint Ubuntu
  • Firefox how to restore and backup saved passwords and history which files/location
  • Linux How To echo as root solution to use tee permission denied solution Ubuntu Debian Mint Redhat CentOS
  • Linux how to keep command line bash process running if you are disconnected or need to logout of SSH remotely
  • Linux swapping too much? How to check the swappiness and stop swapping