0

I'm trying to disable ACPI wake on usb in Ubuntu 20.04 So I created a script in /etc/profile.d

-rwxr-xr-x 1 root root 110 May 18 00:23 disable-usb-wake.sh

#!/bin/sh -e
if cat /proc/acpi/wakeup | egrep 'XHC.*enabled'; then
    echo "XHC" > /proc/acpi/wakeup
fi

When I start my machine it says permission denied. Why?

caduceus
  • 305
  • 2
  • 7
  • IIRC `/etc/profile.d` scripts are run when a user logs in (more specifically, when a login shell is started), as the user. Has your user permissions to write into `/proc/acpi/wakeup`? – Gerald Schneider May 18 '20 at 06:33
  • I could not post here without making an attempt. i'm looking for guidance on how to achieve a simple end, in a paradigmatic way. What are other people doing to stop USB from waking their machines? I've tried setting this in rc.local. I didn't get an error, although neither was the value set. At least by the time I got to it. People accuse systemd of over-reaching. I don't mind, as long as users aren't expected to figure it all out though deductive inquiry. – caduceus May 18 '20 at 07:13

1 Answers1

2

As mentioned in the comments, /etc/profile.d is being run as the user logging in, so will not have sufficient permissions to modify system configuration. You could add a sudo command there, but that would just mean you'll need to type your password again when you log in - this would be annoying and will also not work if the logging in user is not a system admin. Also, it will not do its job if no one is logging in after boot.

There are a few options, including adding /etc/rc.local as you mentioned, which was one of the common ways to do this kind of custom "on-boot" jobs before SystemD made the whole /etc/rc* thing irrelevant.

But - if you already have /etc/rc.local set up with your script, you can just enable it in SystemD by:

  1. Make sure /etc/rc.local is executable. For example by running chmod a+x /etc/rc.local. The SystemD compatibility mode will not work otherwise.
  2. Allow the SystemD compatibility mode to be enabled by creating the file /etc/systemd/system/rc-local.service.d/enable.conf with the contents below.
  3. Enable the SystemD compatibility by running sudo systemctl enable rc-local

/etc/systemd/system/rc-local.service.d/enable.conf :

[Install]
WantedBy=multi-user.target

Next time your system boot, SystemD will run your custom /etc/rc.local.

SystemD Alternatives

  1. Make use of SystemD tmpfiles management system to have it write what you need during boot. This is my recommended solution.
  2. See this AskUbuntu question for some people making SystemD services to do the same thing.
  3. I believe you can write a udev rule that disables "power/wakeup" when it sees whatever the XHC is (I think its the onboard XHCI USB hub?), as documented here: https://www.kernel.org/doc/html/v4.13/driver-api/usb/power-management.html
Guss
  • 2,670
  • 5
  • 34
  • 59