LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-04-2021, 12:12 PM   #1
Johannes33
Member
 
Registered: Jul 2015
Distribution: manjaro Xfce
Posts: 80

Rep: Reputation: Disabled
Spindown hdd after boot, tried systemd or hdparm.conf, does not work @ubuntu20.04


Hi, I'm trying to get my hdd:s to spin down after boot. Arch Linux wiki suggest using systemd:

Quote:
Putting a drive to sleep directly after boot

A device which is rarely needed can be put to sleep directly at the end of the boot process. This does not work with the above udev rule because it happens too early. In order to issue the command when the boot is completed, just create a systemd service and enable it:

/etc/systemd/system/hdparm.service
Code:
[Unit]
Description=hdparm sleep

[Service]
Type=oneshot
ExecStart=/usr/bin/hdparm -q -S 120 -y /dev/sdb

[Install]
WantedBy=multi-user.target

After that I make the service start after every reboot by:

Quote:
$ sudo systemctl enable hdparm.service
That did not work. Does anyone know what is wrong?


Then I edited the settings file /etc/hdparm.conf. In the end I appended

Code:
/dev/sda {
          standby
          quiet
          spindown_time = 24
      }

/dev/sdb {
          standby
          quiet
          spindown_time = 20
      }
It did not work. I also tried to put standby at the end, i.e.:

Code:
/dev/sdb {
          quiet
          spindown_time = 20
          standby
      }
but it did not work either. Does anyone know what is wrong?

The only thing that works is to type in the terminal:
Quote:
$sudo hdparm -S 1 /dev/sda
@ubuntu 20.04

Last edited by Johannes33; 09-04-2021 at 12:15 PM.
 
Old 09-04-2021, 04:19 PM   #2
Rickkkk
Senior Member
 
Registered: Dec 2014
Location: Montreal, Quebec and Dartmouth, Nova Scotia CANADA
Distribution: Arch, AntiX, ArtiX
Posts: 1,364

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Hi Johannes33,

Are you trying to spin down /dev/sda or /dev/sdb ( ... or both ... ) ? I ask because your systemd unit addresses /dev/sdb but your manual example addresses /dev/sda.

Thanks,

Rick
 
Old 09-04-2021, 06:03 PM   #3
Johannes33
Member
 
Registered: Jul 2015
Distribution: manjaro Xfce
Posts: 80

Original Poster
Rep: Reputation: Disabled
To be clear this problem I'm having is on a ubuntu 20.04 installation.
I used Arch wiki becuase their wikis are very good sources of information on linux.

Both,
The references on just one drive are just because I was to lazy to write out for both.

e.g.
this is hdparm.service
/etc/systemd/system/hdparm.service

Code:
[Unit]
Description=hdparm sleep

[Service]
Type=oneshot
ExecStart=/usr/sbin/hdparm -q -S 120 -y /dev/sdb
ExecStart=/usr/sbin/hdparm -q -S 120 -y /dev/sda

[Install]
WantedBy=multi-user.target
and this is my appended bit in /etc/hdparm.conf
Code:
/dev/sda {
          standby
          quiet
          spindown_time = 24
      }

/dev/sdb {
          standby
          quiet
          spindown_time = 1
      }
Currently the hdparm.conf is inactivated and I have focused on systemd.

when checking on the systemd service I get:

Quote:
$sudo systemctl status hdparm.service
hdparm.service - hdparm sleep
Loaded: loaded (/etc/systemd/system/hdparm.service; enabled; vendor preset>
Active: inactive (dead) since Sun 2021-09-05 01:31:02 CEST; 49s ago
Process: 997 ExecStart=/usr/sbin/hdparm -q -S 120 -y /dev/sdb (code=exited,>
Process: 1427 ExecStart=/usr/sbin/hdparm -q -S 120 -y /dev/sda (code=exited>
Main PID: 1427 (code=exited, status=0/SUCCESS)

sep 05 01:31:00 johlux systemd[1]: Starting hdparm sleep...
sep 05 01:31:01 johlux hdparm[997]: issuing standby command
sep 05 01:31:02 johlux hdparm[1427]: issuing standby command
sep 05 01:31:02 johlux systemd[1]: hdparm.service: Succeeded.
sep 05 01:31:02 johlux systemd[1]: Finished hdparm sleep.
but no spindown is done.

If I try in a terminal:

Quote:
$sudo hdparm -q -S 120 -y /dev/sda
issuing standby command
$sudo hdparm -q -S 120 -y /dev/sdb
issuing standby command
It works. what can be wrong?

Last edited by Johannes33; 09-04-2021 at 06:42 PM.
 
Old 09-04-2021, 07:15 PM   #4
Rickkkk
Senior Member
 
Registered: Dec 2014
Location: Montreal, Quebec and Dartmouth, Nova Scotia CANADA
Distribution: Arch, AntiX, ArtiX
Posts: 1,364

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Here's a guess (and I mean that - I'm really not sure what is going on) ...

The return from your systemctl status request shows that the service started (executed) without error. However, it is not active (this would seem to me to be normal, since it is a "one-shot" service). And you say the disks are not "spinned down". Is it possible that since the service executed that some process required the disks and they resumed normal operation ? From my understanding, with a -S value of 120 (600 seconds), you are specifying that the disks should power down after 10 minutes of complete inactivity (no disk access required).

When you execute the hdparm command directly, you say the result is what you expect. Do you mean that 10 minutes after you issue the command, if no other process requires access to the disks, that they power down ? Do you get the same result from starting the systemctl service ?

Code:
sudo systemctl start hdparm
You may see where I'm going here ... I'm wondering whether the behaviour here is simply what should be expected. Perhaps you could elaborate a bit on your objective.

Rick
 
Old 09-05-2021, 12:17 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Most important question:
Are the disks in question in use? If they are, they will only spin up again, and what you do is actively harmful to them. You should just trust the OS to make the right decision. Usually the hard drives are set to spin down anyhow after they haven't been in use for some time.

If they definitely aren't in use, the problem might be with the timing of the systemd.service - maybe it does what it should, but then some other systemd service gets access tot he very same HD, and it spins up again.

You need to faff around with hdparm to see what is possible & what is happening, this is device specific.

Then you need to adjust the systemd.service's "WantedBy=" or "After=" lines. Archwiki has a lot of good info on writing your own systemd services.

There's more to unpack, but this should get you started.

I repeat: if the drive(s) in question are in use, you do not want to power them down all the time.
 
Old 09-05-2021, 05:26 AM   #6
Johannes33
Member
 
Registered: Jul 2015
Distribution: manjaro Xfce
Posts: 80

Original Poster
Rep: Reputation: Disabled
Hi Rickkk and thanks for your time in responding my questions.

hdparm takes a couple of arguments when executing
Quote:
$sudo hdparm -q -S 120 -y /dev/sda
-q stands for quiet as opposed to verbose, so less clutter on stdout.
-S 120 as you say defines spindown to be after 10 min. So if I access the drive it will stay spinning after idle for 10 minutes.
-y forces the drive to go into low power consumption mode, i.e. standby and hence spin down.

Hi ondoho and thanks for your input, you delviered a solution to the problem.
But to be clear, Could you explain just what it is that is harmful by spinning my disks down? In my situation I'm quite convinced there is nothing harmful in spinning down hdds that are not in use. I seldome use them since they work as backup disks only.
The OS does keep them spinning indefenately. So they are not, in my opinion, managed correctly in ubuntu 20.04.

Do you know why I do not get 120 back when executing the below or is there an other way to se time until spindown?

Quote:
$ hdparm -S /dev/sda
-S: bad/missing standby-interval value (0..255)
According to the arch wiki on hdparm, passing the command without value should query the current value.

I do not know how to see what service broke my settings from my hdparm.service. But since it was exectued after my service I changed when my service should be executed.

I did
Quote:
$sudo systemctl status *.service
and found a random service, in my case from virtual box, that started late in the boot process and used After=
Here is my updated hdparm.service which works:

Quote:
[Unit]
Description=hdparm sleep
After=vboxweb-service.service

[Service]
Type=oneshot
DeviceAllow=/dev/sda
DeviceAllow=/dev/sdb
ExecStart=/usr/sbin/hdparm -S 120 -y /dev/sdb
ExecStart=/usr/sbin/hdparm -S 120 -y /dev/sda

[Install]
WantedBy=multi-user.target
Do you know how to see what service changed my settings in the first place?

Last edited by Johannes33; 09-05-2021 at 10:25 AM.
 
Old 09-05-2021, 09:03 AM   #7
Rickkkk
Senior Member
 
Registered: Dec 2014
Location: Montreal, Quebec and Dartmouth, Nova Scotia CANADA
Distribution: Arch, AntiX, ArtiX
Posts: 1,364

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Hey again Johannes33,

Glad you got it worked out to your satisfaction. The vboxweb service just loads Virtualbox's four required drivers, if I recall, so if you run into issues with that again, you can just disable the service and load the drivers manually (or restart the service) before using virtualbox. The Arch Wiki, again, has pretty clear info on this as well.

Cheers,

Rick
 
Old 09-05-2021, 11:45 PM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Re #6:

Again, a lot to unpack here.
  1. I don't know about your specific hard drive but with hdparm you can query its capabilities; please read 'man hdparm' for its many diagnostic options. It is tedious but in the end it will put your mind at rest about what exactly its capabilities are.
  2. I said that forcefully spinning down a hard drive is wrong when it's in use, not when it's not in use.
    You say you aren't using it, but are you sure your OS isn't using (accessing) it, either?
    Have a look at this article; you will notice it isn't so easy to tell the system to leave it be: "I want to save its limited lifetime by keeping it powered down, and I don't want any process to power it up again. Unfortunately various systemd services are prone to do just that, e.g. systemd-hostnamed, dbus, udisks2, but also command line utilities like fdisk, smartctl and even hdparm itself. Waking the drive takes 30s which leads to unholy delays in certain actions (opening files with GtkFileChooser)."
    The article has a lot of information, a related article you also might want to read, and a #Files section where you can look at the scripts.
  3. I think you took my advice about other systemd services interfering a little too literally, or you need a primer on system maintenance with systemd in general.
    I wouldn't say that "another service broke my settings", I'd say "I need to adjust the settings for this service to make it work".
    TBH, I'm pretty sure your system likes to peak at this drive regularly. You will rather need to make the drive "non-existent" before everything else. Again, read the two articles linked, incl. further links.
 
1 members found this post helpful.
  


Reply

Tags
hdparm, systemd



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot successfully configure SNMP in Ubuntu20 BigD63 Linux - Newbie 2 07-15-2021 03:56 PM
How to turn off (spindown) SATA HDD on Debian after 10 min inactivity jtag Linux - General 3 03-14-2010 03:32 PM
How to turn off (spindown) SATA HDD on Debian after 10 min inactivity jtag Linux - Software 1 03-14-2010 01:58 PM
hdparm doesn't load hdparm.conf KOTAPAKA Linux - Hardware 2 05-21-2008 09:54 AM
SATA drive spindown, laptop mode, and hdparm--what works and how? enigma_0Z Linux - Hardware 1 05-02-2008 03:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration