When booting up my keyboard and mouse both dont work for a full minute before all of the sudden they start working

Create the service file named:

/etc/systemd/system/usb-restart.service

With the following contents:

#/etc/systemd/system/usb-restart.service
#sudo systemctl enable usb-restart.service
#sudo systemctl start usb-restart.service
#systemctl list-unit-files --state=enabled
#sudo systemctl stop usb-restart.service
#sudo systemctl disable usb-restart.service
#systemctl status usb-restart.service
#sudo systemctl daemon-reload

[Unit]
Description=Restart USB
Before=display-manager.service
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/sudo -E  /usr/local/bin/restart_usb.sh

[Install]
WantedBy=display-manager.service

Create the script named:

/usr/local/bin/restart_usb.sh

With the following contents:

#!/bin/bash
#the keyboard section below is commented until the correct driver is confimed
#modprobe -r atkbd
#modprobe atkbd reset=1

#Disable all USB devices
#/usr/local/bin/restart_usb.sh
set -euo pipefail
IFS=$'\n\t'

VENDOR="****"
PRODUCT="****"

for DIR in $(find /sys/bus/usb/devices/ -maxdepth 1 -type l); do
  if [[ -f $DIR/idVendor && -f $DIR/idProduct &&
        $(cat $DIR/idVendor) == $VENDOR && $(cat $DIR/idProduct) == $PRODUCT ]]; then
    echo 0 > $DIR/authorized
    sleep 1
    echo 1 > $DIR/authorized
  fi
done

Make the above script executable.

The keyboard section of the script is commented until the correct driver is confirmed:

#modprobe -r atkbd
#modprobe atkbd reset=1

Check that you are using the atkbd keyboard module before uncommenting those lines.

I wrote and used this service quite a few years back, but the USB reset part of the service should still work fine. Test the service as is, then experiment with the keyboard reset section.

3 Likes