Ben Stienstra

Linux, Unix, network, radio and more...

User Tools

Site Tools


Raspberry Pi - PXE server

I was in need of a simple small PXE server (DHCP and TFTP). PXE server on ethernet, management via wifi.


  • Old first gen. RPI.
  • SDCard, large enough to host images / files.
  • Wifi dongle (for management).
  • Most of the commands below need to be run as root.

Raspbian install

  • Download latest Raspbian Lite (Stretch)
  • Validate download:
    # From website:
  • Check if partitions already have been mounted and unmount those.
    lsblk # or mount command
    umount /dev/sdX{1,2}
  • Copy image to SDCard:
    dd if=2017-11-29-raspbian-stretch-lite.img of=/dev/sdX bs=1M && sync
  • Mount partitions (unmount first if auto-mounted under /run/media/…):
    mount /dev/sdX2 /mnt
    mount /dev/sdX1 /mnt/boot
  • Enable SSH:
    touch /mnt/boot/ssh
  • Generate wifi config:
    wpa_passphrase YOUR_SSID YOUR_PASSPHRASE >> /mnt/etc/wpa_supplicant/wpa_supplicant.conf
    # Remove the plaintext passphrase, change country
    vi /mnt/etc/wpa_supplicant/wpa_supplicant.conf
  • Set hostname:
    echo pxe >/mnt/etc/hostname
  • unmount partitions

RPI configuration

  • Boot the RPI with the above prepared SDcard.
  • If everything went well, it will connect to your wifi network.
  • Log in, using SSH, with username and password:pi:raspberry.
    ssh pi@pxe
  • Change user pi password. Or create a new account and delete the pi user.
  • Update the OS:
    sudo su -
    apt-get update
    apt-get upgrade
  • Configure the RPI:
    - Boot options: console
    - Locale
    - Timezone
    - Expand filesystem
  • Reboot
  • Check for new firmware:
  • Install and configure uncomplicated firewall
    apt-get install ufw
    ufw allow ssh
    ufw allow in on eth0 from any port 68 to any port 67 proto udp
    ufw allow in on eth0 from any to any proto udp port 69
    ufw default deny
    ufw enable
    modprobe nf_conntrack_tftp # temporary, line below is for loading at boot
    echo "nf_conntrack_tftp" >> /etc/modules-load.d/modules.conf
  • Disable unnecessary services:
    systemctl disable avahi-daemon --now

PXE server

  • Configure static IP address on network interface:
    cat >> /etc/dhcpcd.conf <<EOF
    interface eth0
    static ip_address=
    systemctl daemon-reload
    systemctl restart dhcpcd
  • Install packages:
    apt-get install dnsmasq syslinux-common pxelinux
  • Configure dnsmasq:
    cat > /etc/dnsmasq.d/server.conf <<EOF
    # For BIOS based systems
    mkdir /var/lib/tftp
    systemctl restart dnsmasq
    mkdir -p /var/lib/tftp/pxelinux.cfg
    ln -s /usr/lib/PXELINUX/pxelinux.0 /var/lib/tftp/
    ln -s /usr/lib/syslinux/modules/bios/ldlinux.c32 /var/lib/tftp/

Memtest example (for serial console)

  • Memtest 5.01
    gunzip memtest86+-5.01.bin.gz
    mkdir -p /var/lib/tftp/memtest
    cp memtest86+-5.01.bin /var/lib/tftp/memtest/memtest86+-5.01
    cat > /var/lib/tftp/pxelinux.cfg/default <<EOF
    console 0
    serial 0 115200 0
    default memtest86
    prompt 1
    timeout 15
    label memtest86
      menu label Memtest86+ 5.01
      kernel /memtest/memtest86+-5.01 console=ttyS0,115200
    systemctl restart dnsmasq

Voyage Linux example

  • Download voyage-0.11.0_amd64.iso.
  • Prepare Voyage Linux 0.11 config:
    mkdir /var/lib/tftp/voyage0.11
    mount -o loop voyage-0.11.0_amd64.iso /mnt
    cp /mnt/live/initrd.img /var/lib/tftp/voyage0.11/
    cp /mnt/live/vmlinuz /var/lib/tftp/voyage0.11/
    cp /mnt/live/filesystem.squashfs /var/lib/tftp/voyage0.11/
    cat > /var/lib/tftp/pxelinux.cfg/default <<EOF
    console 0
    serial 0 115200 0
    default Voyage
    prompt 5
    timeout 15
    LABEL Voyage
        MENU LABEL Voyage
        KERNEL /voyage0.11/vmlinuz
        APPEND initrd=/voyage0.11/initrd.img boot=live fetch=tftp:// live-getty noautologin console=ttyS0,115200
  • Log in and install Voyage:
    ssh root@<dhcp-address> #pass = voyage
    /usr/local/sbin/ /dev/sdX
    mkdir /mnt/cf
raspberry_pi_pxe_server.txt · Last modified: 2017/12/05 16:28 by admin