Setting up PXE / BOOTP / TFTP

RHEL / Ubuntu / Devuan / Slackware

Requirements

Ubuntu and Devuan,

apt install isc-dhcp-server tftpd-hpa tftp inetutils-inetd pxelinux nginx

RHEL,

yum install dhcp syslinux tftp-server

Slackware,

ls -l /var/log/packages/{dhcp-,syslinux-,tftp-hpa-}*

DHCP

ifconfig | grep inet

mv -i /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.dist
vi /etc/dhcp/dhcpd.conf
#mv -i /etc/dhcpd.conf /etc/dhcpd.conf.dist
#vi /etc/dhcpd.conf

allow bootp;
ddns-update-style none;
allow unknown-clients;

subnet 172.17.0.0 netmask 255.255.0.0 {
}

subnet 10.8.8.0 netmask 255.255.255.0 {
        range 10.8.8.100 10.8.8.199;
        next-server 10.8.8.1;
        filename "pxelinux.0";
        #filename "syslinux.efi";
        #filename "pxeboot_ia32.bin";
        option root-path "10.8.8.1:/tftpboot";

         if substring (option vendor-class-identifier, 0, 17)
           = "NetBSD:i386:libsa" {
             if filename = "netbsd" {
                 filename "tftp:netbsd8/amd64/binary/kernel/netbsd-INSTALL.gz";
             }
         }
}

#allow booting;
#option option-128 code 128 = string;
#option option-129 code 129 = text;

dhcpd -t -cf /etc/dhcp/dhcpd.conf
#dhcpd -t -cf /etc/dhcpd.conf

In case you want your network to get access to the internet,

option routers x.x.x.254;
option domain-search "example.local";
#option domain-name example.local;
option domain-name-servers 208.67.222.222, 208.67.222.220;

TFTP

ls -lhd /tftpboot/
ls -lhd /var/lib/tftpboot/
#ln -s var/lib/tftpboot /tftpboot

Ubuntu,

ls -lhF /usr/sbin/in.tftpd
cp -pi /etc/default/tftpd-hpa /etc/default/tftpd-hpa.dist
vi /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-l -s"
RUN_DAEMON="yes"

Devuan with IPv6 disabled at boot time,

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-4 --secure"

RHEL,

vi /etc/xinetd.d/tftp

disable = no

Slackware,

mv -i /etc/inetd.conf /etc/inetd.conf.dist
grep '^# tftp' /etc/inetd.conf.dist | sed 's/^# //' > /etc/inetd.conf

for the record, the content will be,

tftp  dgram   udp     wait    root    /usr/sbin/in.tftpd  in.tftpd -s /tftpboot -r blksize

chmod +x /etc/rc.d/rc.inetd
/etc/rc.d/rc.inetd restart

Acceptance testing,

tftp x.x.x.x

get netbsd-INSTALL.gz

PXE Configuration

handy symlinks,

cd ~/
ls -ldhF /tftpboot/
ln -s ../tftpboot
#ls -ldhF /var/lib/tftpboot/
#ln -s ../var/lib/tftpboot

the needed stuff for PXELINUX to work,

#tmp=/usr/lib/syslinux/modules/bios/
tmp=/usr/share/syslinux

locate ldlinux.c32 ldlinux.e64 pxelinux.0 | grep $tmp

legacy PXE,

cd /tftpboot/
rm -f ldlinux.* libutil.c32 menu.c32 pxelinux.0 syslinux*.efi

for f in ldlinux.c32 libutil.c32 menu.c32 pxelinux.0; do
    echo -n $f...
    cp -f $tmp/$f /tftpboot/ && echo done
done; unset f

PXE/EFI64,

for f in efi64/ldlinux.e64 efi64/libutil.c32 efi64/menu.c32 efi64/syslinux.efi; do
    echo -n $f...
    cp -f $tmp/$f /tftpboot/ && echo done
done; unset f
chmod -x /tftpboot/syslinux*.efi

unset tmp
#meminfo.c32

PXELINUX setup,

mkdir -p /tftpboot/pxelinux.cfg/
vi /tftpboot/pxelinux.cfg/default

default menu.c32
prompt 0
menu title pxe
#menu title pxe/efi64

HTTP & NFS

Slackware, using HTTP,

sbopkg -i thttpd
cp /etc/thttpd.conf /etc/thttpd.conf.dist           
vi /etc/thttpd.conf

#host=localhost

dir=/tftpboot

thttpd -C /etc/thttpd.conf
ps auxw | grep thttpd

#ldd /usr/lib64/libgd.so
#sbopkg -i nginx

Slackware, using NFS,

mv /etc/exports /etc/exports.dist
vi /etc/exports

/tftpboot       x.x.x.x/24(ro,root_squash,async,subtree_check)

exportfs -ra

Ubuntu, using HTTP,

apt install nginx
cp -pi /etc/nginx/sites-available/default /etc/nginx/sites-available/default.dist
vi /etc/nginx/sites-enabled/default

#listen [::]:80 default_server;

#root /var/www/html;
root /tftpboot;
autoindex on;

Kernels and Repositories

Ready to go

stop & start in order

tail -n0 -F /var/log/* /var/log/*/*

Ubuntu,

systemctl stop nginx
systemctl stop tftpd-hpa
systemctl stop isc-dhcp-server

systemctl start isc-dhcp-server
systemctl start tftpd-hpa
systemctl start nginx

Devuan,

service nginx stop
service tftpd-hpa stop
service isc-dhcp-server stop

service isc-dhcp-server start
service tftpd-hpa start
service nginx start

RHEL,

systemctl restart dhcpd

Slackware,

ps auxw | grep dhcpd
ps auxw | grep inetd
pkill dhcpd
dhcpd -q NETIF NETIF    
/etc/rc.d/rc.inetd restart

check the services,

ps auxw | egrep 'dhcpd|tftp'
curl -s localhost/

resulting processes on Ubuntu,

/usr/sbin/in.tftpd --listen --user tftp --address :69 -l -s /tftpboot

dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf

resulting processes on Devuan,

/usr/sbin/in.tftpd --listen --user tftp --address 0.0.0.0:69 -4 --secure /tftpboot

/usr/sbin/dhcpd -4 -q -cf /etc/dhcp/dhcpd.conf

Testing your PXE Service

WARNING: iPXE 1.0.0+ on VirtualBox did not let the NetBSD boot loader, once loaded tru PXE, use TFTP again, nor did the Ubuntu installer fully show up, but I did not troubleshoot that one so far. One cannot fully test with VirtualBox, use hardware.

However for quick tests as first attempts,

brctl addbr dummybr0
ifconfig dummybr0 x.x.x.x/24 up
curl x.x.x.x

and eventually bind a virtual machine and its NIC to that bridge.

References