view · edit · print · history

Special Handling of a Flash Drive for the Unslung Root Drive

Using a flash drive is often an attractive way to run an Unslung NSLU2. It's quiet, small, low-power, and low-cost.

However, they do have a significant disadvantage compared to the traditional hard-drive -- they wear out much, much faster.

A couple of simple changes to how Unslung uses the flash drive can greatly extend the life of the flash device:

  • Disabling swapping on the device.
  • Disabling the recording of the timestamp each time a file is accessed.

All that is required to instruct Unslung to make the necessary changes is to create a file named /.ext3flash after the system has been successfully unslung and rebooted. The following command will do the trick nicely:

 touch /.ext3flash

Once created, the changes will take effect at the next boot.

Potential Pitfalls

Nothing is ever free - and these changes also carry a potential cost. Certain applications may use the "last-accessed" timestamp, and these may misbehave when the accessed-time stamp is disabled (e.g. dropbear started via inetd). Swap space is used when the operating system runs low on main memory. And since the NSLU2 has only a small amount of RAM to begin with, large applications or many applications at the same time may run the system out of memory.

Technical Details

During the boot process, if the /.ext3flash file exists, the boot scripts will:

  • remount the root partition with -o noatime
  • remount the conf partition with -o noatime,sync
  • execute swapoff to turn off swapping on the root drive

Note: Unslung 5.5 only supports a flash disk as the root drive on USB Port 1. Unslung 6.x supports the use of a flash disk as the root drive on either USB port, although USB Port 2 is often preferred.

Reducing the number of writing even more

I've applied the spindown script, which copy all files from /dev and /var into a Ram-filesystem,taken from: http://www.nslu2-linux.org/wiki/FAQ/SpinDownUSBHarddisks. It is a bit dangerous, as the RAM-fs eats up more of the tot available 32Mb, while Ext3flash already has disabled swap.... After a year of using this script, I haven't had problems with this configuration. I can happily use the firefly mediaserver, nfs and the transmission torrent-client, and have no crashes.

 # /etc/init.d/mount_var_dev.sh
 # Script section to create ramdisk for /var and for /dev

 # disable the oom-killer to use the full swap
 /sbin/sysctl -w vm.overcommit_memory=1
 # From JNC : this command does not exist on my slug (release 2.7)

 # better only use /var/log then the full /var
 # following lines might need to be adjusted according to your OS and/or installed services
 /bin/echo "Creating ramfs for /var/log:"
 /bin/mount -t ramfs ramfs /mnt -o maxsize=256
 /bin/cp -rp /var/log/* /mnt/
 /bin/mount -o bind /var/log /var/log.state
 /bin/mount -o bind /mnt /var/log
 /bin/umount /mnt

 /bin/echo "Creating ramfs for /dev:"
 /bin/mount -t ramfs ramfs /mnt -o maxsize=256
 cd /dev
 find . -print0 -mount | cpio -p -0 -d -m -u /mnt
 # you can not use cp command for /dev
 /bin/mount -o bind /dev /dev.state
 /bin/mount -o bind /mnt /dev
 /bin/umount /mnt

 # Uncomment the following line when using debianslug
 #mount devpts /dev/pts -t devpts

 # Return and continue execution of system rc.
 return 1
 # [EOF]

The result on my Unslung6.8 slug with Ext3flash also applied:

 bash-3.2# free
              total         used         free       shared      buffers
  Mem:        30524        28788         1736            0         4900
 Swap:            0            0            0

I've got the firefly mediaserver and bash running alongside the original Linksys app and appr. 5% of 32Mb left...., so it seems. However, the 4900 Kb allocated to the buffers is available for programs directly. Linux is just using this for buffering data for the disks. The 1736 kB which is free, is in effect wasted; it's not used for any purpose.

view · edit · print · history · Last edited by mwester.
Based on work by bluebear, BenMcDui, Joop Verdoorn, Lars Bager, mwester, dB, tman, rwhitby, ChrisE, and Gerald L Clark.
Originally by ChrisE.
Page last modified on February 15, 2009, at 01:12 PM