Skip to content

Instantly share code, notes, and snippets.

@madkoding
Last active December 19, 2024 17:22
Show Gist options
  • Save madkoding/f3cfd3742546d5c99131fd19ca267fd4 to your computer and use it in GitHub Desktop.
Save madkoding/f3cfd3742546d5c99131fd19ca267fd4 to your computer and use it in GitHub Desktop.
Pairing bluetooth devices in dual boot with Linux Ubuntu and Windows 10/11

Pairing Bluetooth Devices in Dual Boot with Linux Ubuntu and Windows 10/11

Introduction

This guide provides updated instructions for pairing Bluetooth devices (such as keyboards or mice) in a dual-boot environment with Linux Ubuntu and Windows 10/11, incorporating community feedback and suggestions.

Instructions

1. Pair in Linux First

  • Pair your Bluetooth device in Linux. This is crucial to ensure the LinkKey remains consistent.
  • Note: Do not re-pair the device in Linux after completing the pairing in Windows.

2. Pair in Windows

  • Pair the Bluetooth device in Windows. Note the MAC address of the device for later steps.

3. Install chntpw in Linux

  • Install the chntpw package to read Windows registry keys:
    sudo apt-get install chntpw

4. Access Windows System Drive in Linux

  • Mount your Windows system drive and navigate to the System32 config folder:
    cd /[MountedDrive]/Windows/System32/config

5. Use chntpw to Access Registry

  • Execute the following command in the config folder:
    chntpw -e SYSTEM

6. Navigate to Bluetooth Registry Keys

  • In the chntpw console, navigate to the Bluetooth registry keys:
    cd \ControlSet001\Services\BTHPORT\Parameters\Keys

7. Find and Copy the Pairing Key

  • Use ls to list unique IDs and find your device's MAC address.
  • Retrieve the pairing key (hex code) associated with your device.

8. Edit Linux Bluetooth File

  • Edit the corresponding file in your Linux drive:
    sudo nano /var/lib/bluetooth/[Unique ID]/[Mac Address]/info
  • Replace the Key value in the [LinkKey] section with the pairing key from Windows.
  • If the [LinkKey] section is missing, add it manually.

9. Restart Bluetooth Service in Linux

  • Save the changes and restart the Bluetooth service:
    sudo service bluetooth restart

Additional Methods and Tips

  • Simplification with reged: Use reged to export Bluetooth pairing keys directly into a file for easier identification and copying.
  • Bluetooth LE Devices: For Bluetooth LE devices, the data storage might differ. Users should research specific steps for these devices.
  • Windows 11 Compatibility: This method is also compatible with Windows 11.
  • Multiple Bluetooth Receivers: If you have multiple Bluetooth receivers, ensure you identify and use the correct pairing key.
  • Changing Bluetooth MAC Address in Linux: If necessary, you can change the Bluetooth MAC address in Linux using the following commands:
    sudo hciconfig hci0 down
    sudo bluemoon -A
    sudo hciconfig hci0 up
    sudo systemctl restart bluetooth.service
  • Adding Missing [LinkKey] Section: If the [LinkKey] section is missing in the info file, you should add it manually.

Acknowledgements

Special thanks to the community members who provided valuable insights and suggestions, including nnnnicholas, kna0085, lguangyu, KeyofBlueS, bjoern-vh, Nielius, IgorRodriguez, princeofguilty, and others.

@b33ev
Copy link

b33ev commented Jan 14, 2024

I'm on Windows 11 and Computer\HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys is empty. But I have a paired mouse in W11. Any idea where the key is stored?

This is the solution: https://superuser.com/questions/1677881/bluetooth-pairing-on-dual-boot-of-windows-11-linux-or-some-os-else

@ForestEco
Copy link

I just successfully paired the keyboard this morning, then a sleep mode occurred when I returned from work and the keyboard wont pair with Ubuntu anymore, although I double checked the linking key harmonization is correct with Windows. Any idea why this might have happened?

@madkoding
Copy link
Author

@ForestEco Sleep mode usually have trouble with some bluetooth-wifi. Check your bluetooth model. If your notebook not fully support, check for experimental drivers or replace the wifi-bluetooth module with some other compatible like Intel AX

@bipox
Copy link

bipox commented Feb 28, 2024

It worked, thank you!
In case someone runs into the same issues as me:

Note the MAC address of the device for later steps.

I couldn't find a tutorial for Windows 11.
You can find the mac address under:
device manager -> bluetooth -> right click the desired device -> properties -> details -> in the list scroll to "bluetooth device address"

Use chntpw to Access Registry

If chntpw SYSTEM is supposed to open a new console then it didn't happen for me. But the command shared by @KeyofBlueS works (remove the commas!)

@chiragdhunna
Copy link

Am I the only one for whom this doesn't work.
PS : Followed all the steps.

@akaihola
Copy link

Am I out of luck if my Windows partition is encrypted?

@alllexx88
Copy link

@akaihola if you can mount it on Linux, it's fine, otherwise bad luck

@akaihola
Copy link

The guide also shows how to change the bluetooth mac address on Linux if necessary. Is this something that would solve the need to re-pair my headset whenever booting to the other OS?

@Omar-Alpjaly
Copy link

Omar-Alpjaly commented Jun 27, 2024

Windows 11 / Ubuntu 24.04

Mouse with Bluetooth 5.0 LE

I end up doing the reverse of this method to get it to work.
I tried copying the Long Term Key values from Windows to Linux, but that didn't work
but doing the reverse worked!

Here’s how you can do it:

First, Remove the current pairing of your mouse in Linux and pair it again.
Then, Note down the new MAC address and Long Term Key values, which you can find in \var\lib\bluetooth\...\{mac-address}\info

Now, reboot into Windows.

To modify the Bluetooth registry keys in Windows, you'll first need permission. Follow these steps:
1. Open the Registry Editor and navigate to ...\ControlSet001\Services\BTHPORT\Parameters\Keys
2. Right-click on the Keys folder, select 'Permissions', and add your Windows user. Grant it 'Full Control' permissions.
3. Relaunch Registry Editor

Next, rename the MAC address key of your mouse to match the one used in Linux (\var\lib\bluetooth\...\{mac-address})

(Keep the formatting as it is in Windows)
...\ControlSet001\Services\BTHPORT\Parameters\Keys\...\{mac-address}
...\ControlSet001\Services\BTHPORT\Parameters\Devices\{mac-address}

Then, navigate to ...\Keys\...\{mac-address}
and modify the LTK, ERand, and EDIV key values to match the corresponding Long Term Key values

After making these changes, restart your computer.

That’s it! Your setup should now be complete.

This method may not work with all devices, I'm having an issue with a Bluetooth 5.2 HeadPhone
When I pair it with Windows I can't find any key for the HeadPhone in ...\Parameters\Keys\...\
even with permission.

Copy link

ghost commented Jul 19, 2024

  1. Find and Copy the Pairing Key
    ...
    Retrieve the pairing key (hex code) associated with your device.

Note that you need some additional steps here to retrieve the correct key.

here is what you need to do:

ls
Node has 1 subkeys and 0 values
key name
<keyid>

cd <keyid>

ls
Node has 0 subkeys and 1 values
size type value name [value if type DWORD]
16 3 REG_BINARY <regid>

hex <regid>
Value <regid> of type REG_BINARY (3), data length 16 [0x10]
:00000 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX.......aU..'..

copy paste 17 hex number
remove spaces

key is in format
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX (34 letters)

add this to [LinkKey] section

@elmergj
Copy link

elmergj commented Aug 16, 2024

Windows 11 / Ubuntu 24.04

Mouse with Bluetooth 5.0 LE

I end up doing the reverse of this method to get it to work. I tried copying the Long Term Key values from Windows to Linux, but that didn't work but doing the reverse worked!

Here’s how you can do it:

First, Remove the current pairing of your mouse in Linux and pair it again. Then, Note down the new MAC address and Long Term Key values, which you can find in \var\lib\bluetooth...{mac-address}\info

Now, reboot into Windows.

To modify the Bluetooth registry keys in Windows, you'll first need permission. Follow these steps: 1. Open the Registry Editor and navigate to ...\ControlSet001\Services\BTHPORT\Parameters\Keys 2. Right-click on the Keys folder, select 'Permissions', and add your Windows user. Grant it 'Full Control' permissions. 3. Relaunch Registry Editor

Next, rename the MAC address key of your mouse to match the one used in Linux (\var\lib\bluetooth...{mac-address})

(Keep the formatting as it is in Windows) ...\ControlSet001\Services\BTHPORT\Parameters\Keys...{mac-address} ...\ControlSet001\Services\BTHPORT\Parameters\Devices{mac-address}

Then, navigate to ...\Keys...{mac-address} and modify the LTK, ERand, and EDIV key values to match the corresponding Long Term Key values

After making these changes, restart your computer.

That’s it! Your setup should now be complete.

This method may not work with all devices, I'm having an issue with a Bluetooth 5.2 HeadPhone When I pair it with Windows I can't find any key for the HeadPhone in ...\Parameters\Keys...\ even with permission.

Windows 11 / Ubuntu 24.04

Mouse with Bluetooth 5.0 LE

I end up doing the reverse of this method to get it to work. I tried copying the Long Term Key values from Windows to Linux, but that didn't work but doing the reverse worked!

Here’s how you can do it:

First, Remove the current pairing of your mouse in Linux and pair it again. Then, Note down the new MAC address and Long Term Key values, which you can find in \var\lib\bluetooth...{mac-address}\info

Now, reboot into Windows.

To modify the Bluetooth registry keys in Windows, you'll first need permission. Follow these steps: 1. Open the Registry Editor and navigate to ...\ControlSet001\Services\BTHPORT\Parameters\Keys 2. Right-click on the Keys folder, select 'Permissions', and add your Windows user. Grant it 'Full Control' permissions. 3. Relaunch Registry Editor

Next, rename the MAC address key of your mouse to match the one used in Linux (\var\lib\bluetooth...{mac-address})

(Keep the formatting as it is in Windows) ...\ControlSet001\Services\BTHPORT\Parameters\Keys...{mac-address} ...\ControlSet001\Services\BTHPORT\Parameters\Devices{mac-address}

Then, navigate to ...\Keys...{mac-address} and modify the LTK, ERand, and EDIV key values to match the corresponding Long Term Key values

After making these changes, restart your computer.

That’s it! Your setup should now be complete.

This method may not work with all devices, I'm having an issue with a Bluetooth 5.2 HeadPhone When I pair it with Windows I can't find any key for the HeadPhone in ...\Parameters\Keys...\ even with permission.

Hi, also need to change other values, if maybe it doesn't work....

I dit it as you did, by this reverse way, but it didn't works.

So, I also change the

  • IRK (IdentityResolvingKey) from Linux
  • Address Value, on Keys windows. So the value from linux shoul be change 3 times
    1 --> \ControlSet001\Services\BTHPORT\Parameters\Keys...{mac-address}
    2 --> \ControlSet001\Services\BTHPORT\Parameters\Devices{mac-address}
    3 --> \ControlSet001\Services\BTHPORT\Parameters\Keys...{mac-address}\Address (Here change the value os this QWORD)

That works for me......................👍👍👍👍

@barikata1984
Copy link

This is just a memo to pair a nice!nano v2 (like the board of Typeractive's Lily 58) on both Win11 and Ubuntu 22.04 simultaneously.

Prerequisites:

  • Follow up to Step 7 above.

8. Edit the Bluetooth file for your device

  • Edit the corresponding file in your Ubuntu:
sudo nano /var/lib/bluetooth/[Unique ID]/[Mac Address]/info
  • Replace the Keys of PeripheralLongTermKey and SlaveLongTermKey with the upper-cased hex value of LTK in the device registry, or appearing in the .reg exported with KeyofBlueS's method.
  • Add [IdentityResolvingKey] and set Key at the upper-cased hex value of CentralIRK in the device registry like:
[IdentityResolvingKey]
Key=YOUR_UPPER_CASED_CENTRAL_IRK

9. Restart Bluetooth service

  • Save the changes and restart the Bluetooth service:
sudo service bluetooth restart

@der-siebte-schatten
Copy link

I still have issue with my Microsoft Bluetooth Ergonomic Mouse. This one is really tricky.
Yes it can pair with up to 3 device, but if I pair it on both OS on my dual boot (Windows 11, LMDE 6), the mouse with always delete the older pairing because it's the same MAC address. So everytime I boot the other OS, I have to pair the device again and lose all preferences.

First, it's one of them changing MAC Address between each pairing because why not. That I can manage.
On Linux, I got 3 keys: [LongTermKey], [PeripheralLongTermKey]and [SlavelLongTermKey]. The two last ones are identical but the first one differs.
On Windows, only one key stamped as LTK. I got also ERand and EDiv but no IRK or CRK, even though there is a CEntralIRKStatus with a value of 1.

I never got a working combination. The best issue I got was to remove [LongTermKey] entirely and leave the two last ones with values I copied from Windows. After that, I got a stable connection on Linux (whereas all other tries resulted in connecting/disconnecting because key seemed wrong) but the mouse is blinking saying there is no connection.

Any ideas how to do on this one?

@chrisrharris
Copy link

chrisrharris commented Nov 18, 2024

I still have issue with my Microsoft Bluetooth Ergonomic Mouse. This one is really tricky. Yes it can pair with up to 3 device, but if I pair it on both OS on my dual boot (Windows 11, LMDE 6), the mouse with always delete the older pairing because it's the same MAC address. So everytime I boot the other OS, I have to pair the device again and lose all preferences.

First, it's one of them changing MAC Address between each pairing because why not. That I can manage. On Linux, I got 3 keys: [LongTermKey], [PeripheralLongTermKey]and [SlavelLongTermKey]. The two last ones are identical but the first one differs. On Windows, only one key stamped as LTK. I got also ERand and EDiv but no IRK or CRK, even though there is a CEntralIRKStatus with a value of 1.

I never got a working combination. The best issue I got was to remove [LongTermKey] entirely and leave the two last ones with values I copied from Windows. After that, I got a stable connection on Linux (whereas all other tries resulted in connecting/disconnecting because key seemed wrong) but the mouse is blinking saying there is no connection.

Any ideas how to do on this one?

I was finally able to get my Microsoft Explorer Mouse and Designer Compact Keyboard working, by some better guidance in this post
https://unix.stackexchange.com/a/413831. I had a similar experience to you, where mouse would connect then disconnect in a loop.

Important

  1. MAC changes on device repairing, and it's easy to miss if you're only visually looking at the begin and end of a MAC entry. So make sure you rename the directory
  2. With my Win11 and Microsoft devices, IRK is set in registry root folder level of Parameters\Keys\{Bluetooth-Controller-ID}' called CentralIRK. I used this value for setting any [IdentityResolvingKey] that's used for all the devices using this same Bluetooth Controller. Not sure if this was necessary, but I also added a [LocalSignatureKey] with this same value.
  3. Especially for my MS mouse, the only other section I needed was [LongTermKey], and it was extremely important to get the Rand and EDiv values byte-aligned as mentioned in the post. MS Designer Compact Keyboard did not care about these values.
  4. I deleted the other key sections, I can't say whether they are necessary in the longer term, but for now this is working for me

@der-siebte-schatten
Copy link

That's what was missing! I was missing the CentralIRK in the root folder level. I also got another key in that folder with an hex name but idk what it is for.
I had to add the [IdentityResolvingKey] section in info and delete the other useless one.

Now it works as well. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment