Ben Stienstra

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

User Tools

Site Tools


raspberry_pi_pxe_server

Raspberry Pi - PXE server

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

Prerequisites

  • 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:
    SHA-256:
    e942b70072f2e83c446b9de6f202eb8f9692c06e7d92c343361340cc016e0c9f
    
    sha256sum 2017-11-29-raspbian-stretch-lite.zip 
    e942b70072f2e83c446b9de6f202eb8f9692c06e7d92c343361340cc016e0c9f  2017-11-29-raspbian-stretch-lite.zip
  • Check if partitions already have been mounted and unmount those.
    lsblk # or mount command
    umount /dev/sdX{1,2}
  • Copy image to SDCard:
    unzip 2017-11-29-raspbian-stretch-lite.zip
    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:
    raspi-config
    
    - Boot options: console
    - Locale
    - Timezone
    - Expand filesystem
  • Reboot
  • Check for new firmware:
    rpi-update
  • 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=10.0.0.1/24
    EOF
    
    systemctl daemon-reload
    systemctl restart dhcpcd
  • Install packages:
    apt-get install dnsmasq syslinux-common pxelinux
  • Configure dnsmasq:
    cat > /etc/dnsmasq.d/server.conf <<EOF
    no-dhcp-interface=wlan0
    
    dhcp-range=eth0,10.0.0.10,10.0.0.100
    
    enable-tftp
    tftp-root=/var/lib/tftp
    
    # For BIOS based systems
    dhcp-boot=pxelinux.0
    
    EOF
    
    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/
    ln -s /usr/lib/syslinux/modules/bios/menu.c32 /var/lib/tftp/
    ln -s /usr/lib/syslinux/modules/bios/libutil.c32 /var/lib/tftp/
    

Memtest example (for serial console)

  • Memtest 5.01
    cd 
    wget http://www.memtest.org/download/5.01/memtest86+-5.01.bin.gz
    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
    EOF
    
    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
    serial 0 115200 0
    console 0
    
    default menu.c32
    prompt 15
    
    MENU TITLE PXE Menu
    TIMEOUT 30
    
    LABEL Voyage64bit
        MENU LABEL Voyage Linux 0.11 64 bit
        KERNEL /voyage0.11/vmlinuz
        APPEND initrd=/voyage0.11/initrd.img boot=live fetch=tftp://10.0.0.1/voyage0.11/filesystem.squashfs live-getty noautologin console=ttyS0,115200
    
    LABEL Voyage32bit
        MENU LABEL Voyage Linux 0.11 32 bit
        KERNEL /voyage0.11-32bit/vmlinuz
        APPEND initrd=/voyage0.11-32bit/initrd.img boot=live fetch=tftp://10.0.0.1/voyage0.11-32bit/filesystem.squashfs live-getty noautologin console=ttyS0,115200
    EOF
    
  • Log in and install Voyage:
    ssh root@<dhcp-address> #pass = voyage
    
    /usr/local/sbin/format-cf.sh /dev/sdX
    mkdir /mnt/cf
    /usr/local/sbin/voyage.update
    
    
    
    
    Configuration details:              
    ----------------------                         
                                                             
    Distribution directory:   /          
                                                                  
    Disk/Flash Device:        /dev/sda
    Installation Partition:   /dev/sda1                          
    Bootstrap Partition:      /dev/sda1
                                                   
    Will be mounted on:       /mnt/cf                        
                                         
    Target system profile:    ALIX                        
    Target console:           serial
    Target baud rate:         115200
    
    Bootstrap installer:      grub
    Bootstrap partition:      /dev/sda1
    
    OK to continue (y/n)? y
    
raspberry_pi_pxe_server.txt · Last modified: 2018/05/13 12:19 by admin