Skip to content

Instantly share code, notes, and snippets.

@rikka0w0
Last active September 13, 2024 17:58
Show Gist options
  • Save rikka0w0/4c4caac493ce682cbed9ba3e928693d5 to your computer and use it in GitHub Desktop.
Save rikka0w0/4c4caac493ce682cbed9ba3e928693d5 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)

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

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/

Add a Ubuntu LiveCD entry

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

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

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

Replace default install with default live, delete menu default under label install. This only controls which menu item is selected by default.

10. Add timeout to the boot menu

In /srv/tftp/pxelinux.cfg/default (NOT /srv/tftp/ubuntu-installer/amd64/pxelinux.cfg/default), replace timeout 0 with:

timeout 50
ONTIMEOUT live

This controls the timeout action.

Restart NFS / TFTP server:

systemctl restart nfs-kernel-server
systemctl restart tftpd-hpa.service

Delete these files to save some space

rm -rf boot.img.gz netboot.tar.gz xen

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