Unable to disable wake from mouse and keyboard

Kernel: 6.5.3-1

# /home/muro/.bin/wakeup-disabled.sh

#!/bin/bash
# Disable wakeup events
echo disabled > /sys/bus/usb/devices/3-2.1/power/wakeup
echo disabled > /sys/bus/usb/devices/3-2.2/power/wakeup
# /etc/systemd/system/wakeup-disabled.service

[Unit]
Description=Disable wakeup events on startup

[Service]
Type=oneshot
ExecStart=/bin/bash /home/muro/.bin/wakeup-disabled.sh

[Install]
WantedBy=multi-user.target

By creating the above two files, I created systemd to disable wake-up by mouse and keyboard operations.
After trying to restart manjaro three times in a row, I was able to confirm that the wakeup setting was not reset and I was unable to wake it from sleep.
However, when I turned off the power, started manjaro the next day, and then went to sleep, I was able to wake up again from the mouse and keyboard, and wakeup was not disabled.

systemctl status wakeup-disabled                                                                                                                                        1 ✘ 
× wakeup-disabled.service - Disable wakeup events on startup
     Loaded: loaded (/etc/systemd/system/wakeup-disabled.service; enabled; preset: disabled)
     Active: failed (Result: exit-code) since Sun 2023-09-24 08:59:22 JST; 2h 7min ago
    Process: 499 ExecStart=/bin/bash /home/muro/.bin/wakeup-disabled.sh (code=exited, status=1/FAILURE)
   Main PID: 499 (code=exited, status=1/FAILURE)
        CPU: 3ms

 9月 24 08:59:22 manjaro systemd[1]: Starting Disable wakeup events on startup...
 9月 24 08:59:22 manjaro bash[499]: /home/muro/.bin/wakeup-disabled.sh: 行 3: /sys/bus/usb/devices/3-2.1/power/wakeup: そのようなファイルやディレクトリはありません
 9月 24 08:59:22 manjaro bash[499]: /home/muro/.bin/wakeup-disabled.sh: 行 4: /sys/bus/usb/devices/3-2.2/power/wakeup: そのようなファイルやディレクトリはありません
 9月 24 08:59:22 manjaro systemd[1]: wakeup-disabled.service: Main process exited, code=exited, status=1/FAILURE
 9月 24 08:59:22 manjaro systemd[1]: wakeup-disabled.service: Failed with result 'exit-code'.
 9月 24 08:59:22 manjaro systemd[1]: Failed to start Disable wakeup events on startup.
grep . /sys/bus/usb/devices/*/power/wakeup                                                                                                                              3 ✘ 
/sys/bus/usb/devices/1-7/power/wakeup:disabled
/sys/bus/usb/devices/1-8/power/wakeup:disabled
/sys/bus/usb/devices/3-2.1/power/wakeup:enabled
/sys/bus/usb/devices/3-2.2/power/wakeup:enabled
/sys/bus/usb/devices/3-2/power/wakeup:disabled
/sys/bus/usb/devices/4-2/power/wakeup:disabled
/sys/bus/usb/devices/5-1/power/wakeup:disabled
/sys/bus/usb/devices/5-2/power/wakeup:disabled
/sys/bus/usb/devices/6-2/power/wakeup:disabled
/sys/bus/usb/devices/usb1/power/wakeup:disabled
/sys/bus/usb/devices/usb2/power/wakeup:disabled
/sys/bus/usb/devices/usb3/power/wakeup:disabled
/sys/bus/usb/devices/usb4/power/wakeup:disabled
/sys/bus/usb/devices/usb5/power/wakeup:disabled
/sys/bus/usb/devices/usb6/power/wakeup:disabled

(Sorry, the above message contains Japanese.)
It seems that the command in the sh file is failing to execute, but the message “No such file or directory” is displayed even though the wakeup file exists.

How can I always disable wakeup?

Usually: Go into your UEFI Settings and disable" wake up by usb inputs" at the power management section. The option can be called differently.

If not possible, then here is a more reliable version of your script:

#!/bin/bash
# Toggle wakeup device (enabled/disabled)
echo "XHC" > /proc/acpi/wakeup
# If enabled, it will be disabled or if disabled, it will be enabled.

Check to which address path it is symlinked to:

file /sys/bus/usb/devices/*

For example: 0000:00:14.0
and compare with:

cat /proc/acpi/wakeup

Adjust “XHC” above.

You can also use something like that:

while read line
do 
   mapfile -t -d' ' <<<"$line"
   [[ "${MAPFILE[2]}" == '*disabled' ]] && continue
   if [[ "${MAPFILE[2]}" == '*enabled' ]] \
   && [[ "${MAPFILE[0]}" == 'XHC' ]]; then
   echo "Disabling ${MAPFILE[3]}"
   # Uncomment the following to run it:
   # echo "${MAPFILE[0]}" > /proc/acpi/wakeup
   fi
done < <(cat /proc/acpi/wakeup | tr '\t' ' ' | tr -s ' ')
1 Like

You have two issues:

1. issue:

The problem is USB number e.g. “3-2.1” that can be randomly changed after many reboots.

How to fix 1. issue:
:point_right: You need to get idVendor and idProduct, they are the identity of your device.
Run $ lsusb to display idVendor and idProduct of your device.

2. issue:
Your script of systemd service is run once after reboot and works. But it does not work when you disconnect and reconnect your mouse without rebooting, because the USB setting of the mouse is reset after reconnecting the USB port.

How to fix 2. issue:
:point_right: Create a udev-rule script /etc/udev/rules.d/90-disable-mouse.rules:
XXXX is idVendor.
YYYY is idProduct.

ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYYY", ATTR{../power/wakeup}="disabled"

or

ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="YYYY", RUN+="/bin/sh -c 'echo disabled > /sys/$env{DEVPATH}/../power/wakeup'"

Run $ sudo mkinitcpio -P and reboot.
That works after reconnecting the USB port of your device to disable wakeup.

Attention: The solution works for mkinitcpio.

#!/bin/bash
# Disable wakeup events
echo "XHC0" > /proc/acpi/wakeup

Thank you for your reply.
After rewriting the sh file as above and restarting manjaro, I was unable to wake up even if I operated the mouse and keyboard during sleep.
I’ll see how it goes for a few days.

cat /proc/acpi/wakeup                                                                                                                                                     ✔ 
Device  S-state   Status   Sysfs node
GP17      S4    *enabled   pci:0000:00:08.1
XHC0      S4    *disabled  pci:0000:07:00.3
XHC1      S4    *enabled   pci:0000:07:00.4
PS2K      S3    *disabled
GPP0      S4    *enabled   pci:0000:00:01.1
PTXH      S4    *enabled   pci:0000:02:00.0
PT20      S4    *disabled
PT21      S4    *disabled
PT22      S4    *disabled
PT23      S4    *disabled
PT24      S4    *disabled
PT26      S4    *disabled
PT27      S4    *disabled
PT28      S4    *enabled   pci:0000:03:08.0
PT29      S4    *enabled   pci:0000:03:09.0
file /sys/bus/usb/devices/*                                                                                                                                             3 ✘ 
/sys/bus/usb/devices/1-0:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb1/1-0:1.0
/sys/bus/usb/devices/1-7:       symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb1/1-7
/sys/bus/usb/devices/1-7:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb1/1-7/1-7:1.0
/sys/bus/usb/devices/1-8:       symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb1/1-8
/sys/bus/usb/devices/1-8:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb1/1-8/1-8:1.0
/sys/bus/usb/devices/1-8:1.1:   symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb1/1-8/1-8:1.1
/sys/bus/usb/devices/1-8:1.2:   symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb1/1-8/1-8:1.2
/sys/bus/usb/devices/2-0:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb2/2-0:1.0
/sys/bus/usb/devices/3-0:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-0:1.0
/sys/bus/usb/devices/3-2:       symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2
/sys/bus/usb/devices/3-2.1:     symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2/3-2.1
/sys/bus/usb/devices/3-2.1:1.0: symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2/3-2.1/3-2.1:1.0
/sys/bus/usb/devices/3-2.1:1.1: symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2/3-2.1/3-2.1:1.1
/sys/bus/usb/devices/3-2.1:1.2: symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2/3-2.1/3-2.1:1.2
/sys/bus/usb/devices/3-2.2:     symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2/3-2.2
/sys/bus/usb/devices/3-2.2:1.0: symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2/3-2.2/3-2.2:1.0
/sys/bus/usb/devices/3-2.2:1.1: symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2/3-2.2/3-2.2:1.1
/sys/bus/usb/devices/3-2.2:1.2: symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2/3-2.2/3-2.2:1.2
/sys/bus/usb/devices/3-2:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3/3-2/3-2:1.0
/sys/bus/usb/devices/4-0:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb4/4-0:1.0
/sys/bus/usb/devices/4-2:       symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb4/4-2
/sys/bus/usb/devices/4-2:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb4/4-2/4-2:1.0
/sys/bus/usb/devices/5-0:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5/5-0:1.0
/sys/bus/usb/devices/5-1:       symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5/5-1
/sys/bus/usb/devices/5-1:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5/5-1/5-1:1.0
/sys/bus/usb/devices/5-1:1.1:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5/5-1/5-1:1.1
/sys/bus/usb/devices/5-1:1.2:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5/5-1/5-1:1.2
/sys/bus/usb/devices/5-2:       symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5/5-2
/sys/bus/usb/devices/5-2:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5/5-2/5-2:1.0
/sys/bus/usb/devices/6-0:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb6/6-0:1.0
/sys/bus/usb/devices/6-2:       symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb6/6-2
/sys/bus/usb/devices/6-2:1.0:   symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb6/6-2/6-2:1.0
/sys/bus/usb/devices/usb1:      symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb1
/sys/bus/usb/devices/usb2:      symbolic link to ../../../devices/pci0000:00/0000:00:02.1/0000:02:00.0/usb2
/sys/bus/usb/devices/usb3:      symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb3
/sys/bus/usb/devices/usb4:      symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.3/usb4
/sys/bus/usb/devices/usb5:      symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb5
/sys/bus/usb/devices/usb6:      symbolic link to ../../../devices/pci0000:00/0000:00:08.1/0000:07:00.4/usb6

Never use your home directory for things that must be executed at the system level. Put your script in /usr/local/bin, chown it to root:root, and give it 755 (-rwxr-xr-x) permissions. You either way don’t have write access to anything under /proc as a regular user, so your script would fail.

Also… :arrow_down:

Prefix your output with LANG=C, like so… :arrow_down:

LANG=C your-command-here
1 Like

To expand on this…

OR keep things in HOME, but use systemd user units … ex:

~/.config/systemd/user/wakeup-disabled.service

systemctl --user enable wakeup-disable --now

But of course that also assumes everything is fine with user permissions, etc.

1 Like

I confirmed that even after moving the sh file to /usr/local/bin, the mouse operation during sleep did not wake up the computer.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.