Using hdparm to reduce HDD load/unload cycles on Windows system.

I don’t know how I managed to survive in those good old days before 2012. I somehow used HDDs but did not have any troubles with them.
Those HDDs were mostly 3.5″ desktop drives and apparently they did not possessed those perverted notion of power saving that is so common now, especially among laptop drives. Those disks spun all the time if you disabled their suspension in Windows power settings, they didn’t park heads and worked up to 10 years.

I even had a laptop with one slow HDD about 320GB capacity, manufactured somewhere in 2007-2009. It was a single and therefore system drive and I didn’t have any problems with it though I didn’t look into its SMART either.
Perhaps, I would have peek at its SMART if I had any annoyances but there weren’t any. That disk is still alive, by the way, and still works.

My life suddenly and tragically changed somewhere in the fall of 2012. I decided to replace the disk, mentioned above, on a 500GB 7200rpm Hitachi. I’m not quite sure, but I suppose it was Hitachi Travelstar Z7K500 HTS725050A7E630.
Being installed into my laptop as the only one drive it began to click once in 1-2 seconds. It did not click all the time but when the system was idle, as I remember. I noticed this only about a week later when I became interested – what does it click in my room at night.
By this time I already had 12000 load/unload cycles in SMART. This is how I became aware of the problem of excessive heads parking.

I couldn’t solve this problem using Windows settings and the usage of hdparm or other tools, able to set APM, seemed too difficult to me so with some luck I found a new firmware for my HDD.
I wasn’t the only one who got a headache with this drive (no pun intended). Many people who had bought it later complained on the Internet about the clicking noise and high value of load/unload counter. One of those people managed to get somewhere on a Chinese forum a patched version of Hitachi Feature Tool which was capable to disable heads parking completely. By that time Hitachi Feature Tool was already abandoned software and didn’t support my drive, that is why a patched version was needed.
Again, I’m not sure, but it seems that I used this particular version: HitachiFeauturetool_217b1.zip.

I was intrepid and flashed this patched firmware into my drive…
Operation was completed almost successfully and I got the disk which didn’t park its heads at all.
The only problem I got with the new firmware was a strange behavior of the “RAW READ ERRORS” SMART counter. This counter is constantly and rapidly increasing since. Overflows and increasing again.
This behavior leads to warnings from various diagnostic tools but haven’t caused any actual data loss or performance degradation.
This disk is still alive and is being used by my friend.

That was my first experience with heads parking problem and it had been solved in a very uncommon way. This method scarcely can be reproduced with other drives.

A few years later I got a laptop (Lenovo x240) into which two disks could be installed – M.2 2242 and conventional 2.5″ SATA disk.
I used Windows 7 then and tried very hard to find a way to use 2.5″ internal drive as a portable one – i.e. to switch it on and off by will.
I couldn’t find convenient and reliable way to do it.
The overall impression that I had got from my attempts could be well conveyed by this cite from one of the Microsoft’s forums.

“In XP, if the drive was online, and you set the power plan to turn off the drive after five minutes, and then you turned the drive offline, it would turn off after five minutes, but it would turn back on every time Windows scanned the bus again (every 30 minutes or so). The result would be the drive would spin down and spin up and spin down and spin up until it would spin no more.”

This quote explains why you cant turn off (park heads and spindown) your HDD on Windows but I also couldn’t find a way to adjust the timeout for heads parking. They either parks after 2-5 seconds or not at all…

The only way I could predictably use my HDD on Windows 7 was to disable power-saving features of the drive completely so it won’t park heads or spindown without corresponding ATA commands.
I believe that constantly flying head won’t impose any additional danger for HDD in case of a sudden jolt because Lenovo x240 has very sensitive Active Protection System which parks heads at slightest laptop movement (similar system on DELL laptops is far less sensitive in my opinion).

The other point to be considered is the excessive wear of the head itself in case it is flying all the time.
I couldn’t find any documents or even thoughts on this matter on the Internet but I didn’t notice such a problem among my disks, though I have only a few.
Last disk that died in my PC during startup was an old 3.5″ 250GB Seagate. It had over 8 years uptime and about 1000 head load/unload cycles.
I also have a 2.5″ HDD on my server which works well, has 3.7 years “Power_On_Hours” and 3000 load/unload cycles.

We’re slowly getting to the point of this post 🙂

Because of a number of bugs and inconveniences in Linux GUI I usually use Windows system. So I had to fight this problem on Windows 7/10.
From various articles on the Internet and my own experience I ended up using this way:
1) install hdparm for Windows
2) remove unsolicited *.bat files which it creates in the system autoload folder
3) Reboot. At least to check that you removed all batch files from (2)
4) take ownership of hdparm folder (usually C:\Program Files (x86)\hdparm. I prefer to do it for easy management and logging)
5) move or remove example *.bat files from hdparm’s foldes so they won’t distract you
6) use command prompt or PowerShell with administrative privileges to execute a couple of commands to find out which name your drive has for hdparm:

cd "C:/Program Files (x86)/hdparm/"
hdparm.exe -I /dev/sda
hdparm.exe -I /dev/sdb
hdparm.exe -I /dev/sdc

etc
The example above is for legacy command prompt, in case of PowerShell you should add ./ before program name i.e. ./hdparm.exe -I /dev/sda
From this output you should recognize the drive you want to manage and remember its path – for example let it be /dev/sdb.
7) based on the results obtained from (6) you should write a windows batch script which would set appropriate parameters for your disk using hdparm.
Simplest example:

"C:\Program Files (x86)\hdparm\hdparm.exe" -B 254 /dev/sdb
"C:\Program Files (x86)\hdparm\hdparm.exe" -S 0 /dev/sdb

The explanation of various hdparm options see here.
8) You should create a Windows Scheduler Task which would run your batch file each time your computer is starting or waking up.
It is also better to make this task recurrent somehow – either by adding “repeat every X hours” option to the Startup or Wakeup triggers or to create a separate “On schedule” triggers to run the task once in a few hours because HDD may reset its own settings sometimes.

To add this Task open Control Panel -> Administrative Tools -> Task Scheduler
Select Task Scheduler Library on the left.

Right click on the central frame -> Create New Task
On the General tab give Task a name, make it run with highest privileges as a SYSTEM

On the Triggers tab add at least two triggers to run your script – “Begin the task at startup” and “Begin the task on a event”.


The latter must be the system-log event Power-Troubleshooter ID 1 which is resume from suspend.
You might add some recurrence to these triggers as I did for my ST1000LM035-1RK172 which tends to forget its settings quickly.
Or you might just add a daily “on a schedule” trigger if your disk is behaved well enough. Just to ensure its loyalty…
On the Actions tab you should point to your batch file.

On the Conditions tab do not forget to remove a notch to allow your task to run on battery power.

Since that you and your HDD should live happily. Disk shouldn’t park heads or spin down anymore.
But there is a little subtlety…

It is known that on Linux systems non-persistent device paths can alter after each boot though I never saw that for internal hard drives.
Surprisingly (at least for me) it could happen on Windows too!

I used hdparm (Windows 7) on my Lenovo x240 for a couple of years without an issue, but then I reinstalled OS (Windows 7 again).
I copied my old *.bat file to the new installation and didn’t even bothered to check how it worked.
After about a week I noticed a muffled clicking sound…
I didn’t believe…
I thought it is impossible and didn’t pay close attention for several days…
When I finally checked SMART on this laptop – there were 13k load/unload cycles instead of ~1k

How could that be? Primary HDD became /dev/sdb!

Ok, I had changed the *.bat file and clicking sound ceased. It happened in late spring of 2018. I’ve been checking that drive since and everything was well. The laptop had been rebooted at least two times and worked without an issue until…
Until I’ve heard those familiar clicking sound again at the end of the year 2018.

The former /dev/sdb became /dev/sda again!
I’m not quite sure, but apparently it happened after suspend.
This is how I got 25k load/unload cycles…

That is why I propose to slightly change the typical contents of the *.bat file to address this issue.
My solution isn’t very elegant, but I propose to check the correctness of the device path each time the script is being run.

1) make the list of possible device names on your system
2) use command hdparm.exe -I /dev/sdx to find a substring that will help to discern the needed device i.e. HDD’s serial number or model name.
3) before setting APM – check the names form (1) against (2)

Example:

@echo off
set LOGFILE="c:/program files (x86)/hdparm/hdd.log"
echo: >> %LOGFILE%
echo %DATE% %TIME% >> %LOGFILE%
 
FOR %%G IN (/dev/sda,/dev/sdb,/dev/hda,/dev/hdb) DO (
 
    "c:/program files (x86)/hdparm/hdparm.exe" -I %%G | find /i "ST1000LM035-1RK172" > NUL
 
    if not errorlevel 1 (
        echo %%G is our disk >> %LOGFILE%
        "c:/program files (x86)/hdparm/hdparm.exe" -B 254 %%G >> %LOGFILE%
        echo: >> %LOGFILE%
        "c:/program files (x86)/hdparm/hdparm.exe" -S 0 %%G >> %LOGFILE%
        exit 0
    )
)

With long enough list of the possible device names, I hope this script will help to circumvent sudden changes in device path – this is what I meant to say by this article.

This is slightly irrelevant, but I also thought about more elaborate script which would spin down HDD in case of a long standby time of the PC.
So HDD wouldn’t spin at night or when nobody is at home.
This script would be run by Task Scheduler each hour, but only in case of PC’s idle time more than a certain threshold (Task Scheduled allows to do that).
And script itself would check which programs are running so it won’t stop HDD if, for example, uTorrent is active.
The sketch of the script is listed below though I never tried to use it actually.

@echo off
set LOGFILE="c:/program files (x86)/hdparm/hdd.log"
echo %DATE% %TIME% >> %LOGFILE%
"c:/program files (x86)/hdparm/hdparm.exe" -C /dev/sdb | find /i "active/idle" >NUL
 
if not errorlevel 1 (
    echo "disk is active"  >> %LOGFILE%
    tasklist | find /i "utorrent.exe" >NUL
    if not errorlevel 1 (
        echo "utorrent is working"  >> %LOGFILE%
    ) else (
        echo "utorrent is absent, issuing standby command"  >> %LOGFILE%
        REM "c:/program files (x86)/hdparm/hdparm.exe" -B 254 /dev/sdb
        REM "c:/program files (x86)/hdparm/hdparm.exe" -S 0 /dev/sdb
        REM "c:/program files (x86)/hdparm/hdparm.exe" -y /dev/sdb
    )
 
) else (
    echo "disk already in standby mode"  >> %LOGFILE%
)

A couple of words about Linux.
Linux so far is significantly better in this matter. It allows (with some restrictions) to use an internal hard drive as a portable one.
Particularly I’ve been using this script for considerable period of time on LinuxMint Cinnamon without an issue:

#! /bin/bash
 
if [[ $(/sbin/hdparm -C /dev/sda | grep active) = *active* ]]; then
    if ! mountpoint -q "/media/DATA"; then
        #date >> /opt/hddcheck.log
        #echo "DATA is not a mountpoint, but disk is active - issuing standby command" >> /opt/hddcheck.log
        /sbin/hdparm -y /dev/sda > /dev/null
    fi
fi

Script is run by cron once in 2-5 minutes.
If I’m using HDD and therefore have mounted it – script does nothing.
If I do not use the disk and therefore unmounted it – script issues standby command so disk parks heads and spins down.
Mounting/unmounting could be done with file manager.

This script was accompanied by the other which set correct APM values time after time.

#! /bin/bash
 
if [[ $(/sbin/hdparm -C /dev/sda | grep active) = *active* ]]; then
    /sbin/hdparm -B 255 /dev/sda
    /sbin/hdparm -S 0 /dev/sda
fi

Boot-time initialization could be done in a similar makeshift way also, but I used hdparm settings in /etc/ for this purpose.

This worked well for me for a long period of time and I liked Linux for the opportunity to use my HDD in such a manner.
Unfortunately, by the end of 2018 I began to face some problems on Kubuntu 18.04
– I noticed that unmounted and stopped HDD begins to spin up if I connect any external storage to the laptop. It can be USB flash drive or even a phone over MTP. It is very disappointing. I didn’t notice such behavior earlier but maybe I was just inattentive.
– The mountpoint command not always worked if the path that is being checked was not in fstab. I’m not quite sure about this because I have no time to investigate.
Perhaps, it has to do with the way I mounted my disk – I used file manager.
– The Dolphin file manager handles directory mounting very ugly if you created a directory for mounting beforehand. It mounts all that I need but gives a couple of error messages and forces me to do a couple of redundant clicks.

I hadn’t time to investigate this thoroughly. I became tired of inconsistency and constant changes in Linux again and switched to Windows 10… So, maybe next time…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code