Using the Boot Disk Mechanism with Unslung
This article pertains to:
The boot disk mechanism is new in Unslung 6.10. It provides a fairly painless means to intercept the boot process and insert your own script - simply by plugging a disk into the NSLU2.
The poor little sick slug - it's hurting, but all it has to tell you what's wrong are a few LEDs and a beeper. Wouldn't it be great to have some other means to communicate with the device? Wouldn't it be neat to have a way to customize the internal firmware boot process to do something extra, or change something, without needing to telnet in, and upload files and all that stuff?
Unslung 6.10 supports something referred to as a "bootdisk". In a nutshell, after it completes the normal boot (with or without disks), if it finds a specifically-named file in a specifically-named place on an external USB device, it will execute that file as a shell script.
Example: "I Lost My NSLU2 on the Network!"
So what do you do with this? Well, how about having that shell script fetch the network IP address that the device has and write that to the USB device (flash memory device or disk)? This would be a convenient way to find your lost slug -- place the script on an ordinary FAT-formatted USB key, plug it into the slug, boot it up, power it off, and look at the log file that appeared on that USB key to see what IP address your slug was using.
Of course, you can change things with that script. The script can do almost anything you can do as a user when you're logged in at a shell prompt.
You can download a sample boot disk script here: http://moko.mwester.net/unslung_sample_bootdisk.zip -- just unzip this to the top level of a FAT-formatted USB key in order to use it as described above.
Advanced Example: Automatic Unsling
As a proof-of-concept (it's nowhere nearly reliable enough), I wrote a script that can be placed in this special directory structure on an other-wise empty USB key of almost any size (32 MB or greater), and the key plugged into a freshly-flashed Unslung system.
Upon power-up, the new Unslung system boots, and begins executing the script, which proceeds to format the USB key, copy the files in place to fake the Linksys firmware into thinking that it itself did the format, then performs an "unsling" to the newly-formatted USB key.
Upon reboot you have a fully-unslung system, ready-to-go. As I said, not stable enough for general use, but it does illustrate what you can do with the bootdisk concept. (For those wondering how one can format a device from the command line on a virgin Unslung system, the fdisk provided with Unslung 6.10 is still the crippled Linksys version so that the Linksys firmware continues to work -- but you can now type "busybox fdisk" to invoke a properly-functional fdisk. This might be useful for some situations.)
An example script to do this can be found here: http://moko.mwester.net/unslung_sample2_bootdisk.zip -- use with caution; it is only an example and is not nearly robust enough to be considered reliable!
Building Your Own Boot Disk Scripts
The requirements for the bootdisk to work are:
In deference to the inevitable, by default the script file will be copied off of the flash device, and MSDOS-style line endings converted to normal line endings. If you wish to avoid this happening (perhaps your script is a very large self-extracting file, and it would fill up the flash on the slug), simply place a line in the script that looks like:
(exactly like that, no indentation, no spaces, no tabs, no nothing)
In order for your bootdisk script to know where that USB device is (so it can find supporting files or tools, or know where to write a log file, etc), two arguments are passed in to the script. The first is the full path to script's original location on the USB device; the second is the path to the subdirectory containing the script.
Disabling Boot Disk on your Unslung NSLU2
Finally, what if you don't want the bootdisk stuff? Perhaps you don't trust people, or you don't trust yourself. If you simply create an empty file at "/.nobootdisk", the bootdisk checking will not occur.