USB HDD power off after shutdown

I use Ubuntu 12.04 on my external USB HDD and from the begining when I power off my ubuntu my USB HDD also power off 5 seconds later than my computer. Its good for me. But after some updates Ubuntu USB HDD stay power on. Where I can set this ?

I make changes according Your help but problem is again and after restart I have ..power/control in mode ON. I am not sure but I think that my HDD is usb1.

petat@mujlin:~$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 003: ID 04e8:342e Samsung Electronics Co., Ltd 
Bus 001 Device 004: ID 152d:2509 JMicron Technology Corp. / JMicron USA Technology Corp. JMS539 SuperSpeed SATA II 3.0G Bridge
Bus 003 Device 002: ID 04f3:0103 Elan Microelectronics Corp. 
petat@mujlin:~$ cat /sys/bus/usb/devices/usb1/power/autosuspend_delay_ms
2000
petat@mujlin:~$ cat /sys/bus/usb/devices/usb1/power/control
auto

Solution 1:

You can try to unload the EHCI controller (USB 2.0) before shutdown.

  1. Check your ID (Bus/Device/Function), use these commands in Terminal:

    cd /sys/bus/pci/drivers/ehci_hcd/
    ls -1
    

    For example, my outputs are:

    0000:00:02.1
    bind
    module
    new_id
    remove_id
    uevent
    unbind
    

    The first one is my ID. Check your ID

  2. Now you need to create the script, use this command in Terminal (rc0.d is used when you shutdown your computer)

    sudo -H gedit /etc/rc0.d/K99mycustomscript
    

    Add this line:

    echo -n "YOUR_ID" > /sys/bus/pci/drivers/ehci_hcd/unbind
    

    For example, in my case it's:

    echo -n "0000:00:02.1" > /sys/bus/pci/drivers/ehci_hcd/unbind
    
  3. Save and close gedit

  4. Make your script executable

    sudo chmod +x /etc/rc0.d/K99mycustomscript
    
  5. Now if you want to run your script on reboot (rc6.d):

    sudo cp /etc/rc0.d/K99mycustomscript /etc/rc6.d/K99mycustomscript
    

References

Solution 2:

You need to find out in which USB port your drive is plugged in.

Use lsusb command. For my Kingston flash drive it shows Bus 001, which means it is on usb1:

$ lsusb
...
Bus 001 Device 003: ID 13fe:1d00 Kingston Technology Company Inc. DataTraveler 2.0 1GB/4GB Flash Drive / Patriot Xporter 4GB Flash Drive

Then check the file (use your usb number for X):

 less /sys/bus/usb/devices/**usbX**/power/control

I have auto in mine. You might have on, in there. Try changing it to auto with your text editor, like this, for example:

 sudo nano /sys/bus/usb/devices/usb1/power/control

Also, check the .../power/autosuspend_delay_ms file. Make sure there is no -1 written to it. Mine has 2000 in it, which gives 2 seconds to the USB device before turning it off.

There is relevant information about USB power management at this site.