Prevent External USB HDD Disk Sleeping

I realized that my external disk (western digital 8tb) sleeps after a while when there is no activity on disk.

i’m wondering if this is a problem for farming?


How can i prevent my external disk for sleeping in ubuntu desktop 20.04?


1 Like

Yes, long wakeup time will be very bad for harvester proof times, which must be under 30 seconds, and are “supposed to be” under 5 seconds.

It’s kind of janky but use this KeepAliveHD program in Windows… I have it set to write a file every 60 seconds to the drive, then delete it.

I assume there are similar programs or scripts for Ubuntu.

I initially had it reading a file every 30 seconds but that actually wasn’t working; I could hear one of the external drives, which I had read set on, waking up from time to time!


it seems you have found a working solution for you which is cool.

I’m looking for alternatives for ubuntu :frowning:

1 Like

You could easily write a small shell script to copy and then delete a small file to your external HDD and setup a cron job to execute that script every 30 seconds


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.


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?

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.


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.


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.


does it solves same problem for seagate external hdds?

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


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).


+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
[root@fedora plots]# ls -l
total 32
-rwxr-xr-x. 1 root root   98 Jun 21 23:15
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
paths=`ls -d /mnt/plots/*/`
for path in ${paths[@]}; do
        touch $path/.stayawake

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

1 Like