Easily monitor power management features
1 Attachment(s)
This thread sparked a feeling on me: I know how to look for power management status, but I need to type a lot to know everything I could also learn with a single short command.
pm-mon is what came out of this spark. A short demo is attached. Installation, usage and other info is available here. One question to the fellow experienced users: I did what I could to obtain HDD spin status without the need to use hdparm and smartctl (both requiring root), but I was beaten on this quest. Is there any way to extract the HDD spin status from /proc, /sys or any other tool not requiring privilege escalation to provide useful readouts? Thanks in advance for any tips. Enjoy! |
No idea how to obtain such info without being root.
Is it an issue if you make use of sudo and restrict what the user running pm-mon is able to execute as root? You could achieve that by running visudo and adding the following line (substitute user with your actual user): Code:
user ALL=(ALL) NOPASSWD:/usr/sbin/hdparm |
Quote:
No, it's not. But this is not up to me. This should be a user choice. It will work the same if the user do this: Code:
chmod u+s /usr/sbin/smartctl hdparm is not an option here as its -C parameter (to query HDD power state) reportedly disturbs the HDD and put it to spin. But thanks anyway for the ideia. |
Quote:
Maybe consider giving the udisks or udisksctl utilities a try, you might be able to extract some info about the PM state of the drive: https://linux.die.net/man/1/udisks http://storaged.org/doc/udisks2-api/...isksctl.1.html |
Quote:
Didn't know about udisksctl. Thanks for that, but it also do not provide HDD spin hints. |
Sorry, no other ideas ATM.
Frankly, I always disable the PM of the hard drive with /usr/sbin/hdparm -B 255 /dev/sdX (in rc.local), I know it's not recomended, especially not parking the heads, but I started to hate the clicking sounds in the newer models. |
That's ok. You have helped anyway. Thanks for the time.
As for HDD PM, yes, the rattling noise is truly annoying. Fortunately my notebook has room for one HDD and two M2 SSDs, sda being the HDD. I've managed to install Slackware into sdb SSD then I can just be aggressive with sda's PM as I have very little use to it, like editing videos when I travel with my motorcycle. The rest of the time it just sits there disabled, so no noise. |
These might be helpful in interrogating the kernel about the pm state, if not, at least they'll keep you busy ;)
https://www.kernel.org/doc/html/v4.1...m/devices.html http://www.infradead.org/~mchehab/ke...driver-api.pdf https://www.kernel.org/doc/Documenta...runtime_pm.txt |
Um - I'm gonna throw something into the mix here - possibly unexpected. I haven't checked exactly for what you're looking for, but this tool my just have it. And check here : https://osquery.io/schema/3.3.0 for the tables and columns to query. And if it doesn't do, maybe you'll get lucky if you ask the developers to add it :-)
|
Quote:
I'll also take a look at smartctl source to see if I can mimic its calls in bash, although I'm not holding my breath about it. :p |
Quote:
|
I gave a good look over smartctl and hdparm sources. Nope, there's no way to get HDD spin status from an unprivileged bash script. The kernel system calls to the SATA subsystems are well protected from the user space. Any operation issued to those calls requires privilege escalation, which is a VERY good thing!
I could implement a small C thing just to query HDD spin status, but that would require privilege escalation too. So it looks wiser to just keep smartctl and add extra checks if a user can run it as root. This is how I did it: 1. If user is root, just run smartctl; else 2. If user can `sudo smartctl` without a password, do that; else 3. If smartctl is setuid, just run it as the user; else 4. If none of the above is true, then just print <root required>. I've updated the script and the comment bellow it to reflect that changes. There are some other improvements too. Thank you all that provided me some extra info here. ;) |
All times are GMT -5. The time now is 06:03 AM. |