homehowtokbslinksaboutcontactprojectsmusic

Index > Help Tutorials > iPXE Setup in Ubuntu 16.04 LTS
Contents
TFTP/PXE Setup
iPXE Setup

TFTP/PXE Setup

install
sudo apt install atftpd syslinux -y
sudo systemctl enable atftpd sudo systemctl restart atftpd create configuration directories
mkdir -pv /srv/tftp/{,krls,imgs,iso,pxelinux.cfg}
Create pxe menu with local boot option only
cat << eot > /srv/tftp/pxelinux.cfg/default
# Default boot option to use
        DEFAULT vesamenu.c32
# Prompt user for select
        PROMPT 0
# Timeout value [10=1 second] for PXE menu
        TIMEOUT 100
# Show menu only if CTRL key is pressed during dhcp query
#        MENU SHIFTKEY 1
# Menu configuration
        MENU WIDTH 78
        MENU MARGIN 15
        MENU ROWS 12
        MENU PASSWORDMARGIN 16
        MENU PASSWORDROW 13
        MENU TIMEOUTROW 20
#       MENU MASTER PASSWD $1$RKJ.jKLr$jWgDXiLlMwBVtWaxYvzEk1
        MENU BACKGROUND #000000
        MENU COLOR SEL          01;36;10     #000000 #eeeeee
        MENU COLOR BORDER       30;44;10     #eeeeee #000000
        MENU COLOR SCROLLBAR    30;44;10     #eeeeee #000000
        MENU COLOR TITLE        01;36;44     #eeeeee #000000  
        MENU TITLE PXE Menu


LABEL local
        MENU DEFAULT
        MENU LABEL Local Boot
        localboot 0

        kernel chain.c32
        append hd0

        TEXT HELP
        Boot from the local hard drive.
        If you are unsure, select this option.
        ENDTEXT
eot
copy memdisk kernel
cp -v /usr/lib/syslinux/memdisk /srv/tftp/krls
copy necessary files
cp -v /usr/lib/syslinux/modules/bios/{ldlinux.c32,libcom32.c32,libutil.c32,chain.c32,vesamenu.c32} /srv/tftp
get pxelinux.0 file
wget -O /srv/tftp/pxelinux.0 http://archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/current/images/netboot/pxelinux.0
copy pxelinux.0 to tftp root
cp ~/pxelinux.0 /srv/tftp
start manually
sudo atftpd --daemon /srv/tftp
setup tftp as service
sed -i s,USE_INETD=true,USE_INETD=false,g /etc/default/atftpd
now start service
/etc/init.d/atftpd start
reference
Go up

iPXE Setup

apt install git make gcc liblzma-dev mkisofs isolinux
compile it
git clone git://git.ipxe.org/ipxe.git
create ipxe script
nano ~/menu.ipxe
and paste the following in it
#!ipxe
dhcp 
params
param mac ${net0/mac}
chain http://${next-server}/ipxe/index.php##params
go to ipxe source directory
cd ipxe/src
make some changes to setting to include needed iPXE commands

sed -i s,'//#define IMAGE_MULTIBOOT','#define IMAGE_MULTIBOOT',g config/general.h
sed -i s,'//#define IMAGE_PXE','#define IMAGE_PXE',g config/general.h
sed -i s,'//#define IMAGE_SCRIPT','#define IMAGE_SCRIPT',g config/general.h
sed -i s,'//#define IMAGE_BZIMAGE','#define IMAGE_BZIMAGE',g config/general.h

uncomment IMAGE_MULTIBOOT, IMAGE_PXE, IMAGE_SCRIPT, IMAGE_BZIMAGE, IMAGE_PNG. In my setup they are on line 106-109 and 114, lines will vary so check before hand
sed -i '106,109 s,//,,' config/general.h
sed -i '114 s,//,,' config/general.h
uncomment useful commands to be added in iPXE from config/general.h file
sed -i s,'//#define IMAGE_MULTIBOOT','#define IMAGE_MULTIBOOT',g config/general.h
sed -i s,'//#define IMAGE_PXE','#define IMAGE_PXE',g config/general.h
sed -i s,'//#define IMAGE_SCRIPT','#define IMAGE_SCRIPT',g config/general.h
sed -i s,'//#define IMAGE_BZIMAGE','#define IMAGE_BZIMAGE',g config/general.h
sed -i s,'//#define NSLOOKUP_CMD','#define NSLOOKUP_CMD',g config/general.h
sed -i s,'//#define TIME_CMD','#define TIME_CMD',g config/general.h
sed -i s,'//#define VLAN_CMD','#define VLAN_CMD',g config/general.h
sed -i s,'//#define PXE_CMD','#define PXE_CMD',g config/general.h
sed -i s,'//#define REBOOT_CMD','#define REBOOT_CMD',g config/general.h
sed -i s,'//#define POWEROFF_CMD','#define POWEROFF_CMD',g config/general.h
sed -i s,'//#define PCI_CMD','#define PCI_CMD',g config/general.h
sed -i s,'//#define PARAM_CMD','#define PARAM_CMD',g config/general.h
sed -i s,'//#define PING_CMD','#define PING_CMD',g config/general.h
sed -i s,'//#define CONSOLE_CMD','#define CONSOLE_CMD',g config/general.h
sed -i s,'//#define IPSTAT_CMD','#define IPSTAT_CMD',g config/general.h
sed -i s,'//#define NTP_CMD','#define NTP_CMD',g config/general.h
uncomment useful commands to be added in iPXE from config/settings.h file, in my setup they are on line 13-16
sed -i '12,16 s,//,,' config/settings.h
now compile ipxe.iso file with embedded script menu.ipxe
make bin/ipxe.iso EMBED=~/menu.ipxe
compile ipxe.lkrn
make bin/ipxe.lkrn
copy ipxe.lkrn to tftp
cp ~/ipxe/src/bin/ipxe.lkrn /srv/tftp/krls/
setup tftp/pxe to load ipxe
cat << eot >> /srv/tftp/pxelinux.cfg/default

LABEL iPXE
        MENU LABEL iPXE
        kernel krls/memdisk keeppxe
        append iso initrd=iso/ipxe.iso

        text help
        Boot to iPXE kernel
        endtext
eot
cat << eot >> /srv/tftp/pxelinux.cfg/default

LABEL iPXE
        MENU LABEL iPXE
        kernel krls/ipxe.lkrn
        append dhcp && chain http://\${next-server}/ipxe/index.php?mac=\${net0/mac}

        text help
        Boot to iPXE kernel
        endtext
eot
Go up
That is it, your PXE server is ready with iPXE support. Now install Apache and php
apt install apache2 libapache2-mod-php php php-doc php-cli php-cgi php-mysql php-ldap mysql-client
now create separate directory for ipxe
mkdir -pv /var/www/html/ipxe
create ipxe menu file
cat << eot > /var/www/html/ipxe/index.php

eot
create directories for boot kernels, boot images, and boot iso
mkdir -pv /var/www/html/ipxe/{,krls,imgs,iso}