Configure PXE Server on Centos7 for both UEFI&BIOS systems

 Install Centos 7 

Download the ISO image of centos7 and create a VM using downloaded ISO image

Once the VM is ready, logged into centos 7 and run the following command to update the system

# yum update -y

 

Set a static ip for the server. In this case, it is 192.168.1.10

Disable Selinux on the server. You can do this by editing /etc/selinux/config file:

# vim /etc/selinux/config

 

Make following changes

SELINUX=disabled

 

Confogure Installation Media

Install httpd packaged

# yum install httpd

Mount centos7 iso image to CDROM of VM

Find path of CDROM using blkid cmd

#blkid

In my case, it is /dev/sr0

Make a directory to mout centos7 iso image

# mkdir /mnt/centos7

#  mount -o loop,ro -t iso9660 /dev/sr0 /mnt/centos7

Copy the content of iso image to http server root

# cp -r /mnt/centos7/* /var/www/html/centos7

 

#mkdir /var/www/html/kickstarts

# cp /root/anaconda-ks.cfg  /var/www/html/kickstarts/ks.cfg

Start httpd service

# systemctl start httpd.service

 

Verify that http://192.168.1.10/centos7 is accessible on browser.

 

Configure TFTP server

 

# yum install tftp-server xinetd

Xinetd is used to manage tftp service

# vim /etc/xinetd.d/tftp

Set disable = no

Create a structure in tftp to support multiple options

# mkdir /var/lib/tftpboot/bios

# mkdir /var/lib/tftpboot/bios/x86

# mkdir /var/lib/tftpboot/EFI

# mkdir /var/lib/tftpboot/EFI/x86

# mkdir /var/lib/tftpboot/EFI/x86/boot

you need to copy the necessary boot files for the x86 BIOS environment to the appropriate boot location. To do so, navigate to the appropriate directory as shown below

# /mnt/centos7/images/pxeboot/

#cd /mnt/centos7/images/pxeboot/

# cp -a vmlinuz initrd.img /var/lib/tftpboot/bios/x86/

# mkdir /var/lib/tftpboot/bios/x86/pxelinux.cfg

# touch /var/lib/tftpboot/bios/x86/pxelinux.cfg/default

# vim /var/lib/tftpboot/bios/x86/pxelinux.cfg/default

Add following text to default file

default menu.c32

prompt 0

timeout 300

ONTIMEOUT 1

menu title ########## CentOS 7 PXE Boot Menu ##########

label 1

menu label ^1) Install CentOS 7

menu default

kernel vmlinuz

append initrd=initrd.img method=http://192.168.0.1/centos7 devfs=nomount

label 2

menu label ^2) Boot from local drive

localboot 0

Setting Up the x86 EFI Boot Environment

 

# cd /mnt/centos7/images/pxeboot/

# cp -a vmlinuz initrd.img /var/lib/tftpboot/EFI/x86/boot

# /mnt/centos7/EFI/BOOT/

# cp -a bootx64.efi grubx64.efi  /var/lib/tftpboot/EFI/x86/

 

Now you need to create a grub.cfg file. This file goes in /var/lib/tftpboot/EFI/x86 and should have contents similar to the below example:

# vim /var/lib/tftpboot/EFI/x86/grub.cfg

set timeout=100

menuentry 'Install centos7 uefi' --class fedora --class gnu-linux --class gnu --class os {

 linuxefi /EFI/x86/boot/vmlinuz inst.ks=http://192.168.0.1/kickstarts/ks.cfg inst.stage2=http://192.168.0.1/centos7

 initrdefi /EFI/x86/boot/initrd.img

 }

DHCP Configuration

 

Open /etc/dhcp/dhcpd.conf and add following text to it

  option space PXE;

  option PXE.mtftp-ip    code 1 = ip-address;

  option PXE.mtftp-cport code 2 = unsigned integer 16;

  option PXE.mtftp-sport code 3 = unsigned integer 16;

  option PXE.mtftp-tmout code 4 = unsigned integer 8;

  option PXE.mtftp-delay code 5 = unsigned integer 8;

  option arch code 93 = unsigned integer 16; # RFC4578

 

  subnet 192.168.0.0 netmask 255.255.255.0 {

          option routers 192.168.0.2;

          range 192.168.0.100 192.168.0.200;

 

          class "pxeclients" {

                  match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";

                  next-server 192.168.0.1;

                  if option arch = 00:07 or option arch = 00:09 {

                         filename "/EFI/x86/grubx64.efi"; }

                  else if option arch = 00:0b {

                         filename "/EFI/armv8/bootaa64.efi"; }

                  else {

                         filename "/bios/x86/pxelinux.0";}

                                }

  }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


Comments