Skip to content

Instantly share code, notes, and snippets.

@madkoding
Last active October 10, 2024 08:33
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.

@danielw-mt
Copy link

Thank you! This is great. Works on Fedora 36

@Julka3561
Copy link

Thank you very much!!! You saved my day!

@amxxrsuhail
Copy link

instead of step 10 and 11, u can just the open files in ubuntu and search /var/lib/bluetooth find the info txt file and edit the key. Then do the step 12

@madkoding
Copy link
Author

instead of step 10 and 11, u can just the open files in ubuntu and search /var/lib/bluetooth find the info txt file and edit the key. Then do the step 12

Ok, I'll check that to add to gist. Thanks

Also sometimes win11 don't shows the pairing keys, gonna add that lines too

@OlliKantola
Copy link

Great guide! Worked perfectly and now my headphones are pairing automatically. Tested on two different computers, first one is running WIN10 + Ubuntu 18.04 and second one is running WIN10 + Ubuntu 20.04.

@zampierilucas
Copy link

Is there a way to use this method with the official xbox dongle?

@KeyofBlueS
Copy link

Hi 😄

If you do:

sudo reged -x "<WINDOWS_MOUNTPOINT>/Windows/System32/config/SYSTEM" "HKEY_LOCAL_MACHINE\SYSTEM" "\ControlSet001\Services\BTHPORT\Parameters\Keys" "/tmp/bt_keys.reg"

reged (it's part of chntpw) will export the bluetooth pairing keys in a file that you can simply cat:

cat "/tmp/bt_keys.reg"

and that will give:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys]

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\00f48d9e41aa]
"34885dd82480"=hex:BE,7F,B1,99,23,29,D5,B2,6A,E2,F6,96,2E,FD,16,8A

00f48d9e41aa is the bluetooth controller MAC (what you call Unique id)
34885dd82480 is the bluetooth device MAC
BE,7F,B1,99,23,29,D5,B2,6A,E2,F6,96,2E,FD,16,8A is the pairing key

With this method you can skip most of the steps here. Just copy the key and paste it (without commas obviously) in the relative info file, in this case is:
/var/lib/bluetooth/00:F4:8D:9E:41:AA/34:88:5D:D8:24:80/info

Moreover, with having that exported reg file, you can automate the whole process with a simple script.
Take a look here https://github.com/KeyofBlueS/bt-keys-sync

Regards 👍

@IgorRodriguez
Copy link

@KeyofBlueS , your comment was really useful. I followed the original instructions unsuccessfully as I have 2 different bluetooth receivers (only one in use) and for some reason I was getting an incorrect pairing key. With the registry file itself I was able to identify both pairing keys and use the right one in the Linux config. Thank you very much!

@KeyofBlueS
Copy link

@IgorRodriguez It’s a pleasure

@robot92000
Copy link

@Nielius I tried this on Linux Mint 21.1 (Equivalent to Ubuntu 22.04) and this did not work. My Link Key came from Windows 11. I don't have an option for the [LinkKey] entry on my 'info' file either. Any work arounds?

@princeofguilty
Copy link

princeofguilty commented Apr 15, 2023

an easy solution for this, change bluetooth mac address on linux

sudo hciconfig hci0 down
sudo bluemoon -A
sudo hciconfig hci0 up
sudo systemctl restart bluetooth.service

now you have a new identity on linux. pair with your device, note you have to do this on every restart.
now when you return to windows you won't need to pair again.

@yegormk
Copy link

yegormk commented May 14, 2023

@Nielius I tried this on Linux Mint 21.1 (Equivalent to Ubuntu 22.04) and this did not work. My Link Key came from Windows 11. I don't have an option for the [LinkKey] entry on my 'info' file either. Any work arounds?

I have Windows 11 - Ubuntu 22.04 Dual Boot System.
This instructions didn`t work for me for the first few times. But I reset my Bluetooth device, repeated the steps and it worked.
Also try to modify key for your bluetooth device using this steps:

  • Enter sudo mode using this command: sudo su -
  • Go to /var/lib/bluetooth/ using this command: cd /var/lib/bluetooth/
  • Chose your bluetooth module using unique id: cd [Unique ID]
  • Look through paired bluetooth devices(using "ls" command) and chose one that you need using this command: cd [Mac Address]
  • Enter "vim info" and hit enter
  • Modify your bluetooth device key using vim(take one from Windows as explained up above and switch with one that already here)
  • Save and close Vim
  • Not exiting sudo mode enter this command: sudo service bluetooth restart

Screenshot with most of commands attached below.
image

@edwinclement08
Copy link

Thanks so much guys, this helped a lot

@alllexx88
Copy link

@bjoern-vh
I experienced something similar with 2 different Logitech keyboards:

Node has 0 subkeys and 11 values
  size     type              value name             [value if type DWORD]
    16  3 REG_BINARY         <LTK>
     4  4 REG_DWORD          <KeyLength>               16 [0x10]
     8  b REG_QWORD          <ERand>
     4  4 REG_DWORD          <EDIV>                 51860 [0xca94]
    16  3 REG_BINARY         <IRK>
     8  b REG_QWORD          <Address>
     4  4 REG_DWORD          <AddressType>              1 [0x1]
    16  3 REG_BINARY         <CSRK>
     4  4 REG_DWORD          <OutboundSignCounter>      0 [0x0]
     4  4 REG_DWORD          <MasterIRKStatus>          1 [0x1]
     4  4 REG_DWORD          <AuthReq>                 45 [0x2d]

I don't understand the problem and appreciate any support :-)

I did find a solution. Looks like each time you pair a keyboard like that, there are two differences when compared to @madkoding instructions:

  1. Each time the keyboard gets paired, it gets a new MAC address (don't know whether it's a simple increment or a limited pool of addresses)
  2. You need to migrate at least two keys (you have three: LTK, IRK and CSRK, but mine doesn't have the latter)

What I did was:

  1. Pair your device in Linux, reboot to Windows
  2. Pair it in Windows, reboot to Linux
  3. Find the device entry using chntpw like you already did and save the keys in HEX format: hex LTK, hex IRK and hex CSRK (and remove the separating spaces between the bytes)
  4. Change saved Linux bluetooth device MAC address to match Windows one (in my case the difference was in the final hex digit): just rename /var/lib/bluetooth/<bt adapter mac>/<device mac>, in the quote above it should be changed to D8:37:79:92:51:BE.
  5. Change the keys in /var/lib/bluetooth/<bt adapter mac>/<new device mac>/info. Just compare Windows registry keys abbreviation to keys names from info, for me it was:
IRK:
[IdentityResolvingKey]
Key=...

LTK:
[PeripheralLongTermKey]
Key=...

And, it should then work after a reboot, or sudo service bluetooth restart. In my case, on Kubuntu 23.04, the system was glitching and crashing a lot after the bluetooth service restart, not sure what happened, but a reboot cured it.

@Tuhinpaul5
Copy link

Tuhinpaul5 commented Dec 10, 2023

I have a Fastrack FZ100 Bluetooth earbuds and dual booting to ubuntu completely messed up my Bluetooth for both windows and ubuntu. The Bluetooth takes longer to find the earbuds on windows and when I press connect it doesn't connect sometimes and sometimes it does. Even after connecting it keeps connecting and disconnecting. This only started happening after dualbooting. (Sometimes it says connected but the earbud still is in pairing mode)

@madkoding
Copy link
Author

Updated instructions... i'm no longer testing it, but i'll still receive the recommendations from other users to update this gist

@pnka
Copy link

pnka commented Dec 24, 2023

I successfully copied Windows 11 key to Debian 12. Thanks for the guide.

@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?

@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

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