Table of Contents

This is part 8 of the series Embedded Linux with Raspberry Pi 3 Model B. Please check earlier articles to get the grasp of current one.

Introduction

In the earlier articles, we have seen how to cross compile Linux kernel, load it from the tftp server and how to generate the root filesystem using busybox.

In this article, we will make Linux kernel boots that root filesystem over network. The root filesystem which we generated through busybox on a development system can be accessed by Raspberry Pi 3B through the network using NFS.

The reason behind booting the Raspberry Pi 3B over NFS is to eliminate the process of copying the modified files or kernel to the SD card for every single change we made.

Network boot your Raspberry Pi 3B
Network boot your Raspberry Pi 3B

Setting NFS server on host system

Install the nfs-kernel-server package on you Ubuntu development system by running following command.

sudo apt install nfs-kernel-server

Once installation is completed, add the following line to /etc/exports file.

<path_to_busybox_install_directory> <ip_address_of_board>(rw,no_root_squash,no_subtree_check)

If you follow the root filesystem generation using busybox, we have installed the root filesystem in the path ~/rpi3/nfs. Replace <path_to_busybox_install_directory> with the absolute path of the root filesystem and replace <ip_address_of_board> with the IP address of the Raspberry Pi 3B which we set during tftp communication establishment. An example is given below.

/home/nayab/rpi3/nfs 192.168.1.115(rw,no_root_squash,no_subtree_check)

Restart the NFS server

Run the following command to restart NFS server on your host system.

sudo service nfs-kernel-server restart

Set bootargs env in the board U-boot console

Power up the board, stop in U-boot console and set the bootargs env using following command. The bootargs value is what will be passed as command line arguments to Linux kernel while booting.

setenv bootargs # Reset bootargs
setenv bootargs root=/dev/nfs ip=<board_ip>:::::eth0 nfsroot=<host_ip>:<path_to_busybox_on_host>,nfsvers=3 rw
saveenv

An example is given below -

setenv bootargs # Reset bootargs
setenv bootargs root=/dev/nfs ip=192.168.1.115:::::eth0 nfsroot=192.168.1.15:/home/nayab/rpi3/nfs,nfsvers=3 rw
saveenv

Booting the RPI through NFS

Make sure the Raspberry Pi is connected through Ethernet to the system in which the nfs-kernel-server is running.

Power on the board or run reset command in the U-boot console. The board must be downloading Linux kernel and dtb file from tftp server and then Linux kernel should boot the root filesystem over NFS.

If you see the following logs flooding your screen, create a dev directory in the NFS path. Run mkdir -p ~/rpi3/nfs/dev command and reboot your board.

can't open /dev/tty2: No such file or directory
can't open /dev/tty3: No such file or directory
can't open /dev/tty4: No such file or directory
can't open /dev/tty2: No such file or directory
can't open /dev/tty3: No such file or directory
can't open /dev/tty4: No such file or directory
can't open /dev/tty2: No such file or directory
can't open /dev/tty3: No such file or directory
can't open /dev/tty4: No such file or directory
.
.
.

At this stage, you should be able to execute commands like ls, mkdir etc..