How to Build a TFTP Server on a Raspberry Pi

The next piece of the puzzle for our Raspberry PXE boot environment is a TFTP server. In the last post, we set up an NFS server for the bulk of the OS files. In this post, we need to really dumb it down to brass tacks. We need to share files across the network, without authorization, in small packets, and over UDP. This is the same scenario in which we would do firmware upgrades to network devices or backing up network devices. Real low-level stuff. Let’s get started!

First, we’ll go back to the NFS server we set up last time and install some more software:

apt install tftpd-hpa

So, the server package installs, immediately tries to load, and fails! UGH! Don’t worry. We can fix it! Edit the config file:


TFTP_OPTIONS=”–ipv4 –secure –create”

Create the shared directory:

root@boots:/data1# mkdir /data1/boot
root@boots:/data1# chown tftp:tftp /data1/boot

and restart the server:

sudo /etc/init.d/tftpd-hpa restart

Kinda weird that it failed on it’s first boot. Let’s double-check that the service is actually running this time:

root@boots:/data1# /etc/init.d/tftpd-hpa restart
Restarting tftpd-hpa (via systemctl): tftpd-hpa.service.
root@boots:/data1# systemctl status tftpd-hpa
● tftpd-hpa.service - LSB: HPA's tftp server
     Loaded: loaded (/etc/init.d/tftpd-hpa; generated)
     Active: active (running) since Sun 2022-03-27 07:14:10 EDT; 15s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 1236 ExecStart=/etc/init.d/tftpd-hpa start (code=exited, status=0/SUCCESS)
      Tasks: 1 (limit: 4164)
        CPU: 27ms
     CGroup: /system.slice/tftpd-hpa.service
             └─1244 /usr/sbin/in.tftpd --listen --user tftp --address :69 --ipv4 --secure --create /data1/boot

Mar 27 07:14:10 boots systemd[1]: Starting LSB: HPA's tftp server...
Mar 27 07:14:10 boots tftpd-hpa[1236]: Starting HPA's tftpd: in.tftpd.
Mar 27 07:14:10 boots systemd[1]: Started LSB: HPA's tftp server.

AH! That tastes better! We can see our new options are in effect too! Let’s go to another Raspberry and give the service a test. Create a little file and see if you can send and receive:

root@node01:~# vi words.txt
root@node01:~# tftp boots

tftp> put words.txt
Sent 36 bytes in 0.0 seconds

tftp> get words.txt
Received 36 bytes in 0.0 seconds
tftp> quit

Looks like a winner! Let’s set this up to restart at boot:

root@boots:/data1#  systemctl is-enabled tftpd-hpa
tftpd-hpa.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install is-enabled tftpd-hpa

Alright! Moving on! We’re going to have a PXE environment before we’re done!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.