0

I have a external Hitachi Hard Drive that has the annoying "Advanced Power Management" feature, that puts the device to sleep, if I do not use it for a minute. It is also not possible to turn this feature off by using "sudo hdparm -B 128".

E.g. when I pause a video to make a short break, the player is not working properly and skips half a minute until the hard drive wakes.

In order to trick the HDD I wrote a small shell script, that constantly reads from the device, so it never falls asleep. It works just fine, but every time I use this script I get a kernel panick after some time.

Here is my shell script:

#!/bin/bash

if [[ "$(id -u)" != "0" ]]
then
  sudo -s <<EOF
  ionice -c3 pv -s 4000784052224 -q -L 1m '/dev/sdb' &> /dev/null
  while [ $?==0 ]
  do
    sleep 1
    ionice -c3 pv -s 4000784052224 -q -L 1m '/dev/sdb' &> /dev/null
  done
EOF
else
  ionice -c3 pv -s 4000784052224 -q -L 1m '/dev/sdb' &> /dev/null
  while [ $?==0 ]
  do
    sleep 1
    ionice -c3 pv -s 4000784052224 -q -L 1m '/dev/sdb' &> /dev/null
  done
fi

I'm using Linux Mint 17.1 with the kernel version 3.16.0-031600-generic (the problem also accrued in the original kernel).

Do you have any idea, why that is happening?

0

I have found out, why a kernel panic is occurring. Apparantly linux is caching this endless data transfer, so the simple solution is to turn the caching off with nocache.

So my current solution right now are the following files:

/etc/udev/rules.d:

KERNEL=="sd*", SUBSYSTEMS=="usb", ATTRS{manufacturer}=="HGST", ATTRS{product}=="Touro Desk 3.0", ATTRS{serial}=="31001312300002100125", ACTION=="add", RUN+="/usr/local/bin/touro_read_loop"
ACTION=="remove",  ENV{ID_SERIAL=="HGST_Touro_Desk_3.0_31001312300002100125"}, RUN+="/usr/local/bin/touro_read_stop"

/usr/local/bin/touro_read_loop:

#!/bin/bash

if [ ! -e /tmp/.apm_pids ]
then
    setsid /usr/local/bin/touro_read_loop_main >/dev/null 2>&1 < /dev/null &
fi

/usr/local/bin/touro_read_loop_main:

#!/bin/bash

if [[ "$(id -u)" == "0" ]]
then
  while test -e '/dev/disk/by-id/usb-HGST_Touro_Desk_3.0_31001312300002100125-0:0'
    do
    setsid nice -n19 ionice -c3 nocache pv -s 4000784052224 -q -L 1m '/dev/disk/by-id/usb-HGST_Touro_Desk_3.0_31001312300002100125-0:0' >/dev/null 2>&1 < /dev/null &
    PV_ID=$(pgrep -nx pv)
    echo -ne "$$\n$PV_ID\n" > /tmp/.read_loop_pids

    while test -d "/proc/$PV_PID"
    do
      sleep 30
    done
  done
fi

/usr/local/bin/touro_read_stop:

#!/bin/bash

cat /tmp/.apm_pids | sudo xargs -i kill {}
sudo rm /tmp/.read_loop_pids

With that my hard drive is always active whenever I plug it to my laptop, so there is no advanced power management anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.