JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Sun Apr 05, 2020 8:16 pm

I will attempt to describe here what I did to create an NFS served root filesystem on a Pi Zero W.

This description is based on a raspbian buster installation. Other versions may require a different approach.

I first tried using the built-in wifi controller, but that didn't work because while it configured and turned on the wifi
adapter, some process within it caused the controller to disconnect which cause the NFS mount to fail.

I performed this process on the Pi Zero W itself which I would suggest to others.

I began by using NOOBS to put a system on a 16G SD card. I first added a USB Ethernet adapter. I got that working and
did the updates and installed a few things I like to have handy.

This was the base of what I needed.

You will want to be the root user for this procedure.

The work done here will be in /etc/initramfs-tools

Create a script /etc/initramfs-tools/hooks/nfsroot

The contents are:

Code: Select all

#!/bin/sh
PREREQ=""

prereqs()
{
  echo "$PREREQ"
}

case $1 in
prereqs)
  prereqs
  exit 0
  ;;
esac

. /usr/share/initramfs-tools/hook-functions

copy_exec /bin/grep /bin
copy_exec /sbin/lsmod /sbin
copy_exec /sbin/ifconfig /sbin
copy_exec /sbin/ifup /sbin

cp /lib/firmware/brcm/brcmfmac43430-sdio.txt ${DESTDIR}/lib/firmware/brcm
Note that the wpa_supplicant copy is commented. That can be deleted as it was legacy code from an attempt to use wifi.

Make sure to set the executable permissions with chmod.

Create another script /etc/initramfs-tools/scripts/nfs-top/ethernet

It doesn't matter what you call the script as long as it exists in /etc/initramfs-tools/scripts/nfs-top. Mine is called
"wifi" because it is from my wifi attempt. I will update that later. And also set execute permissions.

The file's content is:

Code: Select all

#!/bin/sh
PREREQ="udev"

prereqs()
{
        echo "$PREREQ"
}

case $1 in
prereqs)
        prereqs
        exit 0
        ;;
esac

if grep -q splash /proc/cmdline; then
    /bin/chvt 1
fi
sleep 3

if grep -q splash /proc/cmdline; then
       /sbin/usplash -c &
       sleep 1
fi

/sbin/ifup eth0=config1

ifconfig eth0 up
Edit the file /etc/initramfs-tools/modules

Add these lines:

Code: Select all

brcmfmac
brcmutil
cfg80211
rfkill
Those are required for all installations.

This is where you need to find the driver modules used for your USB ethernet adapter.

In my case, they are "asix" and "phylib". I believe that asix is for my device and phylib is used for all, but don't take
that as gospel.

The modules file tells the kernel what modules to load.

Edit the file /etc/initramfs-tools/initramfs.conf

The contents should look like this:

Code: Select all

#
# initramfs.conf
# Configuration file for mkinitramfs(8). See initramfs.conf(5).
#
# Note that configuration options from this file can be overridden
# by config files in the /etc/initramfs-tools/conf.d directory.

#
# MODULES: [ most | netboot | dep | list ]
#
# most - Add most filesystem and all harddrive drivers.
#
# dep - Try and guess which modules to load.
#
# netboot - Add the base modules, network modules, but skip block devices.
#
# list - Only include modules from the 'additional modules' list
#

MODULES=netboot
BOOT=nfs

#
# BUSYBOX: [ y | n | auto ]
#
# Use busybox shell and utilities.  If set to n, klibc utilities will be used.
# If set to auto (or unset), busybox will be used if installed and klibc will
# be used otherwise.
#

BUSYBOX=auto

#
# KEYMAP: [ y | n ]
#
# Load a keymap during the initramfs stage.
#

KEYMAP=n

#
# COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz ]
#

COMPRESS=gzip

#
# NFS Section of the config.
#

#
# DEVICE: ...
#
# Specify a specific network interface, like eth0
# Overridden by optional ip= or BOOTIF= bootarg
#

DEVICE=eth0
IP=192.168.0.97:192.168.0.100:255.255.255.0::eth0

#
# NFSROOT: [ auto | HOST:MOUNT ]
#

NFSROOT=auto

#
# RUNSIZE: ...
#
# The size of the /run tmpfs mount point, like 256M or 10%
# Overridden by optional initramfs.runsize= bootarg
#

RUNSIZE=10%
Please note that in this file you find IP address configuration data. THIS IS FOR MY SYSTEM and is here for example
purposes only. The IP= line is constructed as follows:

Code: Select all

IP=<pizero_IPstaticaddress>:<gateway>:<optional-hostname>:<name of interface>
Note also that there are two additional files that contain device IP address information that you will need to replace
with data that matches your network.

Once these files are in place you need to build the initramfs into a file that will be used at boot time.

Code: Select all

update-initramfs -c -k $(uname -r)
If something fails and it needs to be rerun, use this:

Code: Select all

update-initramfs -u -k $(uname -r)
It will display the name and location of the created file in /boot. You need the name of the file without /boot/ for
a line you will add to config.txt.

That line should be:

Code: Select all

initramfs <the name of your file>

Here are two scripts you will need for the next part:

edit_initramfs:

Code: Select all

#!/bin/bash
[[ ! -d /tmp/initramfs ]] && {  mkdir /tmp/initramfs || { echo "ERROR:  Cannot create /tmp/initramfs"; exit 1; } }
cd /tmp/initramfs || { echo "ERROR:  Cannot change to /tmp/initramfs"; exit 1; }
zcat /boot/initrd.img-$(uname -r) | sudo cpio -idmv
if [ $? = 0 ]
  then echo "SUCCESSS:  Unpacking Successful";
  else echo "ERROR:  Unpacking Failed!";
fi

pack_initramfs:

Code: Select all

#!/bin/bash
cd /tmp/initramfs || exit 1
[[ ! -x init ]] && { echo "ERROR:  Missing init! init wasn't found or isn't executable"; exit 1; }
[[ ! -x bin/busybox ]] && { echo "ERROR:  Missing busybox!"; exit 1; }
find . | cpio -oH newc | gzip -9 | sudo tee /boot/initrd.img-$(uname -r) > /dev/null
Make sure to set the execute permission bits on these.

Now execute edit_initramfs.

This will decompress the initramfs structure into /tmp/initramfs

These commands set up a subdirectory for /etc/network/interfaces in the initramfs needed for network configuration.

Code: Select all

cd /tmp/initramfs/etc
mkdir network
cd network
The interfaces file contains commands and data for setting up the USB/ethernet adapter. Create a text file called "interfaces" in the network subdirectory and place the following contents therein:

Code: Select all

auto lo
iface lo inet loopback

iface config1 inet static
   address 192.168.0.97
   netmask 255.255.255.0
   gateway 192.168.0.100
   dns-nameservers 192.168.0.25 70.47.70.47
   dns-domain lan
[code]

Note that again, this is an example and you must replace my numbers with ones that work for your network.

Now you need to recompress the initramfs file.  Do this with:

[code]pack_initramfs
Take heart, we're almost done.

You already edited the config.txt file to include the initramfs command. Now you need to modify the cmdline.txt.

I'm posting the contents of my file with the caveat that you need to edit the data to match your network.

cmdline.txt:

Code: Select all

console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=192.168.0.25:/sdc1/pi0b_fs,tcp rw ip=192.168.0.97:192.168.0.25:192.168.0.100:255.255.255.0:rpt:eth0:off rootfstype=nfs elevator=deadline fsck.repair=yes rootwait plymouth.ignore-serial-consoles net.ifnames=0
The nfsroot= parameter sets the IP address of your NFS server and the location of the filesystem copy on your NFS server.
The ip= parameter is structured as:
ip=<piZeroIPaddress>:<nfs_server_IPaddress>:<gateway_IPaddress>:<netmask>:rpt:<ethernet device>:off

I don't know what rpt and off do.

The last thing you need is a copy of your Raspbian on the NFS server in the location pointed to by the cmdline.txt line.

I did this by removing the SD card, placing it in a reader and plugging that into a pi4, mounting partition 7 to /mnt and then tar that to a server location. Afterward, I tar -xf the file into the location where I want it. There are other ways to do this, tar is just the method I know and trust.

You may need to alter your fstab to accomodate the new filesystem.

Here is mine and again, it is just an example for guiding you in editing your own:

Code: Select all

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p6  /boot           vfat    defaults          0       2
#/dev/mmcblk0p7  /               ext4    defaults,noatime  0       1
192.168.0.25:/sdc1/pi0b_fs /        nfs4 rw,auto,nolock,x-systemd.automount 0 0

192.168.0.25:/share   /pi4b.share   nfs4 rw,auto,nolock,x-systemd.automount 0 0
192.168.0.25:/sda2    /pi4b.sda2    nfs4 rw,auto,nolock,x-systemd.automount 0 0
192.168.0.25:/sdc1    /pi4b.sdc1    nfs4 rw,auto,nolock,x-systemd.automount 0 0
192.168.0.25:/archive /pi4b.archive nfs4 rw,auto,nolock,x-systemd.automount 0 0
Note that the SD card root is commented and a NFS mount line with mountpoint / exists instead.

Edit the NFS server copy of fstab like the above. Do not edit the fstab on the SD card.

I use a Raspberry Pi 4 (with HDDs) as my NFS server. It's faster than one might think. The first NFS mount line mounts the root file system to /. The rest mount different shares.
Last edited by JovianPyx on Mon Apr 06, 2020 2:36 am, edited 4 times in total.

User avatar
dickon
Posts: 1819
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Raspberry Pi Zero W boot with NFS root filesystem

Sun Apr 05, 2020 9:06 pm

You shouldn't need 'followkernel' on the initramfs line, I think. I believe that's for the concatenate-initrd-to-kernel feature that you need on some kernels, or where the bootloader can't pass the addresses of the initramfs via the dtb (or ATAGS, if legacy). Certainly I've never needed to use it.

Does 'ip=dhcp' not work? Do you really need to specify the whole thing, or can a properly-configured dhcpd supply the right answers, as for wired?

Genuine questions -- I'm about to need this tomorrow, to monitor the internal temperature of my fridge, which I discovered at ~10 deg. C earlier; not good when I'm trying to avoid shopping more than once a week, and food preservation is a critical component of that...

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Sun Apr 05, 2020 9:17 pm

I was able to get DHCP to work for wifi (yes, that is the simple "pi=dhcp"), but while I saw that it got an IP address, something was disabling it and I gave up on wifi.

As I thought about it, I will most often use this machine via an ssh terminal connection and not the GUI very much. As such, it is convenient to have a static IP address. I use my router for a DHCP server, but it doesn't have the capacity to serve static addresses to certain devices. That is why I do static and why I do it as described. So once I started with ethernet, I didn't try DHCP.

As for followkernel, that was part of the description for doing this I found on the web (url is in a previous post). I confess I don't know exactly what it does, but it doesn't seem to interfere with anything.

Regarding specifying the whole data string, I believe it is required for each instance. What I don't know is if some instance or other is not required. I believe the one in cmdline.txt is required, but one of the others in the setup for initramfs might be superfluous. However, I must say that this takes long enough to edit and reboot and then fix if I broke it, that at this point I'm a bit weary and well, it works, so I'm not complaining. :mrgreen: :mrgreen: :mrgreen:

User avatar
dickon
Posts: 1819
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Raspberry Pi Zero W boot with NFS root filesystem

Sun Apr 05, 2020 9:49 pm

Ah. I run ISC's dhcpd on my router, which lets me set static addresses and other options for specific hosts, so I'll probably just do that as usual. I'll also probably override all the OS networking guff again, as I frankly don't trust systemd not to break things royally; it usually does.

As for followkernel: far back in the mists of ancient time, bootloaders didn't always have the capability to specify the addresses of the initramfs via ATAGS (a sort of half-way house between a BIOS ACPI table and a DTB). To solve this, the kernel has a slightly dodgy option to concatenate an initrd -- and latterly a DTB too, for the same reason -- directly to the end of the image: you literally run

Code: Select all

cat initrd.gz >> arch/arm/boot/zImage
and get the bootloader to load the whole, single blob into RAM and run it. It's messy for several reasons: there's no guarantee that what's immediately after the kernel in a warm boot won't *look* like an initrd, and, as I've been caught out before, if you're making a uImage, you need to make a zImage, then do the cat, then make the uImage, then boot that. If you're not careful, you'll end up making changes to your initrd, recatting that to the end of the zImage, making the uImage, but unless you've deleted the zImage, you'll just add another initrd to the end of the thing each time, and the kernel will just use the first. It's quite frustrating...

I *assume* that 'followkernel' is designed to handle this, from a bootloader's point of view. It is easier, particularly on bare-metal systems, as you won't need a DTB parser. But the Pi's bootloader is very well-featured, and is rather good at handling DTBs, so is quite capable of putting the initramfs start and end addresses into the /chosen node as usual, and probably worth using that with a proper kernel.

Finally, the 'ip=' stanza in the command line is documented in Documentation/filesystems/nfs/nfsroot.txt in any given kernel source tree. You've configured the hostname to 'rpt' and turned off all autoconfiguration, which seems fair enough.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Sun Apr 05, 2020 10:34 pm

Thanks for the followkernel history. Sounds like I don't indeed need it.

Once I've rested from this ordeal (20 hours of trying things moving the SD card back and forth between an adapter and the Pi Zero W), I'll remove that and test it.

I also see that the wpa_supplicant is running, and I may have left something in the configuration about that. It's not a big deal, but if it's not used, there's no sense for it to run. I know that the wpa_supplicant is copied to the initramfs, but there may be something else in the config that's starting it. I want to remove the copy at least, that may be all it needs though that may generate an error in boot.log.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 06, 2020 12:39 am

I've done some changes, rebuilt and everything works. This includes removal of the followkernel parameter.

I've renamed my nfs-top script from wifi to ethernet. I removed the wpa_supplicant copy code and now I see that wlan0 is discovered, but the wpa_supplicant messages are still in /var/log/boot.log.

I've turned wifi and bluetooth off in config.txt. I no longer see references to wlan0, but there is a message about a successful start of wpa_supplicant. Killing the process seems to have no ill effect. I searched initramfs and there are no files that have a reference to wpa_supplicant, so something outside of initramfs is starting it. For now, it suffices to kill the wpa_supplicant process in rc.local.

DarkElvenAngel
Posts: 1062
Joined: Tue Mar 20, 2018 9:53 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 06, 2020 11:40 am

That's a tricky one to find if you don't know where to look.

Code: Select all

/lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 06, 2020 1:24 pm

DarkElvenAngel wrote:
Mon Apr 06, 2020 11:40 am
That's a tricky one to find if you don't know where to look.

Code: Select all

/lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant
Would the suggestion to prevent the starting of wpa_supplicant be to remove this file from initramfs?

DarkElvenAngel
Posts: 1062
Joined: Tue Mar 20, 2018 9:53 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 06, 2020 1:42 pm

JovianPyx wrote:
Mon Apr 06, 2020 1:24 pm
DarkElvenAngel wrote:
Mon Apr 06, 2020 11:40 am
That's a tricky one to find if you don't know where to look.

Code: Select all

/lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant
Would the suggestion to prevent the starting of wpa_supplicant be to remove this file from initramfs?
This would be in the rootfs are you sure it's starting in the initramfs? If you removed wpa_supplicant it should show an error

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 06, 2020 3:23 pm

grepping /var/log/boot.log (which I delete before I test) shows that the supplicant starts and there are no error messages, so it must be somewhere other than initramfs. I really don't want to remove that file from the SD card in case I want to reverse the wifi thing. And I've used rc.local to kill it so it doesn't use any resources.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 06, 2020 3:28 pm

It just occurred to me that if wpa_supplicant is starting by something other than within initramfs then perhaps the supplicant shouldn't be started in initramfs and it may be possible to get wifi working as a method for NFS root filesystem.

I think I will generate another SD card and try again on another Pi Zero W board (I have a total of 3)

User avatar
dickon
Posts: 1819
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 06, 2020 3:37 pm

You should be able to do it with iwconfig, which won't persist. I'd stick a script in nfs-top or similar.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Tue Apr 07, 2020 1:36 am

I now have wifi based NFS root filesystem running. I am currently using DHCP for wlan0 configuration. Definitely slower than using USB/ethernet, but it is working.

I followed the original instructions from the website I found (url posted earlier in this thread) and the only thing I changed was to add

Code: Select all

net.ifnames=0
at the end of cmdline.txt. That stops the renaming of the interfaces which was causing the ethernet method to fail.

It was funny because I have the GUI enabled and the script gets to the point where it starts the GUI and the screen goes black - for a long time - and I thought it was dead - but then the mouse pointer appeared and I realized that it was actually running though very slowly. Once the GUI is running it becomes more responsive, but it is still sluggish compared to wired ethernet. I want to use this with a camera (should be here in a few days) which doesn't need the GUI to take pictures, so I'll turn off the GUI and use it headless via ssh.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Tue Apr 07, 2020 3:15 am

I notice that it doesn't reboot all the way using NFS filesystem over wifi. It begins the shutdown procedure, but once it disconnects wlan0 (there is a message to that effect) it gets stuck, probably wanting something on the filesystem.

I live in a residential area with lots of wifi access points. What I've noticed is that during boot, there are messages about not being able to talk to the NFS server and others that indicate the connection works. Then well after boot, the connection can fail. If that happens during boot, it can hang in progress. For my needs it doesn't look all that reliable as well as being slow. I would want something solidly reliable for a filesystem connection and wifi can be interrupted or degraded for reasons external to my control.

IMO, the USB/Ethernet method is far superior. It's fast enough that I can use the GUI. I suspect it's filesystem transfer rate is higher for ethernet than SD card, but will test that. Several times it has hung during the GUI startup, but it will eventually always hang.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Tue Apr 07, 2020 8:35 pm

Zero problems with the eth0 setup. It runs constantly and has never crashed nor had any problems.

Speed-wise, it seems not much different from an SD card installation. Small files read a bit faster from SD card, large files read a bit faster from ethernet. ethernet writes slightly faster. This is just some quickie crude testing I wrote so YMMV. It also "feels" about the same when using the GUI.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Sun Apr 19, 2020 3:50 am

I've tried again to get NFS root filesystem over wifi and it is working.

I didn't keep the last attempt, so I can't say if I made some error or if it was just a bad wifi day.

What I can say is that I followed the instructions precisely and it is working reliably with a DHCP served IP address. I want this to be static IP so that it's easier to ssh.

ejolson
Posts: 6032
Joined: Tue Mar 18, 2014 11:47 am

Re: Raspberry Pi Zero W boot with NFS root filesystem

Sun Apr 19, 2020 4:29 am

JovianPyx wrote:
Sun Apr 19, 2020 3:50 am
I've tried again to get NFS root filesystem over wifi and it is working.

I didn't keep the last attempt, so I can't say if I made some error or if it was just a bad wifi day.

What I can say is that I followed the instructions precisely and it is working reliably with a DHCP served IP address. I want this to be static IP so that it's easier to ssh.
It's good to know that those instructions really work. Thanks for the follow up.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Sun Apr 19, 2020 5:00 pm

You're very welcome. I do try to come back to threads like this when I have success in which others might have interest. It is actually a bit too rare to find complete detailed instructions for things like this.

The system, which is entirely headless, takes about 4 minutes to boot here. For a turnkey type system, this is not a big deal, turn it on and let it work. During troubleshooting, I got tired of checking the /var/log/boot.log (from the NFS server) to see when it has finished booting, so I put an LED on the board and it gets turned on when the auto-login user gets logged in.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 20, 2020 6:20 pm

I've now used the same procedure to modify a Raspbian Lite image installation. No changes were necessary.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 20, 2020 9:02 pm

The Raspbian Lite image works very nicely. It boots faster than the full NOOBS, in about one minute and 45 seconds (with lighttpd installed, configured and enabled). One thing to be aware of is that installation of new software can take a long time. The first time I tried to install wiringPi I power cycled because I thought it was hung. In fact, it just took a long time. Same with lighttpd, but I already knew to just wait.

User avatar
dickon
Posts: 1819
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 20, 2020 9:38 pm

If your underlying filesystem -- ie, on the fileserver -- can be snapshotted, and you snapshot before you start installing or upgrading anything, then have a look at eatmydata. eatmydata does what it says on the tin -- eats your data -- when things go catastrophically wrong (due to power failures, usually), but makes tools like apt vastly quicker to run over NFS (or even legacy, non-SSD HDs) by replacing all the sync() / fsync() / O_SYNC / whatnot calls and flags into noops.

It's very, very capable of reducing a functional system into a mush of errors, but if that happens you can rollback to the snapshot you took before doing the damage and try again. I use it a lot on my NFS-backed Pis for this reason.

DO NOT -- *EVER* -- use it on a live system you care about without a recovery mechanism. Ever. But it's very good at speeding things up if you have one.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Mon Apr 20, 2020 11:46 pm

Thanks for that, interesting piece of software.

At present, the only system this affects is this one with the wifi NFS root filesystem. The ethernet NFS root filesystem did not have this slowness when apt-get was used.

The only time I notice a slowness is when I use apt-get on the wifi-NFS system, but I don't notice a slowness at other times such as access to lighttpd.

I'm about to receive a camera for the system and then I can test the system's usefulness under actual use. The idea is a camera that peers out a window at my front porch. lighttpd will be used to present images to a browser. If the performance of that is unacceptable, I will consider eatmydata.

User avatar
dickon
Posts: 1819
Joined: Sun Dec 09, 2012 3:54 pm
Location: Home, just outside Reading

Re: Raspberry Pi Zero W boot with NFS root filesystem

Tue Apr 21, 2020 8:32 am

Anything synchronous and transactional -- such as apt and sync files to disc -- is very, very sensitive to round trip times, and wifi is surprisingly slow at that. It's the long fat pipe problem. Shunting images around should be fine, as you're not waiting for the previous one to be confirmed to have been delivered before starting on the next.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Thu Apr 23, 2020 3:40 pm

One thing I did that is a likely reason for the wifi success is adding:

Code: Select all

net.ifnames=0
to the line in cmdline.txt. This turns off the renaming of network interfaces. I've no idea why the boot process needs to rename net interfaces, but I saw it happen when I worked on the ethernet version of this.

That was the first version of this that I got working. I then started to include it in all of my cmdline.txt files for NFS root file system with no apparent problems.

I remember the first wifi attempts were grabbing an IP address and then disconnecting. Sometimes it would connect to the NFS server and then disconnect. I've not seen those messages again in any of the attempts I've made since including that parameter.

JovianPyx
Posts: 132
Joined: Fri Nov 20, 2015 9:34 pm

Re: Raspberry Pi Zero W boot with NFS root filesystem

Sat May 16, 2020 9:22 pm

As an addendum, I'll add that using WiFi as a medium for NFS root file system is not at all optimal. Just connecting to mount the root filesystem often fails with a kernel panic because it took too long. When it connects, it can take 4.5 minutes to finish booting. I found this to be less problematic when using a static IP address (in cmdline.txt) instead of using DHCP (even if DHCP serves a static address). This may be a function of the DHCP server in my router, so YMMV.

Once connected, performance is highly variable. I have lighttpd running to serve a camera image. I don't yet have the camera, so I'm serving an image of my dog. Rarely, when I contact to the server, it responds immediately. Usually It causes a browser timeout. It can take several retries to get the image. I've also set up an Ethernet version of the same thing, using NFS to serve the root filesystem, but it's response is always fast. Unfortunately, the place I wish to use the camer/pi zero w is at the other end of the house where I have no LAN wiring. Oddly, if I have the pi zero w ping the workstation that would be accessing lighttpd, it seems to connect right away. I set the ping command to ping once every 10 seconds. A cheesy solution to be sure. I have a third Pi Zero W that I've given a USB hard drive for it's file system. This system also suffers the same lighttpd performance problem and it also connects to the LAN via WiFi.

It may be better for me to have the Pi Zero W transfer the image data regularly back to my main server. It may be delayed, but it should get there.

It seems that adding a small RAM disk helps. Currently, 32 megs seems to do what I need and it's not a burden to the pi.
Last edited by JovianPyx on Sat May 16, 2020 9:54 pm, edited 1 time in total.

Return to “Advanced users”