# Embedded Linux TFTP and NFS Boot

The following is a rough guide for booting embedded Linux over the network (using TFTP and NFS). This assumes the host/server machine is running Debian or Ubuntu.

## Packages

• tftpd-hpa
• isc-dhcp-server
• nfs-kernel-server

## TFTP

The TFTP server does not require much configuration. By default it runs on port 69 and serves out of either /var/lib/tftpboot or /srv/tftp (depending on the Linux distribution). These settings can be changed by modifying /etc/default/tftpd-hpa.

Ensure the server is running with

systemctl start tftpd-hpa


If the host PC has a running firewall, ensure port 69 is open.

The TFTP directory should have all of the files necessary to boot, e.g.

• Image
• image.ub
• system.dtb
• pxelinux.cfg/default

The exact files needed depends on the system and the configuration of U-Boot. For more info see U-Boot Distro Boot.

## DHCP

A DHCP server can be used to simplify managing IP addresses for the board. This is not strictly necessary; the alternative is hard-coding a static IP for the board in U-Boot.

Install isc-dhcp-server and modify /etc/dhcp/dhcpd.conf to add

subnet 10.0.10.0 netmask 255.255.255.0 {
range dynamic-bootp 10.0.10.10 10.0.10.20;
option routers 10.0.10.1;
}


The configuration above assumes that the network interface on the server that connects to the board has IP address 10.0.10.1. Modify the snippet above appropriately if the IP address is different.

Start the DHCP server with

systemctl start isc-dhcp-server


## NFS

Create an NFS root directory (e.g. /srv/nfs) with a root filesystem. Given a compressed rootfs tarball (e.g. rootfs.tar.gz from PetaLinux), extract it to the desired directory with

tar -C /srv/nfs -xf rootfs.tar.gz


Modify the /etc/exports file and add the following:

/srv/nfs        10.0.10.0/24(rw,sync,no_subtree_check,no_root_squash)


Run

exportfs -ar


and then (re)start the NFS server:

systemctl restart nfs-server


Ensure the kernel bootargs contains the following:

root=/dev/nfs nfsroot=10.0.10.1:/srv/nfs,tcp ip=dhcp


Again, 10.0.10.1 is the IP address of the NFS server. Update this to whatever IP address you are using. ip=dhcp will only work if a DHCP server is installed; if not, you'll need to manually specify the IP address.

NOTE: In some cases, it might be necessary to add nfsvers=3 to the kernel bootargs, i.e.

root=/dev/nfs rootfstype=nfs nfsroot=10.0.10.1:/srv/nfs,tcp,nfsvers=3 ip=dhcp


You will also need to make sure the following config options are enabled in the Linux kernel:

• CONFIG_NFS_FS
• CONFIG_NFS_V2
• CONFIG_NFS_V3
• CONFIG_NFS_V4
• CONFIG_ROOT_NFS
• CONFIG_IP_PNP
• CONFIG_IP_PNP_DHCP
• CONFIG_IP_PNP_BOOTP
• CONFIG_IP_PNP_RARP

NFS is enabled in your Linux kernel configuration; however, this is enabled by default so you shouldn't need to modify it unless you've already changed it before.