Spindown hdd after boot, tried systemd or hdparm.conf, does not work @ubuntu20.04
Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
Location: Montreal, Quebec and Dartmouth, Nova Scotia CANADA
Distribution: Arch, AntiX, ArtiX
Posts: 1,364
Rep:
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.
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
Location: Montreal, Quebec and Dartmouth, Nova Scotia CANADA
Distribution: Arch, AntiX, ArtiX
Posts: 1,364
Rep:
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.
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.
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:
Location: Montreal, Quebec and Dartmouth, Nova Scotia CANADA
Distribution: Arch, AntiX, ArtiX
Posts: 1,364
Rep:
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.