Site icon CentLinux

How to Setup a Linux PXE Server

Share on Social Media

Learn how to set up a Linux PXE server with this step-by-step guide. Follow clear instructions to configure your server for network booting, making deployment and management of Linux systems easier than ever. #centlinux #linux #pxe

What is PXE Server?

PXE (pronounced as pixie) is the abbreviation of Preboot eXecution Environment. It is a standardized specification of a client-server environment, where PXE-enabled clients can boot their machines by using PXE boot images retrieved from a preconfigured PXE Boot Server.

Problem Statement

In this article, we will setup a Linux PXE server in RHEL 7, and add option to install Red Hat Enterprise Linux 7 therein.

Our PXE boot server requires different services such as DHCP, TFTP and FTP to function properly. Although, it is not necessary to configure all these services on a single machine, and if you have a running FTP server, you may place the required installation files on your existing FTP server. Similarly, if you have a DHCP server configured for your network, you may define the DHCP configurations therein.

However, for simplicity, we will configure all these services on the same machine.

Note: In this article, we are performing everything from CLI, therefore, it is highly recommended that, you should have Linux Pocket Guide: Essential Commands (PAID LINK) by O’Reilly Media for quick reference.

System Specification

We have a Linux machine with following machine. We will setup it as the PXE boot server.

Configure DHCP Service

Connect to pxe-server.itlab.com using ssh.

Install DHCP server using yum.

# yum install -y dhcp

Configure DHCP service.

# cat >> /etc/dhcp/dhcpd.conf << EOF
> #DHCP configuration for PXE boot server
> ddns-update-style interim;
> ignore client-updates;
> authoritative;
> allow booting;
> allow bootp;
> allow unknown-clients;
>
> subnet 192.168.116.0
> netmask 255.255.255.0
> {
> range 192.168.116.100 192.168.116.199;
> option domain-name-servers 192.168.116.2;
> option domain-name "itlab.com";
> option routers 192.168.116.2;
> option broadcast-address 192.168.116.255;
> default-lease-time 600;
> max-lease-time 7200;
> #PXE boot server
> next-server 192.168.116.41;
> filename "pxelinux.0";
> }
> EOF

Start and enable dhcpd.service.

# systemctl start dhcpd.service && systemctl enable dhcpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.

Allow DHCP service through Linux firewall. Also, proxy-dhcp port is required for propagation of TFTP server’s IP Address.

# firewall-cmd --permanent --add-service={dhcp,proxy-dhcp}
success
# firewall-cmd --reload
success

Configure TFTP Service

Install TFTP (Trivial FTP) server using yum.

# yum install -y tftp-server

Start and enable tftp.service.

# systemctl start tftp.service && systemctl enable tftp.service

Allow TFTP service through Linux firewall.

# firewall-cmd --permanent --add-service=tftp
success
# firewall-cmd --reload
success

Configure FTP Service

FTP Service is required to share the OS Installation media to PXE boot clients. Some system administrators use NFS instead of FTP service. However, if we use NFS then we have to configure Samba as well, when we are going to add Microsoft Windows OS installation options to our PXE boot server. Therefore, it is good to use a single common technology to share the OS installation media for different operating systems. HTTP is also a good alternative of FTP, and can be used to share OS installation media.

Install VSFTPD server using yum.

# yum install -y vsftpd

Start and enable vsftpd.service.

# systemctl enable vsftpd.service && systemctl start vsftpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

Allow FTP Service through Linux firewall.

# firewall-cmd --permanent --add-service=ftp
success
# firewall-cmd --reload
success

Installing Syslinux

Syslinux package provides various bootloaders including FAT filesystem to boot into Microsoft Windows environment.

Install syslinux package via yum.

# yum install -y syslinux

Configure PXE Boot Server

Copy necessary bootloaders (provided by syslinux) to /var/lib/tftpboot directory.

# cp -v /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
â/usr/share/syslinux/pxelinux.0â -> â/var/lib/tftpboot/pxelinux.0â

# cp -v /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
â/usr/share/syslinux/menu.c32â -> â/var/lib/tftpboot/menu.c32â

# cp -v /usr/share/syslinux/mboot.c32 /var/lib/tftpboot/
â/usr/share/syslinux/mboot.c32â -> â/var/lib/tftpboot/mboot.c32â

# cp -v /usr/share/syslinux/chain.c32 /var/lib/tftpboot/
â/usr/share/syslinux/chain.c32â -> â/var/lib/tftpboot/chain.c32â

Create necessary directories.

# mkdir /var/lib/tftpboot/pxelinux.cfg
# mkdir -p /var/lib/tftpboot/networkboot/rhel7
# mkdir /var/ftp/pub/rhel7

Copy contents of RHEL 7.5 ISO to /var/ftp/pub/rhel7. we have mounted RHEL 7.5 ISO at /mnt/iso, therefore, we are using following command for copying contents of ISO file.

# cp -rf /mnt/iso/ /var/ftp/pub/rhel7

Copy boot images of RHEL 7.5 to /var/lib/tftpboot/networkboot/rhel7 directory.

# cp /var/ftp/pub/rhel7/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/networkboot/rhel7/

Configure PXE boot menu and add Red Hat Enterprise Linux 7 installation option therein.

# cat >> /var/lib/tftpboot/pxelinux.cfg/default << EOF
> default menu.c32
> prompt 0
> timeout 30
> menu title Ahmer's PXE Menu
> label Install RHEL 7.5
> kernel /networkboot/rhel7/vmlinuz
> append initrd=/networkboot/rhel7/initrd.img inst.repo=ftp://192.168.116.41/pub/rhel7
> EOF

Connect a new system to network and boot it. The new system will automatically obtain an IP Address from our DHCP Server and obtain the PXE boot menu from PXE Server and display it as follows:

PXE Menu (BIOS)

Since, we have only one installation option so far, therefore, press <ENTER> to start installation.

Install Linux over PXE

We have successfully setup a PXE boot server in RHEL/CentOS 7. The installation process here is not automated. In our next article Kickstart: Automate PXE Client Installations, we will transform the same manual installation process to an automated installation with predefined configurations using Kickstart.

Recommended Online Training: Learn Bash Shell in Linux for Beginners

Final Thoughts

If you found this guide on setting up a Linux PXE server useful and need expert assistance, I’m here to help. I offer professional services to ensure your PXE server setup is efficient and effective. Visit my Fiverr profile for more details and to get started: Linux Admin. Let’s streamline your PXE server configuration together!

Exit mobile version