All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Setting apm and spindown time out on usb hard disk
PostPosted: February 10th, 2021, 10:44 
Offline

Joined: February 10th, 2021, 6:52
Posts: 2
Location: Italy
Hi,
I have two external usb hard drives (a wd elements (WDC WD10SDRW-34A0XS0) and a toshiba canvio basic (MQ04UBF100)) that I use mainly to store data to which I access rarely during the day. The pc stays on for even 7-8 hours consecutively and so even the hdd, but since I don't execute programs on the hdd (there aren't any program installed on them and the programs I use don't access any file on the hdd, I just need to read/write some file every now and then (let's say 15-30 minutes)) they go in hibernation and wake up a lot of time during the day causing a lot of head parking and spinning down. As far as I know, I think that an hdd suffer more from continuously spinning up and down rather than keep spinning even in idle.

I use ubuntu on my pc and I discovered hdparm making some research on the net, it should modify the parameters I'm interested in:
-apm (advanced power management), the algorithm that determines how the hdd behaves until the spindown time out (https://bbs.archlinux.org/viewtopic.php?id=216832): "hdparm -B <num> /dev/sdX"
-spindown time out, the amount of time after which the hdd goes in hibernation: "hdparm -S <num> /dev/sdX"

The problem is that I can read the apm with hdparm, but when I set the two parameters they aren't respected by the two drives (even if the command has been executed without errors).
The second problem is that I would like to run selftest on them (using smartctl from smartmontools) regularly, but the long selftest fails because the disks go in hibernation since there isn't any I/O.
So I made some experiments and this is what I've discovered.
I made these experiments with four disks: the two usb disks (the wd usb and the toshiba usb above mentioned) and two other sata drives from two laptops (a seagate momentus thin and a wd scorpio blue). For the two sata drives I've used two different sata to usb adapters (one of which is a sabrent).

I tried to run a long selftest on the toshiba usb, but it fails because the drive goes in hibernation after 3 minutes and the selftest is automatically aborted. I've also made a long selftest on the wd usb, even this drive can't make it because it goes in hibernation after 30 minutes.
The thosiba usb has a few reallocated sectors, but zero uncorrectable sectors. The short self test fails due to a read error (always on the same LBA). The wd usb is in perfect health: the smart parameters are perfect and the short selftest are successful.
I checked the smart parameters because I thought that maybe I couldn't interact with the firmware of the toshiba because it was close to a break, but I'm sure this isn't the solution.

This is what I tried with hdparm and the usb disks.
Both on the toshiba usb and the wd usb if I run "hdparm -S 6 /dev/sdb" (which should set the spindown time at 30s) there are no changes, they keep going in hibernation with their default time. I want to point out that the command are executed always without error. Nothing changes even if I run "hdparm -B 254 /dev/sdb", which should set the apm for the maximum performance and the lowest power saving (with values under 128 the spindown is permitted while with values higher than that it's not permitted until the spindown time out). I tried also with 255 which should disable the apm, even if the man pages of hdparm say that not all the disks support disabling it (though nothing changed).

Whereupon I made the same things with the sata drives connected with the pc via the two adapters (I don't have a desktop pc but only laptops).
There first adapter is just disgusting. I can mount the two drives and read/write files with it, but nothing else. If I try to run "smartctl -a /dev/sdb" (to get the smart parameters) the prompt is hold for about 1.5m and then (maybe a timer expires or something) the program exits without printing any parameters. If I try to run "hdparm -S 6 /dev/sdb" or "hdparm -B 254 /dev/sdb" it happens the same thing. But I still can read the apm value with "hdparm -B /dev/sdb".
Let's move on to the second adapter. It works better because I can read all the smart parameters. But if I try to change the apm value with "hdparm -B 254 /dev/sdb" or the spindown time out with "hdparm -S 6 /dev/sdb" it succeed (even if their values are ignored as with the usb drives) but the following error is printed (with both disks and both commands): "SG_IO: bad/missing sense data, sb[]: 70 00 01 00 00 00 00 0a 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00". With the seagate sata once I also got this error trying to set the spindown timeout: "HDIO_DRIVE_CMD(setidle) failed: Invalid argument".
I made some research on the net about these errors, but I didn't find anything interesting. They were all related to the secure erase of ssd or to the creation of a password for the ssd (both with hdparm).

So the following are the partial conclusion I managed to get until now, I hope you guys can help me to figure out something more about this.
At this point I think that it's just not possible to interact with the firmware of usb drives (either pure usb drives or sata drives with an usb adapter). Maybe if I could connect a sata drive directly to the sata port on the motherboard I could change these values with hdparm.
Maybe this is due to the fact that the usb controller of the adapter is not made to translate the ata command from usb to ata. Or maybe you can't even send these commands through usb. The last guess is also reinforced because I doubt that the usb drives have an ata controller. I opened one of them and I saw that the micro sub 3.0 is directly soldered on the board, maybe the firmware of those drives is made just to communicate through usb and it's not meant to accept every ata or scsi command at all.

The only workaround it came to my mind to avoid the disks from going in hibernation is to create a simple script that writes the current data on file in the hdd every a certain amount of time (2.5m on the toshiba usb and 29.5 on the wd usb). In this way the disk has a continuous I/O operations and it doesn't go in hibernation, moreover this shouldn't cause a great fatigue to the disk.

I've also used these disks with windows and I remember I could avoid them from going in hibernation from the device manager by unchecking the checkbox of the device which says "allow power saving" (a curious thing is that the drives weren't shown as usb hard disks but as external usb mass storage).
At this point I have only two hypothesis: either there are some proprietary driver for windows to interact with the hdd firmware via usb, or windows creates a temporary file where it writes/reads stuff regularly to avoid the hibernation of the disk. The latter hypothesis is very reasonable. When I left checked the checkbox of the power saving feature, the two drives went in hibernation after that amount of time (the same both in windows and ubuntu) and if I ever wanted to safely remove the drives I could without any problem. If I unchecked that checkbox, the drives wouldn't go in hibernation but I hardly managed to safely remove them (because I got the warning that some files on the disks where opened by a program, like 3 times out of 5). I was absolutely sure that there weren't any opened program both on the desktop and in background, so I thought it was a windows service. I installed LockHunter (a program to understand which files/folders are blocked and by which program) and I discovered that the root of the disk was occupied by the windows file manager and sometimes by windows defender (even though I had completely disabled it from the system registry).
So I would say that there is no way to interact with the firmware of the usb hdd and that even windows uses a workaround like the one I use.

So after this huge wall of text I wrote, I underline my questions:
-Is there a way / is it possible to interact with the firmware of hard disks via usb (both usb disks, sata disks and sata disks plus adapter)? Is it possible to modify even just the apm and the spindown time out in some way?
-Are there any usb hard disks that allow to interact with their firmware? Or even adapters that can translate the command from usb to ata? To be precise I need a disk which support sat (scsi-ata) translation (https://en.wikipedia.org/wiki/SCSI_/_ATA_Translation). On the man pages of hdparm there's written that most of the disks made after 2008 are compatible, but from my experience either I had tons of bad luck buying two hdd in a row which doesn't support it or maybe it's not that common (or maybe I just didn't understand anything and I'm getting everything wrong)
-Has someone of you ever tried to do similar stuff with hdparm on sata or usb hard drives? Did you manage to make it work?


Top
 Profile  
 
 Post subject: Re: Setting apm and spindown time out on usb hard disk
PostPosted: February 28th, 2021, 18:54 
Offline

Joined: August 13th, 2016, 17:10
Posts: 197
Location: Vienna, Austria
I am using hdparm -S 10 /dev/sda to automatically spindown my drives


Top
 Profile  
 
 Post subject: Re: Setting apm and spindown time out on usb hard disk
PostPosted: February 28th, 2021, 18:56 
Offline

Joined: August 13th, 2016, 17:10
Posts: 197
Location: Vienna, Austria
For USB adapters, you have to look for ones that support the UASP protocol.


Top
 Profile  
 
 Post subject: Re: Setting apm and spindown time out on usb hard disk
PostPosted: March 1st, 2021, 17:31 
Offline

Joined: February 10th, 2021, 6:52
Posts: 2
Location: Italy
sourcerer wrote:
For USB adapters, you have to look for ones that support the UASP protocol.

For the sata drives I've used this adapter
https://www.amazon.it/dp/B011M8YACM/ref ... UTF8&psc=1
It should support uasp, but I couldn't get hdparm to work


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: Google Adsense [Bot], MSN [Bot] and 154 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group