Author Topic: Force HDD to keep spinning  (Read 2628 times)

Offline Cobra951

  • Gold Member
  • *
  • Posts: 8,934
Force HDD to keep spinning
« on: Monday, October 27, 2008, 01:14:39 PM »
We've talked before about how some external drives spin down after a fairly short time by design, and that unfortunately some of them won't allow this behavior to be altered at all.  The WD MyBooks are notoriously bad for this, spinning down after 10 minutes of no physical disk access.  It's the physical-access requirement that makes it unacceptable.  In particular, there may be enough data cached in something that you're streaming (like music) so that the drive doesn't get hit for a read for longer than the timeout period.  This will subsequently cause an ugly break in the stream when the disk does get accessed, and has to spin back up.  This is bad for the hardware, and infuriating for the user (e.g., me).

I've searched in vain for an official or otherwise elegant solution for this.  So I spent some time on this last night and today.  After trying simple read commands like VOL and DIR, and getting nowhere (they end up cached after the first iteration), and doing some reading on flushing HDD cache, it struck me that there is no way to do this without writing to the disk.  I wanted to stay away from that on general principles, but I have not come up with something that works reliably, or with so little data having to be processed.  All it takes is copying a very small file to the drive with verify, and then deleting it.  The non-obvious part was getting the batch file to wait as long as possible between writes.  I definitely don't want to do this constantly.  That search went well.  I found out that ping works with minimum overhead for this, while an alternate method using the CHOICE batch command pegs the CPU usage.

KeepOalive.bat:
Code: [Select]
@echo off
ECHO Keep the O: drive from spinning down

:REP
copy c:\autoexec.bat o:\temp/V > NUL
del o:\temp\autoexec.bat

rem ECHO.
rem ECHO Waiting 360 seconds
rem ECHO.

@ping 127.0.0.1 -n 2 -w 1000 > NUL
@ping 127.0.0.1 -n 360 -w 1000> NUL

goto REP

The file can be anything, anywhere.  I chose c:\autoexec.bat for now because it's there and it's only 278 bytes.  (C: is my WinMe drive, though I haven't booted into Me for years.  Heh.)  The NULs prevent text writes to the console, saving a few cycles.  The /V forces a verify of the write.  The ping is bogus and will have to exit via its timeout parameter, making it a timed-pause command.  The extra ping with a timeout of 2 seconds is probably not necessary.  The site I got this wait method from said it made the pause time more accurate, but a few seconds inaccuracy here is irrelevant.  I left it in for now.

This has zero impact on performance, according to task manager.  And it works.  Yay!  I've tested it, managing to keep the offending drive spinning continuously for the better part of an hour.  It sits on the taskbar (after you minimize it) as a reminder to close it when you no longer want to force this behavior.

Anything more elegant and even less intrusive would be most welcome.

Offline WindAndConfusion

  • Veteran
  • ****
  • Posts: 1,336
Re: Force HDD to keep spinning
« Reply #1 on: Monday, October 27, 2008, 04:43:28 PM »
Have you tried touch or poke? They're Unix commands, but you can probably use them on Windows with Cygwin.

(Edit: Although I am 99% sure there exists a Unix utility called "poke" whose SOLE PURPOSE is to wake up sleeping devices, I can't seem to find it on either Google or the Wiki.)

Offline Cobra951

  • Gold Member
  • *
  • Posts: 8,934
Re: Force HDD to keep spinning
« Reply #2 on: Monday, October 27, 2008, 07:05:34 PM »
The only poke command I know of is this one.  It's a simple memory write, with the corresponding peek command for reading.  I had a touch.exe little app once that emulated the Unix command, but I've somehow lost it.  I could probably find it again if I tried, but I don't think it would be doing a whole lot less than what I am now, for this application.  It seems to boil down to a required disk write, because nothing else I've found guarantees the hardware will be accessed.  Any kind of small read will be cached across loop iterations, and a large read would be counterproductive.

I'm sure I can write some sort of script to replace this lowly batch file.  Maybe that would give me better choices, like a way to nudge the drive at a lower level.  It's something to consider.  Thanks.

Offline scottws

  • Gold Member
  • *
  • Posts: 6,602
    • Facebook Me
Re: Force HDD to keep spinning
« Reply #3 on: Monday, October 27, 2008, 07:20:19 PM »
There's an actual sleep command in the Windows 2003 resource kit.

http://malektips.com/xp_dos_0002.html

Offline Cobra951

  • Gold Member
  • *
  • Posts: 8,934
Re: Force HDD to keep spinning
« Reply #4 on: Monday, October 27, 2008, 08:28:20 PM »
I ran across that last night, while searching for such an option.  Is it worthwhile?  Can it be installed on XP without issue, including WGA?

Offline WindAndConfusion

  • Veteran
  • ****
  • Posts: 1,336
Re: Force HDD to keep spinning
« Reply #5 on: Monday, October 27, 2008, 10:17:32 PM »
Doesn't Windows have a cron-like function built in?

Well, even if it does, I still recommend Cygwin. If God wanted us to write scripts using the Windows shell, he wouldn't have invented Unix.

Offline scottws

  • Gold Member
  • *
  • Posts: 6,602
    • Facebook Me
Re: Force HDD to keep spinning
« Reply #6 on: Tuesday, October 28, 2008, 06:15:28 PM »
Cobra: I would think so.  It is probably just an exe but I'll look into it tonight. 

It is interesting... even MS suggests using ping as a pseudo wait command.
Wind: Have to messed with PowerShell at all?  It's very similar to Linux command line and scripting although I find it to be much more wordy.

Offline scottws

  • Gold Member
  • *
  • Posts: 6,602
    • Facebook Me
Re: Force HDD to keep spinning
« Reply #7 on: Tuesday, October 28, 2008, 08:00:27 PM »
Cobra:

http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en

You can download the Windows 2003 Resource Kit without having to deal with WGA.  There is a sleep.exe file included.  I'm sure it would run fine on XP.

Offline Cobra951

  • Gold Member
  • *
  • Posts: 8,934
Re: Force HDD to keep spinning
« Reply #8 on: Wednesday, October 29, 2008, 02:50:09 PM »
Thanks!  I read that page, and there seems to be some other useful stuff there too.  I downloaded the kit, though I have not yet installed.  What surprised me the most while I was working through my problem was that the internal batch command CHOICE pegs the CPU, while the ping hack has negligible impact on performance.  I'll have to see how the SLEEP command fares in this respect.