4

I wanted to change certain powertop params on Ubuntu 17.04 startup, therefore I created a shell script in /usr/sbin/ and made it executable:

#!/bin/sh
echo 'min_power' > '/sys/class/scsi_host/host1/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host2/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host0/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host5/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host3/link_power_management_policy';
echo 'min_power' > '/sys/class/scsi_host/host4/link_power_management_policy';
echo '1' > '/sys/module/snd_hda_intel/parameters/power_save';
echo 'auto' > '/sys/bus/i2c/devices/i2c-0/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-1/device/power/control';
echo 'auto' > '/sys/bus/i2c/devices/i2c-2/device/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1d.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.3/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.6/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:02.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:14.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.4/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:17.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.2/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:00:16.0/power/control';
ethtool -s  enp0s31f6 wol d
exit 0

Then I made a service unit in /etc/systemd/system :

[Unit]
Description=PowerTOP

[Service]
ExecStart=/usr/sbin/powertop-stup.sh

[Install]
WantedBy=multi-user.target

and enabled it with sudo systemctl enable powertop_start.service but after a reboot it does not work.

If I start the service manually after booting with sudo systemctl start powertop_start.service it works flawlessly. Also when I start the shell script itself it works but automatically on boot it does nothing.

karel
  • 114,770
  • And what does journalctl -u powertop_start.service say after it fails to start as expected on boot? Does systemctl status powertop_start show anything interesting? – Mark Stosberg May 11 '17 at 18:31
  • systemctl status powertop_start gives me `powertop_start.service - PowerTOP Loaded: loaded (/etc/systemd/system/powertop_start.service; enabled; vendor Active: inactive (dead) since Thu 2017-05-11 21:10:07 CEST; 53s ago Main PID: 787 (code=exited, status=0/SUCCESS)

    May 11 21:10:06 mediaserver systemd[1]: Started PowerTOP.and journalctl -u powertop_start.service gives meLogs begin at Thu 2017-05-11 21:10:05 CEST, end at Thu 2017-05-11 21:17:01 CE May 11 21:10:06 mediaserver systemd[1]: Started PowerTOP. `

    – ilovebytes May 11 '17 at 19:17
  • But are the logs only from the the attempted startup, or did you capture the logs only after your successful manual run of the service? – Mark Stosberg May 11 '17 at 20:02

1 Answers1

2

I don't know why your service doesn't work, but I believe the standard way to make changes to /sys at boot is to use sysfsutils, so I'm suggesting that as an alternative approach.

The package may not be installed by default, so first do:

sudo apt install sysfsutils

now edit the file /etc/sysfs.conf, for example:

sudoedit /etc/sysfs.conf

and add these lines to the end of it

class/scsi_host/host1/link_power_management_policy = min_power
class/scsi_host/host2/link_power_management_policy = min_power
class/scsi_host/host0/link_power_management_policy = min_power
class/scsi_host/host5/link_power_management_policy = min_power
class/scsi_host/host3/link_power_management_policy = min_power 
class/scsi_host/host4/link_power_management_policy = min_power
module/snd_hda_intel/parameters/power_save = 1
bus/i2c/devices/i2c-0/device/power/control = auto
bus/i2c/devices/i2c-1/device/power/control = auto
bus/i2c/devices/i2c-2/device/power/control = auto
bus/pci/devices/0000:00:1d.0/power/control = auto
bus/pci/devices/0000:00:1f.3/power/control = auto
bus/pci/devices/0000:00:00.0/power/control = auto
bus/pci/devices/0000:00:1f.6/power/control = auto
bus/pci/devices/0000:00:02.0/power/control = auto
bus/pci/devices/0000:00:14.0/power/control = auto
bus/pci/devices/0000:00:1f.4/power/control = auto
bus/pci/devices/0000:00:17.0/power/control = auto
bus/pci/devices/0000:00:1f.2/power/control = auto
bus/pci/devices/0000:00:1c.0/power/control = auto
bus/pci/devices/0000:00:1f.0/power/control = auto
bus/pci/devices/0000:00:16.0/power/control = auto

Save the file and exit, and reboot.

That leaves your ethtool command, which I don't have a solution for, but you might see if systemd will run only that command for you as detailed in this answer by muru.

Zanna
  • 70,465