Skip to content

Instantly share code, notes, and snippets.

@wheeskers
Last active March 13, 2024 11:43
Show Gist options
  • Select an option

  • Save wheeskers/dbd091cc995c7f830889 to your computer and use it in GitHub Desktop.

Select an option

Save wheeskers/dbd091cc995c7f830889 to your computer and use it in GitHub Desktop.
Disable wakeup for device using systemd

Check devices

# cat /proc/acpi/wakeup

Find specific devices

Examples:

EHC1	  S3	*enabled  pci:0000:00:1d.0
EHC2	  S3	*enabled  pci:0000:00:1a.0

Temporary disable waking up for selected device

# echo "EHC1" > /proc/acpi/wakeup
# echo "EHC2" > /proc/acpi/wakeup

Persistent changes via systemd

Create file like this one:

# nano /etc/tmpfiles.d/ehc1-disable-wake.conf

With lines:

w+ /proc/acpi/wakeup - - - - EHC1
w+ /proc/acpi/wakeup - - - - EHC2

Then reboot and check again -- specified devices will not wake up a machine until you let them again.

@bjarneeins
Copy link

bjarneeins commented Aug 8, 2018

It works only for the first line in the config (in your example w /proc/acpi/wakeup - - - - EHC1)
The other files are beeing ignored since they are duplicate path lines. My source: https://lists.freedesktop.org/archives/systemd-devel/2018-May/040718.html

My conf under /etc/tmpfiles.d:

w /proc/acpi/wakeup - - - - EHC1

w /proc/acpi/wakeup - - - - EHC2

w /proc/acpi/wakeup - - - - IGBE

w /proc/acpi/wakeup - - - - XHCI

The output im getting at /var/log/messages:

Aug  8 16:12:10 t430 systemd-tmpfiles[1022]: [/etc/tmpfiles.d/ehc1-disable-wakeup.conf:2] Duplicate line for path "/proc/acpi/wakeup", ignoring.

Aug  8 16:12:10 t430 systemd-tmpfiles[1022]: [/etc/tmpfiles.d/ehc1-disable-wakeup.conf:3] Duplicate line for path "/proc/acpi/wakeup", ignoring.

Aug  8 16:12:10 t430 systemd-tmpfiles[1022]: [/etc/tmpfiles.d/ehc1-disable-wakeup.conf:4] Duplicate line for path "/proc/acpi/wakeup", ignoring.

Any idea on how to get tmpfiles to not ignore the lines?

Greetings :)

@tcellemail
Copy link

You can get around that issue by creating some symbolic links with different names, pointing to the same file:

sudo ln -s /etc/wakeup1 /proc/acpi/wakeup
sudo ln -s /etc/wakeup2 /proc/acpi/wakeup
sudo ln -s /etc/wakeup3 /proc/acpi/wakeup
sudo ln -s /etc/wakeup4 /proc/acpi/wakeup

Then, in /etc/tmpfiles.d:

w /etc/wakeup1 - - - - EHC1
w /etc/wakeup1 - - - - EHC2
w /etc/wakeup1 - - - - IGBE
w /etc/wakeup1 - - - - XHCI

Let me know if this workaround worked for you.

Greetings!

@wheeskers
Copy link
Author

Hi @tcellemail,
I didn't expect that someone will comment after this long time. Thanks!

I don't have that device at the moment but I think this will work.

@brandsimon
Copy link

brandsimon commented May 6, 2020

Thank you for all the hints here.
I decided to disable my devices via /sys/devices/*/*/power/wakeup, since /proc/acpi/wakeup is only a toggle, and I want it to be disabled for sure, also I can then easily specify multiple devices:
e.g. forXHC S3 *disabled pci:0000:00:14.0 the tmpfiles looks like this:

w /sys/devices/pci0000:00/0000:00:14.0/power/wakeup - - - - disabled

Hopefully this is helpful for someone.

Edit: Also be careful with sysfs and tmpfiles, because some devices will be available after tmpfiles is processed
source: https://wiki.archlinux.org/index.php/Systemd#Temporary_files

@HaleTom
Copy link

HaleTom commented Mar 13, 2024

It is possible to write multiple lines to the same file, either with \n in the argument or using the w+ type on multiple lines (including the first one) for appending
-- https://wiki.archlinux.org/title/Systemd#Temporary_files:~:text=It%20is%20possible,for%20appending%3A

@HaleTom
Copy link

HaleTom commented Mar 13, 2024

Here's how to do it via sytstemd:
https://unix.stackexchange.com/a/772229/143394

@wheeskers
Copy link
Author

@HaleTom, thanks for the tip! Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment