[root@rhce-ryanrudolf]# rm -rf / 2> /dev/null

things I break/fix for fun and learning

Dec 2, 2017 - 3 minute read - Comments

PXE Server Using CentOS7 and OpenWRT

This will document the steps I did to be able to host a PXE server using CentOS and OpenWRT in my environment.

Requirements for PXE server -

  • DHCP server to assign IP addresses
  • TFTP server to host the pxe files
  • FTP server to host the install files

DHCP Server

Since I already have an OpenWRT router as my DHCP server, I cannot use the CentOS7 as a DHCP server. I can either use CentOS7 as DHCP instead of the router, but not both. Having 2 DHCP server in the same network will be a disaster!

I need to modify a config file in the OpenWRT router to let it know which server will be the TFTP server.

vi /etc/config/dhcp

add these entries at the beginning of the file -

config boot 'linux'
    option filename 'pxelinux.0'
    option serveraddress '192.168.1.5'
    option servername 'PXE'


serveraddress is the IP address of TFTP server

servername is friendly name of the TFTP server (doesn’t necessarily have to be the actual hostname)

That completes the DHCP part!

TFTP and FTP Server

For the TFTP and FTP part, we need to install additional packages -

yum install tftp tftp-server syslinux vsftpd

Once the packages are installed, we need to reconfigure the TFTP server -

vi /etc/xinetd.d/tftp

service tftp
 {
 socket_type             = dgram
 protocol                = udp
 wait                    = yes
 user                    = root
 server                  = /usr/sbin/in.tftpd
 server_args             = -s /tftpboot
 disable                 = no
 per_source              = 11
 cps                     = 100 2
 flags                   = IPv4
 }


Next step is to create the TFTP root directory and copy over the pxe network boot files -

mkdir -p /tftpboot

chmod 777 /tftpboot

cp -v /usr/share/syslinux/pxelinux.0 /tftpboot

cp -v /usr/share/syslinux/menu.c32 /tftpboot

cp -v /usr/share/syslinux/memdisk /tftpboot

cp -v /usr/share/syslinux/mboot.c32 /tftpboot

cp -v /usr/share/syslinux/chain.c32 /tftpboot

mkdir /tftpboot/pxelinux.cfg

mkdir -p /tftpboot/netboot/

Mount CentOS ISO to temp folder and copy the mounted files to FTP folder -

mount -t iso9660 CentOS.iso /tmp/iso

cp -R /tmp/iso* /var/ftp/pub

Copy initrd.img and vmlinuz from FTP folder to TFTP folder -

cp /var/ftp/pub/images/pxeboot/vmlinuz /tftpboot/netboot/

cp /var/ftp/pub/images/pxeboot/initrd.img /tftpboot/netboot/

Create a new kickstart file -

vi /var/ftp/pub/ks.cfg

Create PXE menu file (replace 192.168.1.x with the IP of FTP server) -

vi /tftpboot/pxelinux.cfg/default

default menu.c32
 prompt 0
 timeout 30
 MENU TITLE ryanrudolf PXE Menu

 LABEL centos7_x64
 MENU LABEL CentOS 7 X64
 KERNEL /netboot/vmlinuz
 APPEND  initrd=/netboot/initrd.img  inst.repo=ftp://192.168.1.x/pub  ks=ftp://192.168.1.x/pub/ks.cfg


Finally, enable and start the services -

systemctl enable xinetd

systemctl start xinetd

systemctl enable vsftpd

systemctl start vsftpd

PXE Server in action!

For testing purposes, I am using a blank virtual machine - no hdd, no iso mounted, network configured as bridged and I have a physical ethernet cable plugged into the ethernet port.

Virtual machine gets an IP address from DHCP server and requests the pxe files from the TFTP server successfully - pxe1

PXE boot menu - pxe2

CentOS7 ISO booting from the network - pxe2

TODO:

Additional steps to improve this project -

  • multiboot PXE for different OSes (Fedora, Debian, Windows etc etc)
  • thinstation thinclient distribution

Like this page? Share it!

Windows98 in 2017 This Site Now Utilizes HTTPS!

comments powered by Disqus