Sunday, May 29, 2011

External usb hdd WD Elements - avoid spindown

Update: I got a new workaound here: External usb hdd WD Elements - avoid spindown -- #2

I've got an external 2.5", 500G USB HDD from WesternDigital
- this one: http://images.google.com/images?q=WDBABV5000ABK-00.
Without being accessed, it spins down after 5-10s (seconds, not minutes!) automatically.
This behavior seems to be hardcoded in the hardware/firmware by WD and cannot be changed (if anyone knows better, please leave a comment). It can be very annoying, for example when starting a file manager or open a 'save as...'-dialog etc. because the hard drive has to spin up every time adding a delay of some seconds until the dialog appears. The same happens when reading or writing at a low speed (let's say ~ <10KiBytes/s) - the drive spins up and down multiple times a minute.

A dirty workaround is to keep the drive busy by touching and syncing in a short interval.

A quick way to do this via commandline:
while [ 1 ]; do echo "touch at - `date`"; touch /media/WD_500G_NTFS/tempfile; sleep 5s; sync; done
A bit nicer with the following script:
#!/bin/sh
# this script finds out the mountpoint for the given DISKLABEL
# and touches the file ${MOUNTPOINT}/tempfile periodically every
# INTERVAL.
# adjust the following two values.
DISKLABEL="WD_500G_NTFS"
INTERVAL="5s"
# get line with our disklabel
MOUNTLINE=$(mount -l | grep "$DISKLABEL");
# check if mounted
if [ "$MOUNTLINE" == "" ]
then
echo "Error: Partition with disklabel $DISKLABEL not mounted."
exit 1
fi
# get mountpoint
# FIXME:
# not sure if awk command always returns
# the correct mountpoint or an empty string...
MOUNTPOINT=$(echo $MOUNTLINE | awk '{ print $3 }')
# check if mountpoint begins with /media/ to prevent errors by
# mountpoint extraction above.
# dirty. problem when partition is mounted somewhere else.. :-(
(echo $MOUNTPOINT | grep "\/media\/") &> /dev/null; RC=$?
if ! [ "$RC" = 0 ]
then
echo "Error: problem extracting mountpoint."
exit 2
fi
echo "Found mountpoint for partition labeled '$DISKLABEL' at '$MOUNTPOINT'."
echo "Touching and syncing ${MOUNTPOINT}/tempfile every ${INTERVAL}..."
echo "Quit with ^C."
while true
do
touch ${MOUNTPOINT}/tempfile
sleep ${INTERVAL}
sync
done
view raw KeepSpinning.sh hosted with ❤ by GitHub


edit: inserted link to new post.

Tests with code and syntax highlighting.

Hello, this is my first blog entry and i'm just testing how to add code.
  • The 'Quote' option in the 'new Post' editor just indents the text block; one possibility is to change the font for the selected text block to e.g. Courier, a fixed width font, but of course there is no syntax highlighting.

There are some other solutions i found in the internet:

Below a simple shellscript example with http://gist.github.com/. Just copy&paste your code there, get the 'embed code', paste into the blogger/blogspot html-editor, done.
#!/bin/bash
function pause(){
read -p "$*"
}
pause 'Press enter to continue…'
view raw pause.sh hosted with ❤ by GitHub
[EndOfFirstBlogEntry] - Woohoooo.