You are not logged in.
I want to set the frequency to fixed 800MHz of my laptop (Core i7 cpu) at startup and have the possibility to set it to an other governor.
Under XUbuntu this works very well with this batch-file "cpu_power_800MHz"I wrote and an entry in "/etc/sudoers":
[File "cpu-power_800MHz" in /usr/bin/ ]
#!/bin/bash
# Add in "/etc/sudoers" the entry at the end:
# %predatorworks ALL = NOPASSWD: /usr/bin/cpupower
# %predatorworks ALL = NOPASSWD: /usr/bin/cpu-power_800MHz
#sleep 3s
cpupower frequency-set -g powersave
cpupower frequency-set -u 800000
[/File]
File attribute:
-rwxr-xr-x 1 root root cpupower
-rwxr-xr-x 1 root root cpu-power_800MHz
But out of some reason I get the Error if I execute the file.
If I use the command alone I get this error too.
Command: "cpupower frequency-set -g powersave"
Answer: "Subcommand frequency-set needs root privileges"
(with "sudo and password" it works, but I want to make it possible without a password)
Arch seems to have a problem with "frequency-set", but why?
What can I do to make it work?
Can I allow this subcommand somehow?
Offline
If you always run that when the machine boots you could alternatively write the values you want to the proper variables in /sys with tmpfiles, see 'man tmpfiles.d'.
R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K
Offline
Not a Sysadmin issue, moving to NC...
Offline
You have to run the program as root. If sudo is prompting for a password you're not satisfying the “NOPASSWD” criteria. Check the obvious first:
1) the sudoers entry is a) present and b) correct (no typos etc.).
2) your user is in the “predatorworks” group (or whatever group your sudoers entry uses)
Offline
@ ukhippo
The nopasswd option works.
I can execute the "/usr/bin/cpupower" command without a password and
I can execute the "/usr/bin/cpu-power_800MHz" command without a password too.
If I make the test:
>$ cpu-power_delay_800MHz
I get:
>$ Subcommand frequency-set needs root privileges
The "/usr/bin/cpu-power_800MHz" Script is executing the "cpupower"-Command and everything is working ... but not the Subcommand "frequency-set".
I do not know why this subcommand is not working.
Offline
But you're NOT running the command as root, hence the error.
You have to run the “delay” script as root (either in a root shell or via sudo so that the cpupower commands get run as root) or change your delay script to prefix the cpupower commands with sudo.
Offline
But you're NOT running the command as root, hence the error.
I can run the "cpupower" command without a password, this is working because I have set the sudoers-entry for it.
Only the sub - command after "cpupower" will not be accepted.
(Under XUbuntu this whole command works very fine.)
You have to run the “delay” script as root (either in a root shell or via sudo so that the cpupower commands get run as root) or change your delay script to prefix the cpupower commands with sudo.
With "sudo" he ask always for a password.
The goal is to start my laptop and in the background it will run automatically some commands with root-permission without the use to typing in the root password. (before login would be fine, but I don't know where to put in the commands)
Offline
ukhippo wrote:You have to run the “delay” script as root (either in a root shell or via sudo so that the cpupower commands get run as root) or change your delay script to prefix the cpupower commands with sudo.
With "sudo" he ask always for a password.
Because you haven't created a NOPASSWD sudoers entry for the delay script.
Offline
It seems you don't want to go the route of tmpfiles I suggested above, how about using a systemd service? It should solve your sudo problems by not needing sudo.
R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K
Offline
ukhippo wrote:But you're NOT running the command as root, hence the error.
I can run the "cpupower" command without a password, this is working because I have set the sudoers-entry for it.
No, you simply don't need superuser privileges for all subcommands. When you're not using sudo, the sudoers entries are irrelevant.
You can enable the cpupower.service that is part of the cpupower package (configuration in /etc/default/cpupower) to set the governor and frequency at startup.
If you want to be able to change it later without entering a password, then you can use sudo for that with the correct NOPASSWD setting. You can either make an entry for a script and run the script with sudo, or make an entry so you can run `sudo cpupower` (as part of a script or on its own) without a password.
Offline
Because you haven't created a NOPASSWD sudoers entry for the delay script.
The "#" should be the comment-sign like // in C ... or isn't it?
Now I have removed the delay-entry.
Under XUnuntu I started this script with the ordinary autostart-method after login and I want give the Laptop some seconds to load everything before I decrease the speed.
But the delay should not be the problem, because if I write directly in the terminal:
$ cpupower frequency-set -d 800000
I get: "Subcommand frequency-set needs root privileges"
And with "$ sudo cpupower frequency-set -d 800000" I must enter a password.
:-(
It seems you don't want to go the route of tmpfiles I suggested above, how about using a systemd service? It should solve your sudo problems by not needing sudo.
First I have create this systemd service and now I read the tempfiles.d man-file.
What I have done:
In: /etc/systemd/system/
I have add the file: "autostart.service"
With the Text:
//Start Textfile ---------------------------
[Unit]
Description=predatorworks User Startup
Conflicts=getty@tty1.service plymouth-quit.service
After=systemd-user-sessions.service getty@tty1.service plymouth-quit.service
[Service]
Type=oneshot
ExecStart=/usr/bin/predatorworks_user_startup
[Install]
// End Textfile ---------------------------
In the file "predatorworks_user_startup" at the path "/usr/bin/" I have write this text:
//Start Textfile ---------------------------
#!/bin/bash
# /var/log is mounted as tmpfs
mkdir /var/log/apache2
#
# /usr/bin/cpu-power_800MHz
cpupower frequency-set -g powersave
cpupower frequency-set -u 800000
#
# Make brightness adjusable:
chmod ugo+w /sys/class/backlight/intel_backlight/brightness
# Standard-brightness at startup:
echo 400 > /sys/class/backlight/intel_backlight/brightness
# information that the script was executed
touch /home/predatorworks/Data/autostartup.txt
#exit 0
// End Textfile ---------------------------
In the root terminal I have enable this service:
"systemctl enable autostart.service"
Start the service:
"systemctl start autostart.service"
You can enable the cpupower.service that is part of the cpupower package (configuration in /etc/default/cpupower) to set the governor and frequency at startup.
Okay, done.
[root@predatorworks-PC etc]# systemctl enable cpupower.service
Output:
Created symlink /etc/systemd/system/multi-user.target.wants/cpupower.service → /usr/lib/systemd/system/cpupower.service.
Now the laptop only speed up to (average) 1.1GHz , before the value was 2.2GHz (average) till 3.1GHz.
But I want the option to set it to 800MHz.
My new sudoers - File:
//Start Textfile ---------------------------
...
... some other text
...
## Uncomment to allow any user to run sudo if they know the password
## of the user they are running the command as (root by default).
# Defaults targetpw # Ask for the password of the target user
# ALL ALL=(ALL) ALL # WARNING: only use this together with 'Defaults targetpw'
%users ALL = (root) NOPASSWD: /usr/bin/tee
%users ALL = (root) NOPASSWD: /sbin/shutdown
%users ALL = (root) NOPASSWD: /sys/class/backlight/intel_backlight/brightness
%users ALL = (root) NOPASSWD: /sys/class/backlight/intel_backlight/actual_brightness
%users ALL = (root) NOPASSWD: /usr/bin/helligkeit_minus
%users ALL = (root) NOPASSWD: /usr/bin/helligkeit_plus
%users ALL = (root) NOPASSWD: /usr/bin/helligkeit_standard
%users ALL = (root) NOPASSWD: /usr/bin/helligkeit_null
%users ALL = (root) NOPASSWD: /usr/bin/truecrypt
%users ALL = (root) NOPASSWD: /usr/bin/cpupower
%users ALL = (root) NOPASSWD: /usr/bin/cpu-power_800MHz
%users ALL = (root) NOPASSWD: /usr/bin/cpu-power_delay_800MHz
##
## Read drop-in files from /etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /etc/sudoers.d
// End Textfile ---------------------------
"predatorworks" is member of the group users:
$ id
uid=1000(predatorworks) gid=1000(predatorworks) Gruppen=1000(predatorworks),6(disk),7(lp),10(wheel),90(network),91(video),93(optical),95(storage),96(scanner),98(power),100(users)
Offline
We have given you options, you don't need to implement all of them. Choose the one that works better or that you feel more comfortable with and stick with it.
R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K
Offline
If you always run that when the machine boots you could alternatively write the values you want to the proper variables in /sys with tmpfiles, see 'man tmpfiles.d'.
Did you not investigate tmpfiles.d
mkdir /var/log/apache2
tmpfiles.d was designed for exactily this situation.
Your solution will also result in the directory being owned by root:root which unless you running apache as root will be an issue.
Conflicts=getty@tty1.service plymouth-quit.service
Why do want it to block the terminal on tty1?
# Make brightness adjusable:
chmod ugo+w /sys/class/backlight/intel_backlight/brightness
# Standard-brightness at startup:
echo 400 > /sys/class/backlight/intel_backlight/brightness
Mixing in three different functions into a single service is probably unwise.
And with "$ sudo cpupower frequency-set -d 800000" I must enter a password.
If this is still happening please post your full /etc/sudeors
Edit:
$ id
uid=1000(predatorworks) gid=1000(predatorworks) Gruppen=1000(predatorworks),6(disk),7(lp),10(wheel),90(network),91(video),93(optical),95(storage),96(scanner),98(power),100(users)
Generally you should not need to be a member of some of those groups. Users_and_groups#Pre-systemd_groups
Some of the other groups are unused. Users_and_groups#Unused_groups
%users ALL = (root) NOPASSWD: /sbin/shutdown
allow_users_to_shutdown#Using_systemd-logind
Last edited by loqs (2016-09-30 00:47:20)
Offline