jamie.lentin.co.uk

D-Link DNS-320 & DNS-325 NAS: Userland configuration

I'm guessing you already know how to setup software RAID under linux and get the NAS to behave vaguely like a NAS. This is how to control the rest of the hardware now you have Linux booted.

The dns-nas-utils package

I've put useful utilities in the dns-nas-utils deb package. To install it, do:

nas:~# wget -O dns-nas-utils.deb https://github.com/lentinj/dns-nas-utils/blob/master/dns-nas-utils.deb?raw=true
nas:~# dpkg -i dns-nas-utils.deb

You can look at the source on github.

Controlling LEDs

The LEDs can be turned on/off via. sysfs:

nas:~# echo 1 > /sys/class/leds/dns320\:red\:usb/brightness
nas:~# echo 0 > /sys/class/leds/dns320\:red\:usb/brightness

You can control what triggers them via. sysfs too. To make the power light pulsate with how loaded the system is, do:

nas:~# echo heartbeat > /sys/class/leds/dns325\:white\:power/trigger

The SATA activity LEDs are wired up so the SoC takes care of them, however you can change this by turning them to GPIO pins in arch/arm/mach-kirkwood/board-dnskw.c, and adding them to arch/arm/boot/dts/kirkwood-dns320.dts.

Using buttons

To test, you can use the evtest tool to see button presses, evtest /dev/input/event0.

To trigger actions on button presses, use the esekeyd daemon:

nas:~# apt-get install esekeyd
nas:~# cat <<EOF > /etc/esekeyd.conf
POWER:/sbin/halt
RESTART:/sbin/reboot
EJECTCD:/bin/umount /dev/sdc
EOF

And edit /etc/default/esekeyd to start the daemon.

Power-recovery

The NAS has the ability to turn itself back on if power is interrupted.

I tried to make the kernel turn this on by default, unfortunately this has been broekn in the majority of mainline kernels, but you can do this in userspace by adding the following to /etc/rc.local:

# Tell PMU to turn back on after a power failure
echo 37 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio37/direction
echo 1 > /sys/class/gpio/gpio37/value

Temperature sensor

There is a script in my dns-nas-utils package dns_temp, that can get the temperature regardless of which NAS you have.

DNS-320
The temperature is read by sending commands to whatever is the other end of ttyS1. See the dns_temp source for the protocol.
DNS-325
The temperature can be read from /sys/class/hwmon/hwmon?/device/temp1_input

Controlling Fan

The dns-nas-utils package has a daemon to control the fan at similar thresholds to what d-link did.

The fan can be controlled directly by twiddling sysfs thus:

nas:~#  echo 6000 > /sys/class/hwmon/hwmon?/device/fan1_target # High speed
nas:~#  echo 3000 > /sys/class/hwmon/hwmon?/device/fan1_target # Low speed
nas:~#  echo    0 > /sys/class/hwmon/hwmon?/device/fan1_target # Off