NSLU2-Linux
view · edit · print · history

SwitchBox is a minimal NSLU2 ramdisk used to switch between root filesystems on boot. It can also be used as a recovery console ramdisk (allowing you to reflash partitions).

It is required because the stock Redboot will always load a ramdisk from the first block of the Ramdisk partition into memory before the kernel boots. Switchbox without network support (i.e. requiring a serial console) is smaller than one erase block size. We have decided to use two blocks (256Kb) to enable network support.

ToDo List:

  • Untar the payload that slugimage provides in the last block (the ixp400-csr and ixp425-eth modules).
  • Grab the macaddr from the redboot partition
  • Use ifconfig to set the macaddr, and bring up the ixp0 interface
  • Choose the boot location, based on kernel args or maybe a string in the last block
  • Boot from the chosen boot location

The following portion of the chat log describes a change to switchbox that will allow the Slug to be booted into ramdisk instead of jffs2. This allows us to upgrade a jffs2 slug with new firmware using the web interface.

[16:17] <rwhitby-web> 1) test mount jffs2 from mtdblock4

[16:18] <rwhitby-web> 2) if that mounts, then look for a /.ramdisk file in the jffs2 rootfs

[16:18] <rwhitby-web> 3) if /.ramdisk exists, then create a /dev/ram1 and copy the contents of jffs2 to it, and tell the kernel to boot from that instead (using real-root-dev)

[16:19] <rwhitby-web> 4) if /.ramdisk does not exist, then set real-root-dev to mtdblock4

[16:19] <rwhitby-web> 5) the rest of /linuxrc in switchbox is unchanged

I don't need mke2fs in switchbox, cause the jffs2 rootfs that I am copying already has it in there - I can just use it directly (but remember that it is dynamically linked, so we need to copy the libraries over to the right place first).

This can also be extended to look for /.recovery on the jffs2, and drop to recovery console if it exists.

By default, the kernel's settings (e.g. set in the kernel file with rdev or compiled into the kernel file), or the boot loader option setting is used for the normal root file systems.

It is possible for the /linuxrc executable to change the normal root device. For /linuxrc to change the normal root device, /proc must be mounted. After mounting /proc, /linuxrc changes the normal root device by writing into the proc file /proc/sys/kernel/real-root-dev. For a physical root device, the root device is changed by having /linuxrc write the new root file system device number into /proc/sys/kernel/real-root-dev. Note that to support NFS rootfs we need to change to a pivot_root based approach.

Making a generic ram disk

Make sure ram disk support is compiled in your kernel. If you don't have it, see the miniroot HOWTO for mounting via loopback.

Create a ramdisk device if one does not already exist in /dev:

 /home/tony# mknod -m 660 /dev/ram b 1 1
 /home/tony# chown root.disk /dev/ram

Zero out the space you need on the ramdisk device:

 /home/tony# dd if=/dev/zero of=/dev/ram bs=1k count=4k
 4096+0 records in
 4096+0 records out

Make a file system on the ram disk, specifying the size:

 /home/tony# /sbin/mkfs -t ext2 -m 0 /dev/ram 4096
 mke2fs 1.18, 11-Nov-1999 for EXT2? FS 0.5b, 95/08/09
 Filesystem label=
 OS type: Linux
 Block size=1024 (log=0)
 Fragment size=1024 (log=0)
 1024 inodes, 4096 blocks
 204 blocks (4.98%) reserved for the super user
 First data block=1
 1 block group
 8192 blocks per group, 8192 fragments per group
 1024 inodes per group
 Writing inode tables: done                            
 Writing superblocks and filesystem accounting information: done

Mount the ram disk as you would a regular device:

 /home/tony# mount -t ext2 /dev/ram /mnt/disk 
view · edit · print · history · Last edited by ka6sox.
Based on work by ka6sox, rwhitby, and Gerald L Clark.
Originally by ka6sox.
Page last modified on April 14, 2005, at 03:26 PM