Author Photo

Ahmer's SysAdmin Recipes is a blog for Linux System Administrators. This blog provides recipes for Installation & Configuration of Linux, Ubuntu, Oracle Database, MySQL, Apache, Nginx, Oracle Cloud Control, FreeIPA, Kerberos & OpenLDAP, Subversion, PXE, DevOps, etc. over Red Hat Enterprise Linux (RHEL), CentOS, Ubuntu and Windows.

Please give me your feedback and help me improve this blog. Please let me know If you want me to write on a specific topic.

Monday, 22 October 2018

Setup a PXE Boot Server in RHEL/CentOS 7

Setup a PXE boot server in rhel centos 7aPXE (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.

In this article, we will setup a PXE boot server in RHEL/CentOS 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 for quick reference.

 

System Specification:

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

CPU: 2 Core (2.4 Mhz)
Memory: 2 GB
Storage: 50 GB
Operating System: RHEL 7.5
Hostname: pxe-server.itlab.com
IP Address: 192.168.116.41/24

 

Configure DHCP Service:

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

Install DHCP server using yum.

[root@pxe-server ~]# yum install -y dhcp Loaded plugins: product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package dhcp.x86_64 12:4.2.5-68.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: dhcp x86_64 12:4.2.5-68.el7 localyum 513 k Transaction Summary ================================================================================ Install 1 Package Total download size: 513 k Installed size: 1.4 M Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 12:dhcp-4.2.5-68.el7.x86_64 1/1 Verifying : 12:dhcp-4.2.5-68.el7.x86_64 1/1 Installed: dhcp.x86_64 12:4.2.5-68.el7 Complete!

Configure DHCP service.

[root@pxe-server ~]# 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 [root@pxe-server ~]#

Start and enable dhcpd.service.

[root@pxe-server dhcp]# 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.

[root@pxe-server ~]# firewall-cmd --permanent --add-service={dhcp,proxy-dhcp} success [root@pxe-server ~]# firewall-cmd --reload success

 

Configure TFTP Service:

Install TFTP (Trivial FTP) server using yum.

[root@pxe-server ~]# yum install -y tftp-server Loaded plugins: product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package tftp-server.x86_64 0:5.2-22.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: tftp-server x86_64 5.2-22.el7 localyum 47 k Transaction Summary ================================================================================ Install 1 Package Total download size: 47 k Installed size: 64 k Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : tftp-server-5.2-22.el7.x86_64 1/1 Verifying : tftp-server-5.2-22.el7.x86_64 1/1 Installed: tftp-server.x86_64 0:5.2-22.el7 Complete!

Start and enable tftp.service.

[root@pxe-server ~]# systemctl start tftp.service && systemctl enable tftp.service

Allow TFTP service through Linux firewall.

[root@pxe-server ~]# firewall-cmd --permanent --add-service=tftp success [root@pxe-server ~]# 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.

[root@pxe-server ~]# yum install -y vsftpd Loaded plugins: product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package vsftpd.x86_64 0:3.0.2-22.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: vsftpd x86_64 3.0.2-22.el7 localyum 169 k Transaction Summary ================================================================================ Install 1 Package Total download size: 169 k Installed size: 348 k Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : vsftpd-3.0.2-22.el7.x86_64 1/1 Verifying : vsftpd-3.0.2-22.el7.x86_64 1/1 Installed: vsftpd.x86_64 0:3.0.2-22.el7 Complete!

Start and enable vsftpd.service.

[root@pxe-server ~]# 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.

[root@pxe-server ~]# firewall-cmd --permanent --add-service=ftp success [root@pxe-server ~]# firewall-cmd --reload success

 

Install syslinux:

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

Install syslinux package via yum.

[root@pxe-server ~]# yum install -y syslinux Loaded plugins: product-id, search-disabled-repos, subscription-manager This system is not registered with an entitlement server. You can use subscription-manager to register. Resolving Dependencies --> Running transaction check ---> Package syslinux.x86_64 0:4.05-13.el7 will be installed --> Processing Dependency: mtools for package: syslinux-4.05-13.el7.x86_64 --> Running transaction check ---> Package mtools.x86_64 0:4.0.18-5.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: syslinux x86_64 4.05-13.el7 localyum 990 k Installing for dependencies: mtools x86_64 4.0.18-5.el7 localyum 203 k Transaction Summary ================================================================================ Install 1 Package (+1 Dependent package) Total download size: 1.2 M Installed size: 2.6 M Downloading packages: -------------------------------------------------------------------------------- Total 24 MB/s | 1.2 MB 00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mtools-4.0.18-5.el7.x86_64 1/2 Installing : syslinux-4.05-13.el7.x86_64 2/2 Verifying : mtools-4.0.18-5.el7.x86_64 1/2 Verifying : syslinux-4.05-13.el7.x86_64 2/2 Installed: syslinux.x86_64 0:4.05-13.el7 Dependency Installed: mtools.x86_64 0:4.0.18-5.el7 Complete!

 

Configure PXE Boot Server:

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

[root@pxe-server ~]# cp -v /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ â/usr/share/syslinux/pxelinux.0â -> â/var/lib/tftpboot/pxelinux.0â [root@pxe-server ~]# cp -v /usr/share/syslinux/menu.c32 /var/lib/tftpboot/ â/usr/share/syslinux/menu.c32â -> â/var/lib/tftpboot/menu.c32â [root@pxe-server ~]# cp -v /usr/share/syslinux/mboot.c32 /var/lib/tftpboot/ â/usr/share/syslinux/mboot.c32â -> â/var/lib/tftpboot/mboot.c32â [root@pxe-server ~]# cp -v /usr/share/syslinux/chain.c32 /var/lib/tftpboot/ â/usr/share/syslinux/chain.c32â -> â/var/lib/tftpboot/chain.c32â

Create necessary directories.

[root@pxe-server ~]# mkdir /var/lib/tftpboot/pxelinux.cfg [root@pxe-server ~]# mkdir -p /var/lib/tftpboot/networkboot/rhel7 [root@pxe-server ~]# 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.

[root@pxe-server ~]# cp -rf /mnt/iso/ /var/ftp/pub/rhel7

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

[root@pxe-server ~]# 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.

[root@pxe-server ~]# 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-boot-menu-01

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

rhel-7-Installation-Language

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.

Setup a PXE Boot Server in RHEL/CentOS 7


YOU MIGHT ALSO LIKE:

6 comments:

  1. Question: How would I set up dhcp relay (if I wanted to keep my current dhcp server in use)

    ReplyDelete
    Replies
    1. dhcp package also provides dhcrelay.service.
      You can use it to configure a dhcp relay on CentOS 7.

      Delete
  2. Just would like to say that your step by step process is so precise it works after I followed it. Now I'm going to do the next step which is Kickstart to automate PXE installation :)

    ReplyDelete
  3. Thanks so much Boss

    ReplyDelete