LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 09-02-2018, 03:31 AM   #1
denydias
Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 127

Rep: Reputation: Disabled
Lightbulb Easily monitor power management features


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!
Attached Thumbnails
Click image for larger version

Name:	0_pm-mon.gif
Views:	65
Size:	61.1 KB
ID:	28506  

Last edited by denydias; 09-02-2018 at 03:47 AM.
 
Old 09-02-2018, 09:25 PM   #2
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 982

Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
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
#or
user ALL=(ALL) NOPASSWD:/usr/sbin/smartctl
 
Old 09-02-2018, 10:34 PM   #3
denydias
Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 127

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by abga View Post
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
#or
user ALL=(ALL) NOPASSWD:/usr/sbin/smartctl
Thank you for the suggestion, @abga.

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
The above will not require add anything to /etc/sudoers. It'll just run smartctl as root, regardless of who called it. I don't want to impose that security hole to users as smartctl allows a number of operations on that we don't need for the scope of pm-mon.

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.
 
Old 09-03-2018, 04:46 AM   #4
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 982

Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
Quote:
Originally Posted by denydias View Post
Thank you for the suggestion, @abga.

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
The above will not require add anything to /etc/sudoers. It'll just run smartctl as root, regardless of who called it.
Using sudo (/etc/sudoers) and restricting the usage of a specific binary for a specific user is a far safer security approach IMO.

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
 
Old 09-03-2018, 04:53 AM   #5
denydias
Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 127

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by abga View Post
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
Yeah, while developing I tried udisks too. It says only if a HDD can spindown, but don't provide the spin status.

Didn't know about udisksctl. Thanks for that, but it also do not provide HDD spin hints.
 
Old 09-03-2018, 05:05 AM   #6
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 982

Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
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.
 
Old 09-03-2018, 05:23 AM   #7
denydias
Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 127

Original Poster
Rep: Reputation: Disabled
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.
 
Old 09-03-2018, 05:44 AM   #8
abga
Member
 
Registered: Jul 2017
Location: EU
Distribution: Slackware
Posts: 982

Rep: Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514Reputation: 514
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
 
Old 09-03-2018, 05:45 AM   #9
Mark Pettit
Member
 
Registered: Dec 2008
Location: Cape Town, South Africa
Distribution: Slackware 14.2 64 Multi-Lib
Posts: 525

Rep: Reputation: 210Reputation: 210Reputation: 210
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 :-)

Last edited by Mark Pettit; 09-03-2018 at 05:45 AM. Reason: spelling error
 
Old 09-03-2018, 05:49 AM   #10
denydias
Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 127

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by abga View Post
These might be helpful in interrogating the kernel about the pm state, if not, at least they'll keep you busy
Sure thing! Thanks for the links.

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.
 
Old 09-03-2018, 05:52 AM   #11
denydias
Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 127

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Mark Pettit View Post
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 :-)
Thanks for that, Mark! I'm going to look for the call I need.
 
Old 09-03-2018, 09:16 PM   #12
denydias
Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 127

Original Poster
Rep: Reputation: Disabled
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.

Last edited by denydias; 09-03-2018 at 09:17 PM.
 
  


Reply

Tags
monitoring, pm-utils, power management, slackware


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
laptop powering down on ac power regardless of xfce power management wufo Ubuntu 2 12-20-2016 07:05 PM
Power Management not working on embedded MIPS when using /sys/power/state RichardS Programming 1 01-21-2011 07:18 AM
Battery monitor icon in Gnome / power management android6011 Linux - Software 1 08-04-2006 03:34 AM
Power Management turns off monitor improperly stelmed Slackware 15 09-14-2005 12:12 AM
Enabling power save/power management/cpu freq scaling features for a Debian system zero79 Debian 0 12-19-2004 01:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:49 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration