When booting between Debian and Windows on my laptop, I used to have to re-pair my Bluetooth devices each time. In this guide, I’ll show how I copied the pairing keys from Windows and used them in Debian so everything stays paired between reboots.
The pairing keys in Windows 10 are stored in the registry at
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\. However, they can only be accessed by the SYSTEM account. We’re going to use PsExec to run the Registry Editor with the SYSTEM account. Additionally, PsExec must be ran as Administrator, so were going to run it from an Administrator Command Prompt.
Download PsTools from Microsoft’s Windows Sysinternals site and extract it somewhere.
Open the Command Prompt as Administrator by hitting the Windows key, typing
cmd, then right-clicking on the Command Prompt menu entry, and finally selecting “Run as administrator”.
Navigate to where you extracted PsTools.
> cd /users/avery/downloads/pstools
- Launch the Registry Editor as the SYSTEM account by using PsExec.
> psexec64 -s -i regedit
Navigate to the branch
You should seen an entry for each Bluetooth device you’ve paired. The name of the key is the MAC address and the value is the pairing key. In my case, it looked something like this:
- Export the Keys branch by right-clicking and selecting Export. Save it somewhere you’ll be able it access from Linux.
Now that we have our pairing keys, we can boot back into Linux and change the keys. Go ahead and pair your devices the way you normally would, if you haven’t already. This will create the config files we’ll need to edit. Those files, however, can only be accessed by root, so we’ll need a root shell.
- Get a root shell.
$ sudo -s
- Find the directory for your Bluetooth controller.
# cd /var/lib/bluetooth/ && ls
- There’s probably only one, so move into that directory:
# cd 10:02:B5:89:D3:51
If there’s more than one, you can use
bluetoothctl to figure out which is your default.
# bluetoothctl list
- Inside this directory, there will be a directory for each paired device, named with it’s respective MAC address, with an
infofile inside each.
- Referencing the Registry entries you exported earlier, edit the
infofiles such that the
[LinkKey]matches the string of hex values from Windows.
# vim 34:88:5D:AE:80:22/info
For example, this is the edited entry for my mouse:
- When you’re done editing all the
infofiles, restart the Bluetooth service for the new settings to take effect.
# systemctl restart bluetooth
Thank you to Richard Vigars for writing an article that got me started on figuring this out.
Thank you to user thezeroth on Super User for providing an answer on how to access the pairing keys in the Registry.