30.12.09

WD MyBook Hacks - S.M.A.R.T.

There was something that bothered me quite a lot: while the MyBook seems to have smartmontools preinstalled, I was not able to read SMART data from the hard disk:

~#:smartctl -a /dev/sda
smartctl version 5.38 [arm-unknown-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

Device: WDC      WDC WD10EADS-00L Version: 01.0
Serial number:      WD-WCAU4C518954
Device type: disk
Local Time is: Wed Dec 30 16:23:35 2009 CET
Device does not support SMART

Error Counter logging not supported

[GLTSD (Global Logging Target Save Disable) set. Enable Save with '-S on']
Device does not support Self Test logging

This is strange because 3.5" SATA drives supposed to possess SMART capability. After reading the smartmontools wiki through I came up with the solution:

 ~#:smartctl -d sat -a /dev/sda

an additional "-d sat" parameter is necessary for proper operation. I note however that "-d ata" works as well. In the output we have the table that should look like something like this:

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x002f   200   200   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0027   157   156   021    Pre-fail  Always       -       7116
  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       53
  5 Reallocated_Sector_Ct   0x0033   200   200   140    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x002e   100   253   000    Old_age   Always       -       0
  9 Power_On_Hours          0x0032   100   100   000    Old_age   Always       -       171
 10 Spin_Retry_Count        0x0032   100   253   000    Old_age   Always       -       0
 11 Calibration_Retry_Count 0x0032   100   253   000    Old_age   Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       11
192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       4
193 Load_Cycle_Count        0x0032   200   200   000    Old_age   Always       -       53
194 Temperature_Celsius     0x0022   111   100   000    Old_age   Always       -       39
196 Reallocated_Event_Count 0x0032   200   200   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0032   200   200   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   100   253   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0032   200   200   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x0008   100   253   000    Old_age   Offline      -       0

SMART Error Log Version: 1
No Errors Logged


For detailed explanation of the parameters above I suggest reading the corresponding Wikipedia article.

29.12.09

WD MyBook Hacks - LEDs

One fascinating aspect of this storage device is the front LED panel. This can be used to visualize the status of the MyBook, or even to merely play around :)
For the "blue ring" version of the MyBook there exist a detailed tutorial on the related wiki, yet for the newer "white light" version I haven't found anything, but after some testing I managed to have a consistent picture of what is going on. Let's see:

The modul in charge for operating the LEDs is the following:

~#: lsmod | grep led
oxnas_wd810_leds            7496   0

This modul is located in  
/lib/modules/2.6.24.4/kernel/arch/arm/mach-oxnas/oxnas-wd810-leds.ko.

 If the modul is loaded (it should be on startup), we get the interface in /sys/class/leds:

/sys/class/leds#: ls -1
oxnas-wd810-leds:ac/
oxnas-wd810-leds:ca/
oxnas-wd810-leds:st/
oxnas-wd810-leds:sw/


Here we find for directories with rather identical content:

/sys/class/leds/oxnas-wd810-leds:ac#: ls -1
brightness
device@
subsystem@
trigger
uevent 

In detail:

brightness contains a single numeric value between 0 and 255
device@  symlink to /sys/devices/platform/oxnas-wd810-leds directory
subsystem@ symlink to /sys/class/leds
trigger:  by default one single line: none [sata-disk]
uevent: contains:
PHYSDEVPATH=/devices/platform/oxnas-wd810-leds
PHYSDEVBUS=platform
PHYSDEVDRIVER=oxnas-wd810-leds

Out of these brightness will be of the most importance. Using the numeric value here we can control the illumination of the LEDs. The rest, well those need some more research, I think however that it is a good idea to leave uevent alone, and trigger might be responsable of the automated operation in response to some event. It is quite confusing still that it has the same content in all four directiories...

The brightness files can simply be altered by for example:

/sys/class/leds/oxnas-wd810-leds:ac#: echo 1 > brightness

which means that we put "1" in the file. So let's see the role of each directory:
  • oxnas-wd810-leds:ac/: "ac" might stand for activity. Putting any numeric value here will cause the LED stripe sweeping up and down once and returning to the previous state. It is interesting that the actual value does not matter (even can be the same always), yet a simple "touch brightness" is not enough.
  • oxnas-wd810-leds:ca/: Here we have a fuel gauge operation of the stripe. The numeric value expresses percentage, so that values between 0 and 100 make sense here. 
  •  oxnas-wd810-leds:st/: This directory is for several visual effects (including blinking, wobbling, sweeping back and forth...) which can be altered by putting a number between 0 and 15 in the brightness file. Larger values have no effect, while 0 and 1 stand for the steady pattern determined by the fuel gauge.
  • oxnas-wd810-leds:sw/ I did not manage to alter the LED pattern by any numeric value. This can be either not implemented feature or has some different mode of operation.
Using these one can easily visualize the disk usage, temperature, or even the load average of the MyBook :) The moving patterns are also capable of some sort of alarm operation (based on e. g. SMART report of smartmontools).

I noticed that sometimes all of the LEDs turned off and didn't respond anymore. In this case a reboot is necessary since reloading the module itself not seemed to be enough.


There is even more: I also found signs of controlling the rest of the LEDs on the storage (including power, USB). This is what I found in /sbin/fschk_prompt.sh:

    #Turn on PWR LED
    /bin/echo 0 >/proc/wixgpio/gpio06
    #Turn off PWR LED
    /bin/echo 1 >/proc/wixgpio/gpio06
    #Turn on USB LED
    /bin/echo 1 >/proc/wixgpio/gpio10
    #Turn off USB LED
    /bin/echo 0 >/proc/wixgpio/gpio10
    #Turn off ID LED
    /bin/echo 0 >/proc/wixgpio/gpio00


The interesting thing is that there is neither such directory in /proc nor any GPIO-related module anywhere. So this can be some sort of residual of code from the "blue ring" device or something like that...

20.12.09

WD MyBook Hacks - The Basics

I recently started to play around with a 1 TB Western Digital MyBook. The aim is to make a versatile online storage and backup solution. I also found that this device can be used as a print server as well which is a plus that we might put to the test later on.

Here I will collect basic knowledge on the device as well a startup guide, while specific hacks will come later on. For putting this post together I highly relied on this wikidot page. I however decided the collect things here because sometimes I felt lost in the huge amount of wiki articles and forum posts and also some hacks are a matter of personal taste.

Upon hooking up the device on the local network, it usually gets IP address by the means of DHCP. It is recommended to supply it with a fixed IP afterward which can be achieved with most of the SOHO routers. If you want to reach the storage from outside of your LAN then it is also necessary to set up a portforward on the router for which you have to refer to the manual of the specific router or the iptables manual.

If the device is on the network, basic settings can be achieved on the web interface by simply putting the IP address of the storage to the address bar of the browser. The default login is "admin/admin". Most of the interesting stuff can be found in Advanced mode :)

I suggest to acquire the latest firmware (web update button) and both disable and unregister Mionet service. The later would be some tool for sharing remote data (except for anything that has an extension of avi, mp3...) but there are way more versatile tools for that including FTP, SFTP rendering this one useless. EDIT: it seems that simply disabling the service on the web interface is not enough. In fact, it periodically respawns. So what needs to be done is the following: From /etc/init.d remove S9M_ionet script, which starts the service upon boot.
In fact, this is not enough either, so the files /usr/mionet/changeNotifySocket and /usr/mionet/bin/cvm also need to be removed or renamed to something else.

Later on we will need to use SSH for customizing the device for which one needs either putty (for Win) or ssh for linux. For the first login the root password is "welc0me" which I strongly suggest to change immediately with the passwd command.

Next, the ipkg package management system needs to be installed. The tutorial can be found here. This lightweight package manager will give us the opportunity to get several hundreds of precompiled packages. One can also compile packages upon installing gcc, but this is way more inconvenient and usually is unnecessary.

Must have ipkg packages:
  • bash (3.2.49-1_arm). Note: for effectively using bash, the shell in /etc/passwd has to be rewritten for each user from /bin/sh to /opt/bin/bash.
  • bash-completion (1.1-1_arm)
  • pciutils (3.0.0-1)
  • usbutils (0.73-3)
  • libusb (0.1.12-1)
  • mc (4.6.2-1) Note: in order to preserve options, create .mc directory in ~. Further tuning includes e. g. coloring.
As ipkg installs everything in /opt, /opt/bin has to be included to the $PATH variable in /opt/etc/profile. For root, one has to include both /opt/bin and /opt/sbin to $PATH in /root/.bashrc and /root/bash_profile. Note: this applies for ipkg itself so in advance of doing so, /opt/bin/ipkg has to be used instead of simply ipkg.

Disabling Twonky Media Server is also a good idea: Like Mionet, it also consumes a great deal of memory and yet not that useful. In fact, instead of a streaming media server, one could always use file sharing and play media on the computer. Obviously this does not apply to consoles and similar stuff.  In order to permanently kill it, I simply renamed the script that starts the service upon boot:
#~: cd /etc/init.d
#~: mv S97twonkyserver /root/S97twonkyserver.old
#~: touch S97twonkyserver
#~: chmod a+x S97twonkyserver

This way we preserved the old startup script in case we need it later on and created a new placeholder file which simply will not do anything. Note that the old script has to be removed from /etc/init.d, otherwise it will run as well.

This was some sort of "must have" part, for specific hacks see the following links (continuously updated):
  1. LED interface
  2. S.M.A.R.T. capability
  3. Print Server
  4. Removing default folder shares
  5. Reading temperature sensors 
  6. Using MRTG

Introduction

Over the last couple of years I made a plenty of so to say hacks in the environment around me. These include both smaller and larger projects usually consisting of some electrical and/or programming job or custom do-it-yourself work.

I recently decided to put these stuff together so that anyone who finds it can profit from it and I also have these things for future reference. For upcoming projects I also think that it will be useful to have them collected here. I however do not restrict myself in that sense that no matter how serious or complicated a project is, I will post it here if I think that it makes sense.


A few words about me: As of starting this blog I am a PhD student at the Department of Physics, Technical University of Budapest. I always aimed to keep an open mind and understand everything around me or even make things better (which effort resulted in this blog). Since I am not excessively trained in electrical engineering and I am also (somewhat :) ) undereducated in computer science, there is a chance that discrepancies will be found in my posts. In such a case everyone feel free to set the record correct straight either by commenting or sending a message to me so that I can correct my mistake.

I think that there is nothing else to say, so everyone have a good reading,
Attila