Bluetooth Hibernate Service - Intel 8260


I did some revisions on a service and scripts from my old thread you found and hopefully it will work for you. Unfortunately, I can't test it out personally as Bluetooth is the first thing I disable on any install.



Bluetooth Restart Service


The Bluetooth Restart Service below should hopefully resolve any issues with Bluetooth not working after resuming from suspend/hibernate.

This Bluetooth Restart Service stops both Wifi and Bluetooth prior to suspend/hibernate, and then restarts both Wifi and BT once resumed.


Bluetooth Restart Service


With your preferred text editor create:

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

bt-restart.service file contents:

# cat /etc/systemd/system/bt-restart.service
# systemctl enable --now bt-restart.service
# systemctl start bt-restart.service
# systemctl stop bt-restart.service
# systemctl disable bt-restart.service
# systemctl status bt-restart.service
# systemctl daemon-reload

[Unit]
Description=Stop/Start BT Pre/Post Suspend/Hibernate
Before=sleep.target
Before=hibernate.target
StopWhenUnneeded=yes

[Service]
User=root
Type=oneshot
RemainAfterExit=yes
ExecStartPre=-/usr/bin/sudo -u $USER /bin/bash -lc 'nmcli networking off'
ExecStart=/usr/bin/sleep 1
ExecStart=/usr/bin/sudo -E  /usr/local/bin/stop_bt.sh
ExecStop=/usr/bin/sudo -E  /usr/local/bin/start_bt.sh
ExecStop=/usr/bin/sleep 2
ExecStopPost=-/usr/bin/sudo -u $USER /bin/bash -lc 'nmcli networking on'

[Install]
WantedBy=sleep.target
WantedBy=hibernate.target

Then, in whichever text editor program you are using, save the script, (root or sudo authorization required).


Pre-suspend - Stop Bluetooth Script


Create the pre-suspend script to stop Bluetooth.

With your preferred text editor (root or sudo authorization required), create:

/usr/local/bin/stop_bt.sh

Pre-suspend script contents:

#!/bin/bash
#cat /usr/local/bin/stop_bt.sh
#pre-suspend script to stop bluetooth 

set -euo pipefail
IFS=$'\n\t'

VENDOR="8087"
PRODUCT="0a2b"

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
  fi
done

With root or sudo authorization save the script as /usr/local/bin/stop_bt.sh, and exit your text editor.


Post-Suspend - Start Bluetooth Script


Create the post-suspend script to start Bluetooth.

With a text editor create:

/usr/local/bin/start_bt.sh

Post-suspend script contents:

#!/bin/bash
#cat /usr/local/bin/start_bt.sh
#post-suspend script to start bluetooth 

set -euo pipefail
IFS=$'\n\t'

VENDOR="8087"
PRODUCT="0a2b"

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 1 > $DIR/authorized
  fi
done

With root or sudo authorization save the script as /usr/local/bin/start_bt.sh, and exit your text editor.

Then, make both scripts executable:

sudo chmod +x /usr/local/bin/stop_bt.sh && sudo chmod +x /usr/local/bin/start_bt.sh

Then enable the bt-restart.service:

systemctl enable --now bt-restart.service

Anyone wishing to stop/start any USB device can easily do so by altering the script and inserting your device's HWID.

You can find the hardware ID of of your Bluetooth device, (or any other USB device) with the lsusb command.

Substitute your own hardware device ID codes for the device that you wish stopped/started - pre/post suspend into both scripts.

The fields for the "VENDOR" and "PRODUCT" codes (found with the lsusb command ) must be substituted in the scripts above.

In the fields shown below, you must substitute/insert your own 4 digit (X2) alphanumeric hardware device ID codes in both scripts.

VENDOR="8087"
PRODUCT="0a2b"

Both "8087"` and "0a2b" must be swapped with your own device's hardware codes, (quotation marks included).


I hope my explanations about the required script modifications is not too confusing to understand.

Let me know how that works out for you, and I appreciated your honesty about the distro you were using (that's why I helped you out).

Good luck, and be sure to give Garuda a test drive (you just may like it). :smile:


5 Likes