NFS root partition for Raspberry Pi

UPDATED on 12/04/2015 : added a way to get the offset and added -t ext4 option in mount command.

As stated in Raspberry Pi & SD card reliability, I had a try at using an NFS share as the root file system for one of my Raspberry Pi.

There is quite a lot of information on the subject on the net. But here is what I did.

Creating an NFS share

I own a Synology NAS. So I just created a shared folder and give permission to my Pi’s IP address. That is quite easy.

  • First enable NFS sharing if it is not already the case. Go to Control Panel > Win/Mac/NFS > NFS Service, tick Enable NFS and then apply
  • Then create an NFS share
    • Go to Control Panel > Shared Folders.
    • Create a new shared folder called piroot for instance
    • Click on Priviledges > NFS priviledges
    • Click create to add you Pi IP address (or a range if you prefer)

Copying proper files

Then, connect to you NAS using ssh for instance. Now you should have a new folder called /volume1/piroot on your NAS (/volume1 may be different on yours if you have several volumes.

I copied over an img file from raspberry.org and mounted the root fs included in the img file as a standard fs.

Took me a while to understand how to do it… To get the offset, you can use the command “file” but it is not available on the Synology. So I used Cygwin version of it on my Windows machine :

The offset to look at is the start sector of the second partition : 122880. And you need to multiply it by 512 (size of a sector in bytes) which gives 62914560. The other interesting stuff is partition ID : 0x83 which means ext4, thus the option -t ext4 in the following command.

Now, you just need to copy the files from the img file to your new NFS share, taking care of preserving permissions (-p option) !

Modifying fstab

You need to modify /etc/fstab on the Pi to remove the root fs entry. You will tell the kernel where is the root fs on its command line. If you keep this entry, Pi will not fully boot and it will complain about no being able to run fsck !

Preparing the SD card

Now we got our NFS share loaded with root fs files. Let’s configure the Pi boot. After dumping the raspbian OS to an SD card (I am on Windows so I use Win32DiskImager to to do that.) You then need to modify the cmdline.txt at the root of the SD card. Mine look like that :

Note that I removed all references to serial port which is by default used for connecting a debug console.

I did this because I need it for other stuff (Pi will be used for an emoncms server.) This is not mandatory for NFS to work.

The following entries are mandatory :

  • root=/dev/nfs : tells the Pi that the root fs will be on NFS
  • nfsroot=ip:/whatever/dir,udp,vers=3 tells Pi where is the root fs to be mounted
  • ip=dhcp : startup IP stack because you need it for NFS (I use DHCP but you could used a fixed IP.) If using a local fs, fs is mounted prior starting up the IP stack.
  • rootfstype=nfs : tells that the fs type is nfs

PXE…

By the way, no, you just can’t use PXE boot. The Pi doesn’t support it. The ONLY viable boot device is the SD card.

References

Here is a list of links that point to sources I used :

Leave a Reply

Your email address will not be published.