Linux : Sheevaplug as a perfect NAS

After having done a little research on arm based computer (see article), I found an used Sheevaplug for less than 40 euros (!)… So I decided to use it as a NAS. Below is the main steps I followed to install it : easier than installing a classical x86 debian.

Like I did on my previous x86 server, I use two 2To sata disks : one for main storage plugged on the eSata port, and another plugged on the usb2 port for mirroring (sync’ed every night with rsync then turned off for power saving and disk protection)

Preparing

The following site contains a simple and well made guide to get a debian Squeeze install image for the kirkwood architecture (the one used by the Sheevaplug):
http://www.cyrius.com/debian/kirkwood/sheevaplug/install.html

As I wanted to optimize SdCard partition (see article), I prepared the sdcard on my desktop (archlinux). After partitioning, I made a LVM partition the classical way before formating in ext4:

pvcreate /dev/sdb1
vgcreate vg-data /dev/sdb1
lvcreate -n lv-data -L 7.27g vg-data

 

As I wanted to install the root partition on the SdCard, I could not use it as install media. So I put the install image (uImage) and the initrd image (uInitrd) on an usb pendrive (/boot will be on internal sheevaplug’s flash: /dev/mmcblk0p1).

Boot sheevaplug and follow the installer

I followed the aforementioned guide and I made the following choices during the debian install process:

  • do manual partition
  • choose not to format existing partition (just select mount point as I previously optimised and formated the SdCard)
  • ignore error about bad option on file system (due to no journaling) => answer no
  • answer no for swap too (not need for swap in my case)

The base system install begin, and all is automated…

Optimize system for flash drive (sdcard)

In order to optimize the whole system for flash drive (more speed and less write access) I made some custom changes to both /etc/fstab and /etc/rc.local.

On fstab I mainly added tmpfs partitions for frequently written directories as well as more secure mount options:

tmpfs /tmp         tmpfs nodev,nosuid,noatime           0 0
tmpfs /var/tmp     tmpfs nodev,nosuid,noatime           0 0
tmpfs /var/log     tmpfs nodev,nosuid,noatime,size=20M  0 0
tmpfs /var/backups tmpfs nodev,nosuid,noatime,size=10M  0 0
tmpfs /var/run     tmpfs defaults,noatime,size=1M       0 0
tmpfs /var/lock    tmpfs defaults,noatime,size=1M       0 0

 

Then in /etc/rc.local I setup “deadline” scheduler which is better than the default one which is made for harddrive. Note That I don’t use the “noop” scheduler because “deadline” can be better as it group small accesses, which improve latency.

echo deadline > /sys/block/mmcblk0/queue/scheduler

 

Finaly I made a little script based on my own shell library to sync /var/log and /var/backup to a non tmpfs partition in order to keep logs on a non-volatile support. I run this on a weekly basis throught /etc/cron.weekly.
This mecanism is safe enought for me as my sheevaplug is powered from a battery backed up source, so there is very few chance to loose log files (ok, the server could crash and I accept that)…

#!/bin/bash
. /etc/bluemind/functions
synclog
syncbak
cleanTmp

 

NAS softwares

After having finished the base system install and optimizations, I configured two main software for a NAS : Network Sharing and search engine.

Samba install

There is not a lot to say for samba installation as it is pretty straight forward using “apt-get”.
I got the best speed results (thought both wired and wireless connections) with the following adjustments in the configuration file (/etc/samba/smb.conf)

socket options = SO_KEEPALIVE TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536
read raw = Yes
write raw = Yes
getwd cache = Yes

 

A search engine for hosted document

I used “regain” to index all my documents. It works more or less like google and is very usefull to find documents on the NAS (including mp3, as it indexes ID3 tags).

I got the server version on sourceforge and unzipped it in /opt. Then, I  followed the install instructions on http://regain.murfman.de/wiki/doku.php?id=installation:server (I chose to install it on /opt)

To run the web UI you need to install tomcat

apt-get install tomcat6

 

Then change the memory allocated to the tomcat’s JVM (32M is enought for regain web interface) in /etc/default/tomcat6 :

JAVA_OPTS="-Djava.awt.headless=true -Xmx32m -Xms32m -XX:+UseConcMarkSweepGC"

 

Finaly I made a script to update document index every week  if any new file has been added on the NAS during the last 7 days (again, based on my own shell framework):

#!/bin/bash
 
. /etc/bluemind/functions
 
headerMessage "Documents indexing for $HOSTNAME"
 
# get number of modified file
nbfile=$(getNbChangedFile "/path/1 /path/2 /path/X" -7)
 
if [ $nbfile -eq "0" ]; then
 footerMessage
 exitOK "No change to document => nothing new to index"
else
 indexDocuments
 exitOK "Documents indexing output ($nbfile changes)"
 footerMessage
fi

Leave a Reply

Your email address will not be published. Required fields are marked *


*