Embedded Linux TFTP and NFS Boot

Tags: linux petalinux u-boot tftp nfs

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

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.

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:

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.