CentOS

Configuring PXE Network Boot Server on CentOS 7

PXE is a protocol used to boot operating system installers over the network. Then, you can install it on your server or workstation. You won’t need any CD/DVD or USB for that. Using a PXE boot server, you can install an operating system on all of the computers in a network at the same time. This will save you a lot of time.

In this article, I am going to show you how to setup a PXE boot server on CentOS 7 and configure it to boot Fedora 30 Workstation Live installer over the network via PXE. So, let’s get started.

Network Topology:

Here, I will configure a CentOS 7 server as a PXE boot server. The PXE boot server will serve Fedora 30 Workstation Live installation media to the PXE clients. Then, I will install Fedora 30 Workstation on the PXE client over the network. The PXE boot server will have a fixed IP 192.168.50.1. The PXE client will be on the same network.

Configuring the Network:

You can use nmtui to configure a static IP to the network interface on your CentOS 7 machine. To learn how to do that, you may read a dedicated article on this topic at https://linuxhint.com/setup_static_ip_centos7/

Here, I used ens37 for configuring PXE boot server. Change it depending on your setup.

Installing and Configuring DHCP and TFTP for PXE Boot:

You have to configure a DHCP and a TFTP server for PXE boot. I will use dnsmasq for that.

First, update the YUM package repository cache with the following command:

$ sudo yum makecache

Now, install the dnsmasq with the following command:

$ sudo yum install -y dnsmasq

dnsmasq should be installed.

Now, rename the original /etc/dnsmasq.conf file to /etc/dnsmasq.conf.backup as follows:

$ sudo mv -v /etc/dnsmasq.conf /etc/dnsmasq.conf.backup

Now, create an empty dnsmasq.conf file with the following command:

$ sudo vi /etc/dnsmasq.conf

Now, type in the following lines to the file:

interface=ens37
bind-interfaces
domain=linuxhint.local
 
dhcp-range=ens37,192.168.50.100,192.168.50.240,255.255.255.0,8h
dhcp-option=option:router,192.168.50.1
dhcp-option=option:dns-server,192.168.50.1
dhcp-option=option:dns-server,8.8.8.8
 
enable-tftp
tftp-root=/netboot/tftp
dhcp-boot=pxelinux.0,linuxhint,192.168.50.1
pxe-prompt="Press F8 for PXE Network boot.", 5
pxe-service=x86PC, "Install OS via PXE",pxelinux

The final configuration file should look as follows. Once you’re done, save the configuration file.

Now, create a new directory /netboot/tftp for TFTP as follows:

$ sudo mkdir -p /netboot/tftp

Now, restart the dnsmasq service with the following command:

$ sudo systemctl restart dnsmasq

NOTE: I set SELinux to permissive mode on my CentOS 7 machine. Because, if SELinux is set to enforcing mode, dnsmasq won’t start in this configuration. Covering SELinux is out of the scope of this article.

Now, check whether the dnsmasq service is running or not with the following command:

$ sudo systemctl status dnsmasq

As you can see, dnsmasq service is running.

Now, add the dnsmasq service to the system startup as follows:

$ sudo systemctl enable dnsmasq

Installing and Configuring PXE Bootloader:

Now, you have to install the PXE bootloader files and copy them over to the TFTP root directory.

To install the PXE bootloader files, run the following command:

$ sudo yum install -y syslinux

Once syslinux is installed, copy the pxelinux.0 and menu.c32 files to the /netboot/tftp directory as follows:

$ sudo cp -v /usr/share/syslinux/{pxelinux.0,menu.c32} /netboot/tftp/

Now, create PXE bootloader configuration directory /netboot/tftp/pxelinux.cfg/ as follows:

$ sudo mkdir /netboot/tftp/pxelinux.cfg

Now, create PXE bootloader’s default configuration file /netboot/tftp/pxelinux.cfg/default as follows:

$ sudo touch /netboot/tftp/pxelinux.cfg/default

TFTP server is now able to serve all the required bootloader files over the network.

Installing Apache Web Server:

Fedora 30 Workstation uses Dracut as the kernel command line option provider. It supports PXE booting over HTTP. So, I am going to use the Apache 2 web server to serve the Fedora 30 Workstation files over the network.

To install Apache 2 web server, run the following command:

$ sudo yum install -y httpd

Apache 2 should be installed.

Now, make a symbolic link /netboot/www of the /var/www/html directory for easier management of the PXE boot server as follows:

$ sudo ln -s /var/www/html /netboot/www

The symbolic link should be created.

$ ls -l /netboot/

Now, start the httpd service as follows:

$ sudo systemctl start httpd

Now, check whether the httpd service is running as follows:

$ sudo systemctl status httpd

As you can see, the httpd service is running correctly.

Now, add the httpd service to the system startup with the following command:

$ sudo systemctl enable httpd

Preparing Fedora 30 Workstation for PXE Boot:

Now, download the Fedora 30 Workstation Live ISO image with the following command:

$ wget https://download.fedoraproject.org/pub/fedora/linux/releases/30/Workstation/
x86_64/iso/Fedora-Workstation-Live-x86_64-30-1.2.iso

It will take a while for the download to complete.

Now, mount the Fedora 30 Workstation Live ISO image on the /mnt directory as follows:

$ sudo mount -o loop Fedora-Workstation-Live-x86_64-30-1.2.iso /mnt

Now, create dedicated directories for Fedora 30 Workstation /netboot/www/fedora30/ and /netboot/tftp/fedora30/ as follows:

$ sudo mkdir -v /netboot/{tftp,www}/fedora30

Now, copy the contents of the ISO file to the /netboot/www/fedora30/ directory as follows:

$ sudo cp -Rfv /mnt/* /netboot/www/fedora30/

The contents of the Fedora 30 Workstation ISO file should be copied.

Now, copy the initrd.img and vmlinuz files of Fedora 30 Workstation to the /netboot/tftp/fedora30/ directory as follows:

$ sudo cp -v /netboot/www/fedora30/images/pxeboot/{initrd.img,vmlinuz}
 /netboot/tftp/fedora30/

Now, you can unmount the Fedora 30 Workstation ISO image and delete it if you want.

$ sudo umount /mnt
$ rm Fedora-Workstation-Live-x86_64-30-1.2.iso

Adding PXE Boot Entry for Fedora 30 Workstation:

Now, you have to add a boot entry for Fedora 30 Workstation on the /netboot/tftp/pxelinux.cfg/default file.

Open the PXE boot menu configuration file /netboot/tftp/pxelinux.cfg/default for editing as follows:

$ sudo vi /netboot/tftp/pxelinux.cfg/default

Now, add the following lines to the file.

default menu.c32
label install_fedora30
menu label ^Install Fedora 30 Workstation
menu default
kernel fedora30/vmlinuz
append initrd=fedora30/initrd.img root=live:http://192.168.50.1/fedora30/
LiveOS/squashfs.img plymouth.enable=1 rd.live.image rd.luks=0 rd.md=0
rd.dm=0 rd.live.ram=1

The final configuration file should look as follows. Once you’re done, save the file.

Adding Firewall Rules:

Now, you have to open ports from your firewall for the PXE boot server to work.

Allow the DHCP service as follows:

$ sudo firewall-cmd --zone=public --add-service=dhcp --permanent

Allow the HTTP service as follows:

$ sudo firewall-cmd --zone=public --add-service=http --permanent

Allow the TFTP service as follows:

$ sudo firewall-cmd --zone=public --add-service=tftp --permanent

Allow the UDP port 4011 and 69 as follows:

$ sudo firewall-cmd --zone=public --add-port=4011/udp --permanent

$ sudo firewall-cmd --zone=public --add-port=69/udp --permanent

Now, reload the firewall as follows:

$ sudo firewall-cmd --reload

Installing Fedora 30 Workstation via PXE:

Now, on the PXE client where you want to install Ubuntu 18.04 LTS over the network via PXE, go to the BIOS and select Network Boot.

When you see the following message, press <F8> on your keyboard.

Now, select Install OS via PXE and press <Enter>.

You will only have one option. So, just press <Enter>.

Fedora 30 Workstation Live installer should start.

Now, you can install it on your client machine as usual.

So, that’s how you configure PXE boot server on CentOS 7. Thanks for reading this article.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.