# [Solved] How to Turn Off USB External Disk

## solamour

I've been using "hdparm -S 241 /dev/sda" to set a timeout value for the hard disk, so that it goes to sleep after 30 minutes. However, it doesn't seem to work on the external (IDE) disks that are connected via USB; hdparm says the disk doesn't support such an operation.

I'd like to put the disks to sleep, because sleeping disks generate less noise, less heat, and (possibly) consumes less electricity. Besides, I access them only occasionally, so there is no reason for me to keep the disks running all the time. My computer has no room for internal disks, and USB is the only option.

Getting a second computer with Wake-On-Lan and turn it on only when I need to access its disks is a possible solution, but it involves extra cost, which I'd like to keep low if possible. If you have an idea, please share. Thank you.

__

solLast edited by solamour on Sun Mar 15, 2009 8:21 am; edited 2 times in total

----------

## baeksu

You can use "sdparm --command=stop /dev/sdX", though that doesn't work for all USB enclosures.

With the various models I've come across, I'd say about 50% of enclosures support this.

The disks will spin back up when they are accessed. What I've used is a looping script that compares the value from /proc/diskstats every N minutes, and if there hasn't been any change in, say, 30 minutes, then it spins down the disk.

----------

## solamour

Sounds like a great idea, but unfortunately "sdparm" doesn't seem to work on my external enclosure. I appreciate your suggestion, though.

Would you care to share the script? Seems like it might come in handy. Thanks.

__

sol

----------

## baeksu

I'm worried I'll get royally booted for my lack of grace in bash, but here goes:

```
#!/bin/sh

disk="sda"

runs="0"

state=$(grep "$disk" /proc/diskstats)

while true;do

 sleep 5m

 newstate=$(grep "$disk" /proc/diskstats)

 if [ "$state" = "$newstate" ];

 then

  runs=$(($runs + 1))

  if [ "$runs" -gt 3 ];

   then

   sdparm --command=stop /dev/$disk

   runs="0"

  fi

 else

  runs="0"

  state="$newstate"

 fi 

done
```

The script basically gets the "$state" of "$disk" from /proc/diskstats, and then compares the state every 5 minutes.

If the value has changed (i.e. there's been some i/o on the disk), then it resets the loop counter.

If the value hasn't changed since a few iterations, it uses sdparm to shut down the disk, and starts over.

----------

## solamour

I just got a cheapo, no-name HDD enclosure from eBay, and it just happened that this thing supports "hdparm -S" command. Now the disk spins down when I leave it alone for a while. As baeksu mentioned, some units seem to support hdparm/sdparm, while others don't.

Is there a way to identify what chipset is used in the enclosure from the command line, like "lspci" does for, say, network cards?

__

sol

----------

## eccerr0r

lsusb works for usb devices.

I've found one of my Genesys logic does not power down external disks, and I think a later one of the same chip (different rev?) does...

Then again I might have been confusing it with some other... ugh. too confusing..

----------

## nerdbert

My Iomega 1TB drive doesn't spin down, even though sdparm's output looked promising:

```

root@homeserver > sdparm --command=stop /dev/sdc

    /dev/sdc: WDC WD10  EACS-00ZJB0

root@homeserver >

```

First I thought that something is accessing the disk, but lsof didn't return anything. So I'm quite sure this drive doesn't support it.

Could one of you recommend me a cheap 3.5 case which supports sdparm? 

I'm sure the disk will break rather soon if I keep it running 24/7...

----------

## solamour

A couple of my 2.5" cases do respond to hdparm, but none of 3.5" cases worked, even though some of them do seem to spin down in Windows. I'm also interested in 3.5" cases that work in Linux, so if you know of any, please share. Thank you.

__

sol

----------

## nerdbert

 *solamour wrote:*   

> even though some of them do seem to spin down in Windowsl

 

Same here. Both external drives I bought recently spin down under OSX without any user intervention. I don't even know how they do it.

Using 2.5 cases is my emergency strategy - I'm planning to set up a RAID 5 and since 2.5 drives cost much more and provide less storage I'm not willing to use them unless there is no other way.

I'll let you know if I find a 3.5 case/controller which goes to sleep under linux.

----------

## solamour

I really didn't need another enclosure, but I got one on eBay just to try it out and see how it measures up. It was slightly more expensive than others, but it had an eSata port as well as a USB port. I didn't have a 3.5" drive that I can pull out and test, so I used a 2.5" drive instead. Issuing "hdparm -Y" immediately put the drive to sleep.

It's a no-name brand, and "initio INIC-1611L A2128P A87457 02 200810" is written on the chip. Here is what "lsusb -v" says.

```
Bus 002 Device 024: ID 13fd:1340

Device Descriptor:

  bLength                18

  bDescriptorType         1

  bcdUSB               2.00

  bDeviceClass            0 (Defined at Interface level)

  bDeviceSubClass         0

  bDeviceProtocol         0

  bMaxPacketSize0        64

  idVendor           0x13fd

  idProduct          0x1340

  bcdDevice            1.04

  iManufacturer           1 Generic

  iProduct                2 External

  iSerial                 3 WD-WXE908H43984

  bNumConfigurations      1

  Configuration Descriptor:

    bLength                 9

    bDescriptorType         2

    wTotalLength           32

    bNumInterfaces          1

    bConfigurationValue     1

    iConfiguration          0

    bmAttributes         0xc0

      Self Powered

    MaxPower                2mA

    Interface Descriptor:

      bLength                 9

      bDescriptorType         4

      bInterfaceNumber        0

      bAlternateSetting       0

      bNumEndpoints           2

      bInterfaceClass         8 Mass Storage

      bInterfaceSubClass      6 SCSI

      bInterfaceProtocol     80 Bulk (Zip)

      iInterface              0

      Endpoint Descriptor:

        bLength                 7

        bDescriptorType         5

        bEndpointAddress     0x81  EP 1 IN

        bmAttributes            2

          Transfer Type            Bulk

          Synch Type               None

          Usage Type               Data

        wMaxPacketSize     0x0040  1x 64 bytes

        bInterval               0

      Endpoint Descriptor:

        bLength                 7

        bDescriptorType         5

        bEndpointAddress     0x02  EP 2 OUT

        bmAttributes            2

          Transfer Type            Bulk

          Synch Type               None

          Usage Type               Data

        wMaxPacketSize     0x0040  1x 64 bytes

        bInterval               0

Device Qualifier (for other device speed):

  bLength                10

  bDescriptorType         6

  bcdUSB               2.00

  bDeviceClass            0 (Defined at Interface level)

  bDeviceSubClass         0

  bDeviceProtocol         0

  bMaxPacketSize0        64

  bNumConfigurations      1

Device Status:     0x0001

  Self Powered

```

__

sol

----------

## nerdbert

Thanks solamour!

So I either find one with the same chipset or I'm back to trial and error (all the fun  :Wink:  )

----------

