Keeping Bluetooth devices paired between Linux and Windows
Source
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.
Getting the keys out of Windows
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.
1 |
|
- Launch the Registry Editor as the SYSTEM account by using PsExec.
1 |
|
Navigate to the branch
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\
.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:
1 |
|
- Export the Keys branch by right-clicking and selecting Export. Save it somewhere you'll be able it access from Linux.
Updating the keys in 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.
1 |
|
- Find the directory for your Bluetooth controller.
1 |
|
- There's probably only one, so move into that directory:
1 |
|
If there's more than one, you can use bluetoothctl
to
figure out which is your default.
1 |
|
- Inside this directory, there will be a directory for each paired
device, named with it's respective MAC address, with an
info
file inside each.
1 |
|
- Referencing the Registry entries you exported earlier, edit the
info
files such that theKey
under[LinkKey]
matches the string of hex values from Windows.
1 |
|
For example, this is the edited entry for my mouse:
1 |
|
- When you're done editing all the
info
files, restart the Bluetooth service for the new settings to take effect.
1 |
|
Acknowledgments
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.