Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: [SOLVED] Second disk not automatically going to sleep (Read 1551 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

[SOLVED] Second disk not automatically going to sleep

For anyone who reads later, gnome-disk-utility has a GUI does all that, I guess. In options somewhere, just poke around it.

It always works even when I don't use it, which I don't mostly. The thing is, I removed my DVD-RW and instead I put this caddy hdd box thing instead. It's good but it's working for nothing even when I don't use it for a long time. I hear and sense the hdd spinning for nothing. Since I use a laptop, and this drains unneccessary power, it's kinda important I suppose.

And also, I want it to sleep by default at startup. I only use it occasionally. Can you help me at this?

Re: Second disk not automatically going to sleep

Reply #1
There's a hdparm init script for all our inits: hdparm-{openrc,runit,s6}. Get it, edit its config to point at your disk(s) and enable it.

Re: Second disk not automatically going to sleep

Reply #2
There's a hdparm init script for all our inits: hdparm-{openrc,runit,s6}. Get it, edit its config to point at your disk(s) and enable it.

Wow, terrific! It makes battery life much higher! Soo, how to make this permanent at each boot? Like this: sudo hdparm -B 1 -S 7 /dev/sdb
But everytime and always? I use openrc, I added that hdparm service and started it, but it seems it doesn't do this command at every boot. I am not quite sure but -B value must be close to zero right? To prevent it strictly from running? I guess so. And just wondering, how does more spin-down wears the drive faster? That makes no sense. It's an engine after all and I am an engineer so.. Less usage means better life imo.

 

Re: Second disk not automatically going to sleep

Reply #3
I didn´t know about the init script. So I put the command in rc.local to get it started at every boot.

Code: [Select]
/usr/bin/hdparm -B 255 -S 30 /dev/sdb"

-B 255 disables the automatic powermanagement of the disk. I do this because some Western Digital HDDs are parking the heads of the disk after 8 seconds not in use. Disabling the powermanagement of the disk prevents from this.
-S 30 send the disk to standby after 150 seconds (30x 5 seconds) not in use.

In fstab I use the option noauto. The disk spins only up if opened in the file explorer.

Re: Second disk not automatically going to sleep

Reply #4
I didn´t know about the init script. So I put the command in rc.local to get it started at every boot.

Code: [Select]
/usr/bin/hdparm -B 255 -S 30 /dev/sdb"

-B 255 disables the automatic powermanagement of the disk. I do this because some Western Digital HDDs are parking the heads of the disk after 8 seconds not in use. Disabling the powermanagement of the disk prevents from this.
-S 30 send the disk to standby after 150 seconds (30x 5 seconds) not in use.

In fstab I use the option noauto. The disk spins only up if opened in the file explorer.

What's this rc local, please explain. I don't have any files like this. I thought of sessions and startup but sudo commands don't work there.

Re: Second disk not automatically going to sleep

Reply #5
English isn´t my native language so I hope I can explain it correctly and understandable.
I use Artix Plasma with OpenRC. The file rc.local is located in /etc. At sytsem start It´s called by /etc/local.d/local.start. If you put the hdparm command in rc.local it will be executed at boot.

Re: Second disk not automatically going to sleep

Reply #6
@katinka, I studied this question some time ago, it is part of the SMART functionality of the HD, and this is the solution that I find (I no longer use it now cause I replaced all the HDs with SSDs; only the backup disks are yet HD).

The steps to do are:

1) to install hdparm, but you have
2) to create the file /etc/udev/rules.d/50-hd-parm.rules with these commands (I specified a line for every HD installed inside or connected via USB at my notebook):
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sda", RUN+="/usr/bin/hdparm -B 255 -S 0 /dev/sda"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sdb", RUN+="/usr/bin/hdparm -B 254 -S 0 /dev/sdb"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sdc", RUN+="/usr/bin/hdparm -B 254 -S 0 /dev/sdc"
ACTION=="add", SUBSYSTEM=="block", KERNEL=="sdd", RUN+="/usr/bin/hdparm -B 254 -S 0 /dev/sdd"

With this command all start automatically when you boot. Obviously you con modify the -B and -S parameter to the value that you prefer.
You have to evaluate the -B parameter cause not all the HD are compatible with -B 255 and sometime is better to use -B 254.

Francesco

Re: Second disk not automatically going to sleep

Reply #7
Yes @francesco , I remember I used this in Void Linux. Maybe the more elegant solution.

Re: Second disk not automatically going to sleep

Reply #8
@katinka, if you are interested, I wrote also a small script, just to apply the parameters at a USB connected HD, without to have to define it in udev, If you want I can post it.

Ciao. Francesco

Re: Second disk not automatically going to sleep

Reply #9
Sure, that´s interesting @francesco and maybe not only for me. I would appreciate it very much.

Re: Second disk not automatically going to sleep

Reply #10
This is the description of the script.

The last generation SMART HDs, have a “strange” function that can make their life short. Its something that we can avoid, to offer a longer life at our HD. Why not to do?

Here you can find where I take the idea for this script:
https://classicforum.manjaro.org/index.php?topic=17890.014
so: thank you Skully!

For Western Digital HD, internal or external, you find, in the previous link, the description of how to apply the patch to correct the problem of your Green Western Digital HD (also some Blue models). Western Digital report, also, in their website, the ID of the HDs that may need the patch, but I don’t remember where I read the info. DuckDuckGo can help you  ;)

But there are also other HDs with the SAME problem. I discover that some Seagate, Hitachi, Samsung too implement the same SMART parameter and, to avoid to kill my HDs, both internal and external, I started to manually use the hdparm command to disable this not so SMART functions.

The “evil” is <193 Load_Cycle_Count> SMART capabilities of some modern HDs: this functionality KILL the HDs.

For non WD hd, you can disable it, for the internal HD, creating the file /etc/udev/rules.d/50-hdparm.rules
with the command line:

ACTION=="add", SUBSYSTEM=="block", KERNEL=="sdX", RUN+="/usr/bin/hdparm -B 255 -S 200 /dev/sdX"

NOTE: change sdX with the name of your device

BUT, with this command``

you cannot disable 193 Load_Cycle_Count for the HDs attached via USB.

This trivial script try to give you an “almost” automatic solution to disable the 193 Load_Cycle_Count using the hdparm command. You can install it with: sudo pacman -S hdparm

Please, before to use the command read this post with care: https://classicforum.manjaro.org/index.php?topic=17890.014
install also the smartmontools and read also the hdparm man page!

NB: the -B 255 parameter is not usable with all the HD, try it manually before to set it in the script and consider that almost all the HD, with SMART capability, support the -B 254

STEP 1
Connect the HDs at your PC and, with the command lsblk --output kname,serial display the serial number.
With a text editor create the file EPattern.txt and past the serial number, previously displayed, of the HD that you want to attach at your PC. Specify a serial number in every line: only the serial number. This will became the “DB” of your HDs.

When done you are ready to launch the script (see below), when you attach a USB HD, to disable the 193 Load_Cycle_Count function and to care your HDs.

If you’ll find this script useful, I’ll do the next steps to add more functionalities and to make the script more useful:

STEP 2

To parametrize the script adding, in the EPattern.txt, the command line specific for every HD.

STEP 3
Probably the more simple.
When all the previous steps will be done and tested, to launch automatically the script every time that an external HD is attached to the PC.

Every advice is accepted!

Below the script that you can use. Don’t forget to make it “executable”

#!/bin/bash
# Create the file with the list of all the HD/Device connected
lsblk --output kname,serial > HdSerialNumberList.txt

# create the file with ONLY the HD registered in your EPattern.txt
grep --file=EPattern.txt HdSerialNumberList.txt > TestFileHD.txt

     # read the file TestFileHD.txt and launch the commands
     while read -r line; do
         # ${line:0:3} read the first 3 characters of the line
         # exactly where I can find the sdX assigned to the HD
         # it can change every time that you connect the HD so...
         sudo hdparm -B 255 /dev/${line:0:3}; # set APM Level off
         sudo hdparm -S 200 /dev/${line:0:3}; # set stand by time at 16 minutes
     done < TestFileHD.txt

     # delete the temporary files
     rm HdSerialNumberList.txt
     rm TestFileHD.txt

     echo "===< Work done >==="

Re: Second disk not automatically going to sleep

Reply #11
Thank you very much @francesco . I´ll try it during the day.

Re: Second disk not automatically going to sleep

Reply #12
Wow, terrific! It makes battery life much higher! Soo, how to make this permanent at each boot? Like this: sudo hdparm -B 1 -S 7 /dev/sdb
But everytime and always? I use openrc, I added that hdparm service and started it, but it seems it doesn't do this command at every boot.
To make it run at every boot, you have to instruct openrc:
Code: [Select]
rc-update add hdparm
As a general rule, if there's already an init file for a daemon use that instead of editing rc.local.

Re: Second disk not automatically going to sleep

Reply #13
To make it run at every boot, you have to instruct openrc:
Code: [Select]
rc-update add hdparm
As a general rule, if there's already an init file for a daemon use that instead of editing rc.local.

Does it apply the command I wrote at start? If so, then problem solved.

Btw, gnome-disk-utility has a GUI does all that, I guess. In options somewhere, just poke around it.

Re: Second disk not automatically going to sleep

Reply #14
Thank you very much @francesco for the link to that Manjaro thread, I had a WD Green drive fail yesterday and found it a little strange as the drive has had very little use, your excellent post and link explains it all.

I have now installed the software and disabled the timer.

Cheers!