Prevent External USB HDD Disk Sleeping

thanks for the solution. i will try to do that. it is a dirty way but if it works, why not :slight_smile:

1 Like

If you want to wake up your drives, query the SMART info.

For PowerShell:
Run this from a .vbs on your Task Scheduler every N minutes set to run under the SYSTEM account (Administrative privileges)

Get-PhysicalDisk -ErrorAction Ignore | Get-StorageReliabilityCounter -ErrorAction Ignore

Windows/Linux/macOS will not cache the SMART info and the on-board controller will always report it and guarantee spin-up of the disk if it is able to do so.

5 Likes

hmm thats an interesting idea.

i found a tool in ubuntu smartmontools it gives smart status of hdd; change sdc1 with your drive.

sudo apt install smartmontools
sudo smartctl --all /dev/sdc1 

the result is as below there is no smart support for my hdd but i think even getting below output will prevent from sleeping, right?

=== START OF INFORMATION SECTION ===
Vendor:               WD
Product:              Elements 25A3
Revision:             1030
Compliance:           SPC-4
User Capacity:        8.001.529.315.328 bytes [8,00 TB]
Logical block size:   512 bytes
Physical block size:  4096 bytes
LU is fully provisioned
Rotation Rate:        5400 rpm
Serial number:        VGJJT9LG
Device type:          disk
Local Time is:        Mon May  3 00:59:30 2021 +03
SMART support is:     Unavailable - device lacks SMART capability.
1 Like

Glad you solved your problem my friend, my response time is 0.00300. Do I have to use it?

for ubuntu systems,

hd-idle solved my issue and my hdd is not sleeping anymore.

here was the solution.

4 Likes

does this keepaliveHD program only works for Western digital?

It works for any drive. I set it to write file and then delete, I found that just reading alone wasn’t keeping the drives awake (due to caching, perhaps).

1 Like

For Linux, I used this cron job posted at Ask Ubuntu. I modified it to 4 minutes rather than every minute:
*/4 * * * * /bin/bash -c 'dd if=/dev/disk/by-uuid/THE-UUID of=/dev/null count=1 skip=$RANDOM'
The post linked goes into more detail.
My problem wasn’t the drive but the ORICO enclosure that has an annoying “smart sleep” feature.

2 Likes

I use USBDLM to fixed drive letter and set time for DiskKeepAlive function, work well without needed to write file to hard drive as its only read sector 0 of every drive.

Basically, if I set

hd-idle -i 0

, my external HDD would never sleep, right?

yes you can try first that solution.

if it does not work, you can create a cron job which basically copies any file to hdd every x minutes. that also works too.

2 Likes

does it solves same problem for seagate external hdds?

If using windows 10 you can untick this in device manager. Works like a charm!

devicemanager

I found out that the bullet proof solution is to use crontab -e. It’s the simplest and cleanest solution, doesn’t mess with your system settings in any way, also works 100% regardless your HDD model.

To use crontab, open the terminal and type crontab -e. Then, for instance, you can tab your HDD every 5 mins so it won’t go to sleep by adding this line into your crontab:

*/5 * * * * /bin/touch /media/user/hdd_label/.stayawake &> /dev/null

Please note that /media/user/hdd_label/.stayawake should correspond to your HDD directory path that point to .stayawake file (you have to create an empty file called .stayawake first).

2 Likes

+1, this is the best approach I’ve tried ever since.

Thanks for the idea. It was the only thing that worked.
Note hd-idle -i 0 does not work at all.
and for my Toshiba USB drives, hdparm -S 0 or -B 255 do not work, nor does sdparm or smartctl.

I have created the script like this so that I don’t have to add in new paths when I make more mount points / add more drives:

[root@fedora plots]# pwd
/mnt/plots
[root@fedora plots]# ls -l
total 32
-rwxr-xr-x. 1 root root   98 Jun 21 23:15 stayawake.sh
drwxrwxrwx. 3 carl carl 4096 Jun 22 01:46 toshiba_4tb_usb_10
drwxrwxrwx. 3 carl carl 4096 Jun 22 15:19 toshiba_4tb_usb_11
drwxrwxrwx. 3 carl carl 4096 Jun 22 13:18 toshiba_4tb_usb_12
drwxrwxrwx. 3 carl carl 4096 Jun 21 23:12 toshiba_4tb_usb_13
drwxrwxrwx. 3 carl carl 4096 Jun 21 23:12 toshiba_4tb_usb_14
drwxrwxrwx. 3 carl carl 4096 Jun 21 23:12 toshiba_4tb_usb_15
drwxrwxrwx. 3 carl carl 4096 Jun 21 23:12 toshiba_4tb_usb_9
[root@fedora plots]# cat stayawake.sh
#!/bin/bash
paths=`ls -d /mnt/plots/*/`
for path in ${paths[@]}; do
        touch $path/.stayawake
done

[root@fedora plots]# cat /var/spool/cron/root
* * * * * /mnt/plots/stayawake.sh

1 Like

Would this work in sudo crontab -e or does it need to be in the users crontab?

This will work in crontab -e.

When I run the command outside of crontab -e I get Permission denied. Makes me wonder if it is working in crontab -e

$ /bin/touch /media/user/ch1-010/.stayawake
/bin/touch: cannot touch '/media/user/ch1-010/.stayawake': Permission denied

crontab -e modifies your user crontab, i.e. it runs any commands as the same user as the one you configured crontab with. If that user doesn’t have write access to the drive (which it sounds like is the case based on your inability to perform touch /media/user/chi-010/.stayawake), then it is failing when run from cron. You can check your logs to see if this is the case.

If for some reason you’ve set permissions on your drive to exclude your user account from writing, then you’d have to use the crontab of a user with write permission. Assuming your root account has permission, then sudo crontab -e should do the trick. Alternatively you could change the owner of the directories serving as mountpoints for your plot drives to be your user, eliminating the need for sudo
altogether when performing any plot disk management.