PXE Server Setup

PXE (Preboot Execution Environment) has become a standard in computer world to have network connected computers to install OS images remotely by the Admins.

In this article we will see how to setup a PXE server in few simple steps

Pre-requisites 

  • CentOS (v7.1 and above. It can be in a VM)
  • Internet access to install files

Install and configure dnsmasq

yum install -y dnsmasq

Edit /etc/dnsmasq.conf with the below content

interface=eth0
domain=yourdomain.com
dhcp-range=172.26.0.0,proxy,255.255.240.0
dhcp-boot=pxelinux.0,pxeserver,172.26.0.30
dhcp-option=3,172.26.0.1
dhcp-option=6,172.26.0.1
server=172.26.0.1
dhcp-option=28,172.26.0.255
dhcp-option=42,0.0.0.0

pxe-prompt="Press F8 for menu.", 5
pxe-service=x86PC, "Install TRSV Operating Systems", pxelinux
enable-tftp
tftp-root=/var/lib/tftpboot

Information about the file

interface – Interfaces that the server should listen.
domain – Replace it with your domain name.
dhcp-range – Replace it with IP range .
dhcp-boot – Give your interface IP.
dhcp-option=3, – Give Gateway IP.
dhcp-option=6, - Give DNS IP.
server= – Put your DNS forwarders IPs Address.
dhcp-option=28, – Give broadcast address.
dhcp-option=42, - Give your network time servers.
pxe-prompt – Leave it as default 
pxe=service – Use x86PC for 32-bit/64-bit architectures and enter a menu description prompt under string quotes.
enable-tftp – Enables the build-in TFTP server.
tftp-root – Give /var/lib/tftpboot.

Start the dnsmasq and enable to start after a reboot

# systemctl start dnsmasq
# systemctl enable dnsmasq

Install syslinux boot loaders and tftp server and copy bootloaders to the tftp-server root folder

# Install syslinux bootloaders:
yum install syslinux

# Check bootloaders files
ls /usr/share/syslinux

# Copy bootloaders to tftp-server's root folder:
cp -r /usr/share/syslinux/* /var/lib/tftpboot

Setup PXE Server configuration file and add entry for PXE boot and install over NFS

mkdir /var/lib/tftpboot/pxelinux.cfg
touch /var/lib/tftpboot/pxelinux.cfg/default
# vi /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
prompt 0
timeout 30
MENU TITLE ####### TRSV Network PXE Menu #######
LABEL centos7_x64
MENU LABEL CentOS 7_X64
KERNEL /trsvCentOS/vmlinuz
APPEND initrd=/trsvCentOS/initrd.img method=http://mirror.centos.org/centos/7/os/x86_64/ devfs=nomount ip=dhcp

Add OS boot images to PXE Server

# mount -o loop /dev/cdrom  /mnt
# wget http://mirrors.xservers.ro/centos/7.0.1406/isos/x86_64/CentOS-7.0-1406-x86_64-DVD.iso
# mount -o loop /path/to/centos-dvd.iso  /mnt
# mkdir /var/lib/tftpboot/trsvCentOS
# cp /mnt/images/pxeboot/vmlinuz  /var/lib/tftpboot/trsvCentOS
# cp /mnt/images/pxeboot/initrd.img  /var/lib/tftpboot/trsvCentOS
# umount /mnt

Once done, restart PXE server and start using it

That’s it … Feel free to post your comments or queries below…

Leave a Reply

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