Hi
Because I can't find a straight forward documentation about PXE boot with Raspi and LibreELEC, I will post my configuration, where I did today. I won't go in the details like how to install DHCP server, NFS server etc. There are a lot of good documentation... So let's start...
Prerequirements (can be found on the net):
- A working DHCP server
- A working TFTP server
- A working NFS server
- A Raspberry who can and is configured for PXE boot
- Knowledge about TFTP, NFS, DHCP, Linux etc.
My setup:
- opnSense firewall who is responsible for DHCP requests (10.243.29.1)
- Ubuntu 18.04.3 who do the TFTP and NFS stuff with the IP 10.243.29.10
- Rasperry Pi 3B+ with serial number 3X84XbXf and a via DHCP assigned IP 10.243.29.112
- LibreELEC 9.2.0
1. DHCP server configuration
I use my opnSense as my DHCP server, so maybe you have to adapt the settings to your DHCP server, but here is my configuration with the Raspi PXE special configured fields:
Services/DHCPv4/[lan]/TFTP server/Set TFTP hostname: 10.243.29.10
Services/DHCPv4/[lan]/TFTP server/Set Bootfile: [let them empty]
Services/DHCPv4/[lan]/Additional Options/Number:43 Type:Text Value:Raspberry Pi Boot
Services/DHCPv4/[lan]/Additional Options/Number:60 Type:Text Value:PXEClient
2. TFTP server configuration
I use tftpd-hpa (apt-get install tftpd-hpa) as server and I made these changes:
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure -vvv"
Don't forget to systemctl restart tftpd-hpa.service and let the TFTP server automatic start after reboot.
3. NFS server
There is nothing special configured on the NFS server, but here is my /etc/exports config to understand also next points:
/nfs 10.243.29.0/24(rw,sync,no_subtree_check,no_root_squash)
So, everything related to NFS is in the /nfs directory and don't forget to let the NFS server start after a reboot.
4. LibreELEC image
Download the latest LibreELEC Image from https://libreelec.tv/downloads_new/raspberry-pi-3-3 (or whatever you have) to your TFTP server, extract it, mount it temporary and copy the bootcode.bin file to the root directory from the TFTP server:
root@home-ch-zrh01-lin01:/tmp# wget http://releases.libreelec.tv/LibreELEC-RPi2.arm-9.2.0.img.gz
root@home-ch-zrh01-lin01:/tmp# losetup -f -P /tmp/LibreELEC-RPi2.arm-9.2.0.img
root@home-ch-zrh01-lin01:/tmp# losetup -l
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop1 0 0 1 1 /var/lib/snapd/snaps/core_8268.snap 0 512
/dev/loop0 0 0 1 1 /var/lib/snapd/snaps/core_8213.snap 0 512
/dev/loop3 0 0 0 0 /tmp/LibreELEC-RPi2.arm-9.2.0.img 0 512
root@home-ch-zrh01-lin01:/tmp# mkdir /tmp/1
root@home-ch-zrh01-lin01:/tmp# mount /dev/loop3p1 /tmp/1/
root@home-ch-zrh01-lin01:/tmp# cp -vax /tmp/1/bootcode.bin /var/lib/tftpboot/
Don't unmount the loop device, we need it later again...
5. Get the Raspi serial number
Now, just let your Raspi boot with PXE and have a look in /var/log/syslog, you can find a lot of sending NAK (1, File not found) to 10.243.29.112, but also the requests to the requested files, like RRQ from 10.243.29.112 filename 3X84XbXf/start.elf
And here you are, you have your Raspi serial number: 3X84XbXf
Ah, the filename in the syslog is relative to the tftp configuration where I set in /etc/default/tftpd-hpa:TFTP_DIRECTORY before.
So you can have for each Raspi in your network your own PXE configuration, cool...
6. Prepare the files on the TFTP server
Because we have the LibreELEC image still mounted and also the serial number from our Raspi, we have to bring the things together and I change the cmdline.txt file:
root@home-ch-zrh01-lin01:/tmp# mkdir /var/lib/tftpboot/3X84XbXf
root@home-ch-zrh01-lin01:/tmp# cp -vax /tmp/1/* /var/lib/tftpboot/3X84XbXf/
root@home-ch-zrh01-lin01:/tmp# echo "boot=NFS=10.243.29.10:/nfs/Raspi/3X84XbXf.boot disk=NFS=10.243.29.10:/nfs/Raspi/3X84XbXf.disk ssh ip=dhcp" >/var/lib/tftpboot/3X84XbXf/cmdline.txt
7. Prepare the files on the NFS server
On the NFS server, we have to prepare now the directories. The 3X84XbXf.boot is for the little binary stuff (only the "SYSTEM" file) and the 3X84XbXf.disk for the data from LibreELEC, we let them empty, LibreELEC fill it up after the first start. If you have the TFTP and NFS server on separate machines, you have to copy the file for the 3X84XbXf.boot directory from your TFTP server or download the LibreELEC again and attach it via loop again. For me, it's on the same machine and the image is still mounted to /tmp/1:
root@home-ch-zrh01-lin01:/tmp# mkdir -p /nfs/Raspi/3X84XbXf.boot /nfs/Raspi/3X84XbXf.disk
root@home-ch-zrh01-lin01:/tmp# cp -vax /tmp/1/SYSTEM /nfs/Raspi/3X84XbXf.boot
Now, we don't need the LibreELEC image anymore, so you can unmount it and remove it as a loop device, or just reboot everything... Also the Raspi, because it should now boot from network and you can start to configure it
8. Something won't work
Check the DHCP server log, what's going on with the requests (maybe you need to dump the packets with tcpdump).
Have a look on the TFTP server's syslog file about "not found's".
If everything is fine there and the problem is on the NFS side, you can start NFS debugging in the NFS server with rpcdebug -m nfsd -s proc, now everything is logged also to the syslog file. Stop it with rpcdebug -m nfsd -c
I hope this help's you a bit through the jungle...
gruss ivo