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