Linux(NixOS)笔记本挂起时插拔USB键盘后无法唤醒问题
I’ve dealt with similar USB wake quirks on laptops with hotplugged devices, so let’s break down what’s going on and how to fix it:
When you plug/unplug the USB keyboard while the system is suspended, the USB bus re-enumerates the device once the system wakes up—but the kernel doesn’t always reattach the wake-up trigger correctly, even though power/wakeup shows as enabled. Here are actionable fixes you can try:
1. Quick Temporary Fix: Reset Wake-up State
If you just need to get the keyboard working right after waking up, toggle the wake-up state to force the kernel to re-recognize the device’s capability:
echo disabled | sudo tee /sys/bus/usb/devices/1-7.1/power/wakeup echo enabled | sudo tee /sys/bus/usb/devices/1-7.1/power/wakeup
This quick resync often fixes the issue temporarily, but we’ll want a permanent solution below.
2. Permanent Fix with Udev Rules
Udev can automatically set the wake-up state every time the keyboard is plugged in (including after suspend hotplug). Here’s how to set it up:
- First, get your keyboard’s vendor and product IDs using
lsusb:
Look for your keyboard entry—you’ll see something likelsusbID 1234:5678 Vendor Name Keyboard Model. The1234is the vendor ID,5678is the product ID. - Create a udev rule file at
/etc/udev/rules.d/99-usb-wakeup.ruleswith this content (replace the IDs with yours):SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", RUN+="/bin/sh -c 'echo enabled > /sys$devpath/power/wakeup'" - Reload udev to apply the rule immediately:
sudo udevadm control --reload-rules && sudo udevadm trigger
Now every time you plug in the keyboard (even after suspend), udev will ensure the wake-up setting is enabled.
3. Adjust Kernel USB Power Management Parameters
Some kernel-level USB autosuspend settings can interfere with wake-up after hotplug. Try disabling USB autosuspend entirely (it’s a small trade-off in power draw for reliability):
In NixOS, edit your configuration.nix and add this line:
boot.kernelParams = [ "usbcore.autosuspend=-1" ];
Then rebuild your system configuration:
sudo nixos-rebuild switch
This prevents the kernel from putting USB devices into low-power states that might break wake-up triggers after hotplug.
4. Verify Device Wake-up Capability
Double-check that your keyboard actually supports wake-up (though you said it works when not hotplugged, so this is just a sanity check):
cat /sys/bus/usb/devices/1-7.1/power/wakeup_capable
If the output is yes, the hardware supports wake-up, and the issue is definitely with system state sync. If it’s no, you might have a hardware limitation—but your scenario suggests this isn’t the case.
内容的提问来源于stack exchange,提问作者illabout

