• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

• Buried in cloud files? We can help with Spring cleaning!

Whether you use Dropbox, Drive, G-Suite, OneDrive, Gmail, Slack, Notion, or all of the above, Dokkio will organize your files for you. Try Dokkio (from the makers of PBworks) for free today.

• Dokkio (from the makers of PBworks) was #2 on Product Hunt! Check out what people are saying by clicking here.

View

WGT634U_wireless_NFS_root

last edited by 16 years, 2 months ago

WGT634U_wireless_NFS_root

WORK IN PROGRESS

NFS (over wireless) pivot_root for WGT634U and OpenWrt (Kamikaze).

NOTE: This assumes that WPA will be used. Don't implement an NFS root unless you are on a secure network (i.e. using WPA). Open and shared key WEP are not secure networks.

The general idea is flash the wgt634u with a squashfs based image that has the requisite kernel modules to initiate a client connection (with WPA) to a remote AP, use dhcp to fetch an IP address, then to mount an NFS partition. That NFS parition, through a pivot_root call, will become the new NFS root for the device. I take /tmp out of RAM (I opt for RAM, not for fast /tmp). /etc/inittab is altered to run /etc/init.d/rcK which syncs the NFS filesystems before rebooting. Flash is not written to during normal operation, under this paradigm. One trick is that wpa_client wants a writable filesystem for its control files. To accomplish this, a tmpfs filesystem (mounted on /wpa ) is created that is just large enough to hold these files. This is similar in spirit to dacb's WGT634U_USB_root HOW_TO approach. The methods for configuring wireless in WPA client mode is taken from ClientMode (Managed Mode) with WPA-Supplicant.

This has been tested on: OpenWrt (Kamikaze) release 3535

• Get fresh source, e.g. to fetch release 3535:

• Configure source tree for WGT634U w/ minimal modules for Atheros wifi and NFS filesystems:

cd trunk/openwrt

• Select '*' (not "M!") for the following items:

        Target System (Broadcom BCM47xx/53xx [2.6])
OpenWrt Package Selection  --->
Networking  --->
wpa_supplicant  # required for WPA client mode
Kernel Configuration / Device Support  --->
Filesystems support  --->
kmod-fs-nfs     # required to mount NFS


BUSYBOX_CONFIG_NFSMOUNT


to

BUSYBOX_CONFIG_FEATURE_MOUNT_NFS


Note: you will have to reapply this change .config everytime you do a make menuconfig. There is probably a way to make this more permanent.

You can check if you did this correctly (after the make below), by making sure your bb_config.h file has the right lines:

grep NFS build_mipsel/busybox-1.1.0/include/bb_config.h
#define CONFIG_FEATURE_MOUNT_NFS 1
#define ENABLE_FEATURE_MOUNT_NFS 1


• Build it all with:

make

• Install the squashfs image in bin. For 3535 it is openwrt-wgt634u-2.6-squashfs.bin in the bin directory. I did it via CFE and a serial console. Like so (your hwaddr, ipaddr, etc. will differ as will the bytes read and written - see the WGT634U hardware page at openwrt.org):

CFE> ifconfig eth0 -auto

gateway 192.168.0.1, nameserver 69.69.69.69, domain foo.bar.

*** command status = 0

Programming...done. 1806336 bytes written

*** command status = 0

• Read this entire step before doing anything At this point, you will need to make a root filesystem for your device on your NFS server. One excellent way to do this is:
1. Reboot the unit. It will boot kernel from flash and root from squashfs. Then it will run firstboot and create a complete jffs filesystem in flash for 'permanent storage'.
2. Copy the requisite directories from the newly created jffs filesystem device's flash to the NFS server. The 'requisite' directories are those found in WGT634U_USB_root HOW-TO (search for the text 'Now you need to copy' and perform that step - replacing the word usb w/ nfs). This will require you to connect to your wireless network as a client in WPA mode (or via a wired connection) and to mount your NFS server from the device.
• KEEP READING Doing both of these now is good for testing your NFS server configuration, mount points, networking, etc. However, it requires that you have a working network connection from your device to the NFS server. You might want to see ClientMode (Managed Mode) with WPA-Supplicant) for some information on how to do this via wireless.
• KEEP READING The fact is, there are so many ways to perform this step that it is left open. (E.g. one could follow the instructions in WGT634U_USB_root HOW-TO to build the USB filesystem. Then mount the USB filesystem on the NFS server machine and copy the contents of the filesystem to the desired NFS share directory). STOP READING, GO BACK TO THE BEGINING OF THIS STEP AND READ EVERYTHING AGAIN

• So now you should have your WGT634U's OpenWrt root filesystem available on your NFS host (lets say it is nfs_root_host) and verified that directory is shared (lets say as nfs_root_dir) and that you can mount it remotely, create files, etc. For example, my /etc/exports on my NFS server (which is Gentoo, but does it matter?) looks like:

/wgt634u 192.168.0.0/255.255.255.0(rw,sync,no_root_squash,no_all_squash)

If you are planning to have multiple devices netbooting from this directory (as I do) you will need a separate root directory for each. This isn't strictly true - you need at least separate /tmp and /var for each NFS root client. I find, however, that a full install with a mess of packages takes up about 64 MB for each host. As such, duplicating (for example) /usr for each NFS root client doesn't waste too much disk space. Besides, the preinit script below expects them all to be separate. To make this more concrete. I have two WGT634Us that I netboot in this way. One is femto, the other is pico. So in my NFS share (/wgt634u - see the /etc/exports above):

ls -l /wgt634u/*
/wgt634u/femto:
total 3
drwxr-xr-x  2 root root 1200 Dec 31  1999 bin
drwxr-xr-x  2 root root   48 Dec 31  1999 dev
drwxr-xr-x  9 root root  752 Dec 31  1999 etc
drwxr-xr-x  3 root root  688 Dec 31  1999 lib
drwxr-xr-x  2 root root   48 Dec 31  1999 mnt
drwxr-xr-x  2 root root   48 Dec 31  1999 proc
drwxr-xr-x  2 root root   48 Dec 31  1999 rom
drwxr-xr-x  2 root root  776 Dec 31  1999 sbin
drwxr-xr-x  2 root root   48 Dec 31  1999 sys
drwxrwxrwx  2 root root  104 Dec 31  1999 tmp
drwxr-xr-x  2 root root   48 Dec 31  1999 usb
drwxr-xr-x  6 root root  144 Dec 31  1999 usr
drwxr-xr-x  5 root root  120 Dec 31  1999 var
drwxr-xr-x  5 root root   48 Dec 31  1999 wpa

/wgt634u/pico:
total 3
drwxr-xr-x  2 root root 1200 Dec 31  1999 bin
drwxr-xr-x  2 root root   48 Dec 31  1999 dev
drwxr-xr-x  9 root root  752 Dec 31  1999 etc
drwxr-xr-x  3 root root  688 Dec 31  1999 lib
drwxr-xr-x  2 root root   48 Dec 31  1999 mnt
drwxr-xr-x  2 root root   48 Dec 31  1999 proc
drwxr-xr-x  2 root root   48 Dec 31  1999 rom
drwxr-xr-x  2 root root  776 Dec 31  1999 sbin
drwxr-xr-x  2 root root   48 Dec 31  1999 sys
drwxrwxrwx  2 root root  104 Dec 31  1999 tmp
drwxr-xr-x  2 root root   48 Dec 31  1999 usb
drwxr-xr-x  6 root root  144 Dec 31  1999 usr
drwxr-xr-x  5 root root  120 Dec 31  1999 var
drwxr-xr-x  5 root root   48 Dec 31  1999 wpa


• Go back to the Kamikaze tree... You need to fix wpa_supplicant (because it uses a hardcoded path of /tmp which is ROM). Use the build tools to do this automagically - create a file package/wpa_supplicant/patches/200-tmp-to-wpa-path.patch that contains (copying and pasting might not work if tabs get converted to spaces!):

--- wpa_supplicant-0.4.7.orig/wpa_ctrl.c        2005-10-19 19:43:50.000000000 -0700
+++ wpa_supplicant-0.4.7/wpa_ctrl.c     2006-04-06 16:28:06.000000000 -0700
@@ -99,7 +99,7 @@

ctrl->local.sun_family = AF_UNIX;
snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path),
-                "/tmp/wpa_ctrl_%d-%d", getpid(), counter++);
+                "/wpa/wpa_ctrl_%d-%d", getpid(), counter++);
if (bind(ctrl->s, (struct sockaddr *) &ctrl->local,
sizeof(ctrl->local)) < 0) {
close(ctrl->s);


Force a rebuild of wpa_supplicant with:

make package/wpa_supplicant-clean


• After making some changes to the squashfs filesystem tree, you will make a new flash image (openwrt-wgt634u-2.6-squashfs.bin) that has a different /etc/preinit , and configuration files telling the device how to connect to the network (in additions to some other minor paranoia brick defense changes). To do this, go into your build root directory, i.e. trunk/openwrt/build_mipsel/root (where you previously built Kamikaze):

cd trunk/openwrt/build_mipsel/root

# paranoia brick defense precautions

\rm bin/firstboot sbin/mount_root etc/preinit sbin/mtd sbin/jffs2root

# make mount point for nfs and wpa tmpfs

mkdir nfs wpa

• Now copy this preinit file to etc/preinit. This is the core of the wireless NFS root mount. This loads requisite modules, joins the wireless network, gets an IP address, and mounts an NFS share. Finally a pivot_root is done that leaves the nfs directory as / and the squashfs as /rom. Examine this file before you install it. You must configure it to your specific situation - in particular, set the variables: wifi_essid , wifi_channel , wifi_ap_mac , nfs_root_host , nfs_root_dir , and possibly change nfs_mount_options . Other file systems may be mounted with via /etc/fstab and mount in an /etc/init.d/rcS script later so there is no need to add them to preinit. Download and copy like:

# copy your own preinit to etc/preinit (assumes you have wget)

# in your build root directory (i.e. trunk/openwrt/build_mipsel/root), do

wget -O etc/preinit http://openwrt.pbwiki.com/f/WGT634U_wireless_NFS_root_preinit

# edit the file (specifically the wifi_essid , wifi_channel , wifi_ap_mac ,

# nfs_root_host , nfs_root_dir , and possibly nfs_mount_options variables)

vi etc/preinit

# don't forget to set it executable

chmod +x etc/preinit

vi etc/wpa_supplicant.conf

with the following contents (IMPORTANT make sure you put your ctrl interface file on /wpa - this is a tmpfs partition created by etc/preinit that will hold the wpa_supplicant files - this can't be in /var as /var is still a ROM filesystem when wpa_supplicant is run):

# allow frontend (e.g., wpa_cli) to be used by all users in 'root' group
ctrl_interface=/wpa/supplicant_ctrl_interface
ctrl_interface_group=root
#
# home network; allow all valid ciphers
network={
ssid="my_ssid"
scan_ssid=1
key_mgmt=WPA-PSK
psk="my_passphrase"
}


• Build the new image:

cd trunk/openwrt

make target/install

• Check your image by looking at the tgz counterpart, quickly:

tar -tvzf build_mipsel/linux-2.6-brcm/root.tar.gz | more

• In particular, make sure ./etc/preinit is the correct size, also verify that (paranoia brick defense) ./bin/firstboot, ./sbin/mount_root, ./sbin/jffs2root and ./sbin/mtd are absent.

• Flash the image via CFE and tftp. Reboot. Enjoy! See stuff below:

root@OpenWrt:/# df
Filesystem           1k-blocks      Used Available Use% Mounted on


• Postscript If you change your WPA passphrase, you will need to edit trunk/openwrt/build_mipsel/root/etc/wpa_supplicant.conf to reflect your changes. If you change your SSID, channel, etc. or any of your NFS server settings you will also need to edit trunk/openwrt/build_mipsel/root/etc/preinit (the one you downloaded w/ the wget above and edited previously). Finally, you will need to rebuild the image and flash it again.