Skip to content

Instantly share code, notes, and snippets.

@neofob
Forked from rikka0w0/pxe_tftp_openwrt.md
Created February 21, 2025 02:04
Show Gist options
  • Select an option

  • Save neofob/60b8200ccab5de0b3143f09edd3c053b to your computer and use it in GitHub Desktop.

Select an option

Save neofob/60b8200ccab5de0b3143f09edd3c053b to your computer and use it in GitHub Desktop.
PXE on OpenWrt with a different TFTP server

In this configuration, DHCP will run on the OpenWrt Box, while the TFTP server (the one serves the boot files) runs on a different computer.

1. Add to /etc/config/dhcp on OpenWrt Box

config boot linux
        option filename 'pxelinux.0'
        option serveraddress '192.168.?.?'
        option servername '?'

2. Restart DHCP server on OpenWrt Box

/etc/init.d/dnsmasq restart

3. Install TFTP server on another computer

apt install tftpd-hpa
# vi /etc/default/tftpd-hpa
# systemctl status tftpd-hpa
# systemctl restart tftpd-hpa

4. Test TFTP server (Optional)

  # cd /tmp
  # uname -a >/srv/tftp/test
  # tftp 192.168.0.2
  tftp> get test
  tftp> quit
  # diff test /srv/tftp/test
  (nothing, they are identical)

5. Download Ubuntu NetBoot

cd /srv/tftp
wget -r --no-parent --reject="index.html*"  "http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/"
mv archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/* .
ls
boot.img.gz  ldlinux.c32  mini.iso  netboot.tar.gz  pxelinux.0  pxelinux.cfg  ubuntu-installer  xen

6. Setup NFS server

sudo apt install nfs-kernel-server
echo "/srv/nfs 192.168.0.0/16(async,no_root_squash,no_subtree_check,ro)" >> /etc/exports
systemctl restart nfs-kernel-server.service

7. Mount ISO image

sudo mkdir /mnt/ubuntu_18_desktop_iso
sudo mount -o loop ubuntu-18.04.3-desktop-amd64.iso
ln -s /mnt/ubuntu_18_desktop_iso /srv/nfs/

8. Prepare Live Boot files

mkdir /srv/tftp/casper
cp /srv/nfs/casper/initrd /srv/tftp/casper
cp /srv/nfs/casper/vmlinuz /srv/tftp/casper

8. Append to /srv/tftp/ubuntu-installer/amd64/boot-screens

label ubuntudesktop
  menu label Ubuntu Desktop 18.04 Live
  kernel casper/vmlinuz 
  append nfsroot=192.168.x.x:/srv/nfs netboot=nfs boot=live boot=casper initrd=/casper/initrd systemd.mask=tmp.mount --

Reference:

  1. https://stelfox.net/blog/2013/12/configuring-pxe-booting-on-openwrt/
  2. TFTP boot, https://openwrt.org/docs/guide-user/base-system/dhcp_configuration
  3. https://wiki.debian.org/PXEBootInstall
  4. Another solution, https://forum.openwrt.org/t/solved-dhcp-config-pxe-boot-from-external-tftp-server/5880/2
  5. Openwrt doc, https://openwrt.org/docs/guide-user/base-system/dhcp
  6. Ubuntu Live PXE, http://c-nergy.be/blog/?p=13243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment