Nethence Newdoc Olddoc Lab Your IP BBDock  

Setting up PXE / BOOTP / TFTP

Requirements

Ubuntu,

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

RHEL,

yum install dhcp syslinux tftp-server

Slackware,

ls -1 /var/log/packages/ | grep dhcp
ls -1 /var/log/packages/ | grep sysli
ls -1 /var/log/packages/ | grep tftp

DHCP

mv -i /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.dist
vi /etc/dhcp/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";
}

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

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

Refs.

TFTP

Ubuntu,

ls -lhd /var/lib/tftpboot/
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="/var/lib/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-l -s"
RUN_DAEMON="yes"

RHEL,

ls -lhd /tftpboot/
ls -lhd /var/lib/tftpboot/

vi /etc/xinetd.d/tftp

disable = no

Note. /tftpboot on RHEL6 and /var/lib/tftpboot on RHEL7, hence on RHEL7,

ln -s var/lib/tftpboot /tftpboot

Slackware,

mkdir -p /tftpboot/pxelinux.cfg/
vi /etc/inetd.conf

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

/etc/rc.d/rc.inetd restart

PXE Configuration

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

cp -i /usr/lib/syslinux/modules/bios/ldlinux.c32 /var/lib/tftpboot/
cp -i /usr/lib/syslinux/modules/bios/libutil.c32 /var/lib/tftpboot/
#cp -i /usr/lib/syslinux/modules/bios/meminfo.c32 /var/lib/tftpboot/
cp -i /usr/lib/syslinux/modules/bios/menu.c32 /var/lib/tftpboot/
cp -i  /usr/lib/PXELINUX/pxelinux.0 /var/lib/tftpboot/

mkdir /var/lib/tftpboot/pxelinux.cfg/
vi /var/lib/tftpboot/pxelinux.cfg/default

default menu.c32
prompt 0
menu title PXE

HTTP

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

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

    tail -F /var/log/syslog &
    systemctl restart nginx
    curl -s localhost
    curl -s localhost/centos7x64/

Repositories

CentOS

Check for latest release.

Eventually spare some bandwith by copying the release from the ISO image,

mkdir mnt/; mount CentOS-7-x86_64-DVD-1708.iso mnt/
ls -ldhF /var/lib/tftpboot/
cp -R mnt/ /var/lib/tftpboot/CentOS7x64-1708/
umount mnt/; rmdir mnt/

and finish-up (namely images/pxeboot is missing) using some mirror.

remote="rsync://mirror.yandex.ru/centos/7.4.1708/os/x86_64"
#remote="rsync://mirror.logol.ru/centos/7.4.1708/os/x86_64"

rsync -avz --delete-after $remote/images/pxeboot/ /var/lib/tftpboot/centos7x64/images/pxeboot/
rsync -avz --delete-after $remote/ /var/lib/tftpboot/centos7x64/

unset remote

Setup the PXE menu,

vi /var/lib/tftpboot/pxelinux.cfg/default

label CentOS
kernel centos7x64/images/pxeboot/vmlinuz
append initrd=centos7x64/images/pxeboot/initrd.img ip=dhcp method=http://10.8.8.1/centos7x64/ text
#repo=http...
#url --url http...

label CentOS Rescue
kernel centos7x64/images/pxeboot/vmlinuz
append initrd=centos7x64/images/pxeboot/initrd.img ip=dhcp method=http://10.8.8.1/centos7x64/ rescue

label CentOS Kickstart FULLY AUTOMATED DANGEROUS
kernel centos7x64/images/pxeboot/vmlinuz
append initrd=centos7x64/images/pxeboot/initrd.img ip=dhcp method=http://10.8.8.1/centos7x64/ ks=http://10.8.8.1/centos7x64.ks text

Refs.

Slackware Linux

This is only the installer, not the full install media,

mkdir -p /var/lib/tftpboot/slackware64/
cd /var/lib/tftpboot/slackware64/
wget ftp://ftp.lip6.fr/pub/linux/distributions/slackware/slackware64/kernels/huge.s/bzImage
wget ftp://ftp.lip6.fr/pub/linux/distributions/slackware/slackware64/kernels/huge.s/config
wget ftp://ftp.lip6.fr/pub/linux/distributions/slackware/slackware64/isolinux/initrd.img

vi /var/lib/tftpboot/pxelinux.cfg/default

label Slackware Linux
kernel slackware64/bzImage
append initrd=slackware64/initrd.img load_ramdisk=1 prompt_ramdisk=0 rw SLACK_KERNEL=huge.s

Notes. about Slacware, 14.1 ==> huge.s and on 13.1 ==> hugesmp.s; vga=791 or 773 is not necessary since KMS is taking care of the video card.

Ubuntu

cd /var/lib/tftpboot/
mkdir lala/
sudo mount -o loop ubuntu-16.04.3-server-amd64.iso lala
cp -r lala/ ubuntu1604/
umount lala
rmdir lala

vi /var/lib/tftpboot/pxelinux.cfg/default

label Ubuntu
kernel ubuntu1604/install/netboot/ubuntu-installer/amd64/linux
append initrd=ubuntu1604/install/netboot/ubuntu-installer/amd64/initrd.gz vga=788 url --url http://10.8.8.1/ubuntu1604/

Refs.

Ubuntu Kickstart

cd /var/lib/tftpoot/
vi ubuntu1604.ks

install
url --url http://10.8.8.1/ubuntu1604/
...

vi /var/lib/tftpboot/pxelinux.cfg/default

label Ubuntu Kickstart 
kernel ubuntu1604/install/netboot/ubuntu-installer/amd64/linux
append initrd=ubuntu1604/install/netboot/ubuntu-installer/amd64/initrd.gz vga=788 ks=http://10.8.8.1/ubuntu1604.ks

NetBSD

Chaining pxelinx.0 to pxeboot_ia32.bin (WORKS),

rsync -avz --delete-after --exclude 'binary/sets/x*.tgz' rsync://rsync.fr.netbsd.org/NetBSD/NetBSD-7.1/amd64/ /tftpboot/netbsd7/amd64/

cd /var/lib/tftpboot/
cp netbsd7/amd64/installation/misc/pxeboot_ia32.bin ./
cp netbsd7/amd64/binary/kernel/netbsd-INSTALL.gz ./
mv netbsd-INSTALL.gz netbsd.gz

#wget http://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-7.1/amd64/installation/misc/pxeboot_ia32.bin
#wget http://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-7.1/amd64/installation/misc/MD5
#cat MD5 
#md5sum pxeboot_ia32.bin 

vi /var/lib/tftpboot/pxelinux.cfg/default

label NetBSD pxeboot
kernel pxeboot_ia32.bin

Note. it is good to keep amd64/binary/sets/ as path as this is the default used by sysinst.

Note. placing netbsd.gz in place so you will not have to play as such at the boot prompt,

boot tftp:netbsd7/amd64/binary/kernel/netbsd-INSTALL.gz

and it also avoids playing with dhcpd.conf, inside the subnet stanza (this is the trick to differenciate the hardware BOOTP requests from the NetBSD pxeboot_ia32.bin BOOTP requests,

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

Note. there is no need to rename .bin to .0,

#mv pxeboot_ia32.bin netbsdpxe.0

Tweaking pxeboot_ia32.bin, but this is unfortunately possible only from within a NetBSD system,

#installboot -v -e -o bootconf,modules pxeboot_ia32.bin
#vi boot.cfg

Otherwise, attempting multiboot (FAILS),

cp -i /usr/lib/syslinux/modules/bios/libcom32.c32 /var/lib/tftpboot/
cp -i /usr/lib/syslinux/modules/bios/mboot.c32 /var/lib/tftpboot/

vi /var/lib/tftpboot/pxelinux.cfg/default

label NetBSD multiboot
com32 mboot.c32
append netbsd7/amd64/binary/kernel/netbsd-INSTALL.gz

but this is what I get,

Invalid Multiboot image: neither ELF header nor a.out kludge found

Ref. http://www.syslinux.org/wiki/index.php/Mboot.c32

Obsolete method, using memdisk against the floppy installer (DEPRECATED),

wget ftp://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-5.0.2/i386/binary/kernel/netbsd-INSTALL_FLOPPY.gz
#TODO what is the last release providing floppy?

vi /var/lib/tftpboot/pxelinux.cfg/default

label NetBSD install floppy
kernel memdisk
append netbsd-INSTALL_FLOPPY.gz

Refs.

Ready to go

Ubuntu,

cd ~/bin
vi START_PXE

systemctl start tftpd-hpa
systemctl start isc-dhcp-server
    systemctl start nginx
sleep 1
tail -n 50 /var/log/syslog

vi STOP_PXE
    systemctl stop nginx
systemctl stop isc-dhcp-server
systemctl stop tftpd-hpa
sleep 1
tail -n 50 /var/log/syslog

vi STATUS_PXE

ps auxw | grep tftp
ps auxw | grep dhcpd

chmod +x S*_PXE

resulting processes,

/usr/sbin/in.tftpd --listen --user tftp --address :69 -l -s /var/lib/tftpboot
dhcpd -user dhcpd -group dhcpd -f -4 -pf /run/dhcp-server/dhcpd.pid -cf /etc/dhcp/dhcpd.conf

RHEL,

systemctl restart dhcpd

Slackware,

pkill dhcpd
dhcpd -q eth0

Testing

tftp 10.8.8.1

get netbsd-INSTALL.gz

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 10.8.8.1/24 up
curl 10.8.8.1

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

References


Home | GitHub | Docker Hub | Donate | Contact