SlackwareThis Forum is for the discussion of Slackware Linux.
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.
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.
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.
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
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.
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.
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.