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
svn co -r 3535 https://svn.openwrt.org/openwrt/trunk/
cd trunk/openwrt
make menuconfig
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
make
CFE> ifconfig eth0 -auto
et0: link down
Device eth0: hwaddr 00-00-C0-FF-EE-00, ipaddr 192.168.0.103, mask 255.255.255.0
gateway 192.168.0.1, nameserver 69.69.69.69, domain foo.bar.
*** command status = 0
CFE> flash -noheader 192.168.0.2:openwrt-wgt634u-2.6-squashfs.bin flash0.os
Reading 192.168.0.2:openwrt-wgt634u-2.6-squashfs.bin: Done. 1806336 bytes read
Programming...done. 1806336 bytes written
*** command status = 0
/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
--- 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
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
# 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" }
cd trunk/openwrt
make target/install
tar -tvzf build_mipsel/linux-2.6-brcm/root.tar.gz | more
root@OpenWrt:/# df Filesystem 1k-blocks Used Available Use% Mounted on