Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pairing bluetooth devices (keyboard or mouse) in dual boot with Linux Ubuntu and Windows 10

1) Pair ALL bluetooth devices in linux (it is to have the files you will need to edit later)

2) Pair ALL bluetooth devices in Windows 10. If you know how, get the MAC address id from your bluethooth keyboard, we will need it later

3) Reboot and go back to Linux

4) Install chntpw package, this is needed to read the registry keys from Wintendo

sudo apt-get install chntpw

5) Mount your Wintendo system drive in Linux and enter to this folder

cd /[MountedDrive]/Windows/System32/config

5) Execute this command inside that folder

chntpw -e SYSTEM

6) In the chntpw raised console, enter in the bluetooth registry keys list like this:

cd \ControlSet001\Services\BTHPORT\Parameters\Keys

7) run ls command to show you a Unique id lists

(...)\Services\BTHPORT\Parameters\Keys> ls
Node has 1 subkeys and 0 values
  key name
  <00f48d9e41aa>

Like this one equivalent to 00:F4:8D:9E:41:AA

8) Enter in each Unique id folder to search for your MAC address of your bluetooth device in each value name

(...)\Services\BTHPORT\Parameters\Keys> cd 00f48d9e41aa
(...)\BTHPORT\Parameters\Keys\00f48d9e41aa> ls
Node has 0 subkeys and 3 values
  size     type              value name             [value if type DWORD]
    16  3 REG_BINARY         <34885dd82480> <- This is our keyboard
    16  3 REG_BINARY         <34885db5f481>

9) Get the hex code (that we will call friendly: the pairing key) from the keyboard MAC address value

(...)\BTHPORT\Parameters\Keys\00f48d9e41aa> hex 34885dd82480
Value <34885dd82480> of type REG_BINARY (3), data length 16 [0x10]
:00000  BE 7F B1 99 23 29 D5 B2 6A E2 F6 96 2E FD 16 8A ....#)..j.......

10) So... we will copy the pairing key that use Wintendo to pair your device: BE7FB1992329D5B26AE2F6962EFD168A We will use this pairing key to make Linux pair our keyboard, without re-pairing again. We will use now de Unique Id, the MAC Address and edit this file in your Linux drive:

sudo nano /var/lib/bluetooth/[Unique ID]/[Mac Address]/info

sudo nano /var/lib/bluetooth/00\:F4\:8D\:9E\:41\:AA/34\:88\:5d\:d8\:24\:80/info

11) In the info file go to the [LinkKey] section and replace the Key value with the pairing key

Key=BE7FB1992329D5B26AE2F6962EFD168A

12) Save and restart the bluetooth service in Linux and you are ready to go

sudo service bluetooth restart
@nnnnicholas
Copy link

nnnnicholas commented Apr 20, 2021

These instructions are great except for one crucial error. You must pair to Linux BEFORE Windows (steps 1 and 2), or else the LinkKey copied in step 12 will not work as it will have changed way back in step 2. So to do this correctly, just invert steps 1 and 2. Great guide, thank you!

@kna0085
Copy link

kna0085 commented May 2, 2021

great guide!

Regarding the previous comment

These instructions are great except for one crucial error. You must pair to Linux BEFORE Windows (steps 1 and 2), or else the LinkKey copied in step 12 will not work as it will have changed way back in step 2. So to do this correctly, just invert steps 1 and 2. Great guide, thank you!

I think for more clarity steps need to be

  1. Pair in linux if the device was not paired previously (it is to have the files you will need to edit later)
  2. Pair in windows the device.
    2.1 It is importat that when you go back to linux, you don't need to pair the device again because if you do it the mac will change again and the configuration will not work. So, you need another keyboard to follow steps 3 to 12.

@bigbadmonster17
Copy link

bigbadmonster17 commented Jun 12, 2021

Just wanted to thank the author for this!!

Followed the instructions for my Windows 10/Fedora 34 - I used sudo dnf install instead of apt-get

You saved me from having to constantly use the screen keyboard so many thanks again

@madkoding
Copy link
Author

madkoding commented Jun 13, 2021

Updated gist and rewrited some steps based on @nnnnicholas @kna0085 comments o7 thanks guys

@lguangyu
Copy link

lguangyu commented Jun 14, 2021

On my windows 10 (21H1) and ubuntu (20.04) setup there are multiple keys from both sides, LTK (long term key), IRK (identity resolving key), slave LTK, etc. Also found a keyvalue called CSRK on registry not sure about what it is.
Apparently syncing both LTK and IRK does not work.

@madkoding
Copy link
Author

madkoding commented Jun 28, 2021

On my windows 10 (21H1) and ubuntu (20.04) setup there are multiple keys from both sides, LTK (long term key), IRK (identity resolving key), slave LTK, etc. Also found a keyvalue called CSRK on registry not sure about what it is.
Apparently syncing both LTK and IRK does not work.

just follow exactly the steps in here, meaby you entered in the wrong place, i got lastest dev windows 10 release and i didn't have any problems, got the same registry keys in the same place, nothing has changed

@bjoern-vh
Copy link

bjoern-vh commented Jul 12, 2021

Many thanks for this great explanation.

I followed your instructions and paired my Linux Mint 20.1 (64bit) before Windows 10 21H1 (64bit) and went back to linux.
Unfortunately I get no values:

`> cd ControlSet001\Services\BTHPORT\Parameters\Keys

(...)\Services\BTHPORT\Parameters\Keys> ls
Node has 1 subkeys and 0 values
key name
<001a7dda7107>

(...)\Services\BTHPORT\Parameters\Keys> cd 001a7dda7107

(...)\BTHPORT\Parameters\Keys\001a7dda7107> ls
Node has 1 subkeys and 1 values
key name

size type value name [value if type DWORD]
16 3 REG_BINARY

(...)\BTHPORT\Parameters\Keys\001a7dda7107>`

What I am doing wrong? Can anyone help me please?

Thanks a lot in advance!

@madkoding
Copy link
Author

madkoding commented Jul 12, 2021

@bjoern-vh try to re-pair in windows, needs to be connected and working. Reboot in linux and check again for the missing value

NOTE: this also works in Windows 11 insider version, so, is not a OS issue if you couldn't find the value, just try again and check slowly ;)

@bjoern-vh
Copy link

bjoern-vh commented Jul 12, 2021

I tried it agein, What I have done now:

  1. In Linux I paired the keyboard again. I tested it and it works as expected.
  2. Restart PC and boot into Windows,
  3. Pair the keyboard. Works fine.
  4. Restart PC and boot into Linux.
  5. Create temporary folder and mount my Windows drive.
  6. cd into ../System32/config
  7. chntpw -e SYSTEM
  8. cd ControlSet001\Services\BTHPORT\Parameters\Keys
  9. ls
Node has 1 subkeys and 1 values
  key name
  <d837799251be>
  size     type              value name             [value if type DWORD]
    16  3 REG_BINARY         <MasterIRK>
  1. cd d837799251be

I get the same result as before:

Node has 1 subkeys and 1 values
  key name
  <d837799251be>
  size     type              value name             [value if type DWORD]
    16  3 REG_BINARY         <MasterIRK>

I even try to cd one step deeper:


(...)\Parameters\Keys\001a7dda7107\d837799251be> ls
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 :-)

@madkoding
Copy link
Author

madkoding commented Jul 12, 2021

@bjoern-vh you already been there, look the path

\Parameters\Keys\001a7dda7107\d837799251be

just go to: \Parameters\Keys\001a7dda7107 and then do hex d837799251be

your UniqueId is 001a7dda7107 and your bluetooth mac address is : d837799251be

@bjoern-vh
Copy link

bjoern-vh commented Jul 13, 2021

OK, the marked values are in a completely different place for me.

After the input of hex d837799251be the only thing happens is an echoed "Cancelled" after a few seconds and I was thrown out of the registry editor.

? clueless

@madkoding
Copy link
Author

madkoding commented Jul 13, 2021

@bjoern-vh meaby the devices are in another control set. search for ControlSet002 or CurrentControlSet.

If not works, try this in wintendo:

  • Run regedit
  • Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Devices
  • Delete each subkey here (there's one for each Bluetooth device)
  • Reboot - you'll need to re-pair any bluetooth devices

then try again

@bjoern-vh
Copy link

bjoern-vh commented Aug 8, 2021

Sorry it's taken me so long to get back to you.

I have reinstalled both systems and still had the same error message when running "hex".

After some research on the internet, I came across the following post: https://unix.stackexchange.com/a/413831

I think I'm using Bluetooth LE (Low Energy) and the data is stored differently. Now everything works in any case :-)

@vatsdimri
Copy link

vatsdimri commented Jan 13, 2022

Thanks. It worked.

@S-trace
Copy link

S-trace commented Jan 20, 2022

This also works for Xbox Wireless Controller and headsets. Thank you for your guide.
Usually, MAC address increments by one after each pairing on multi-pairing mouses and keyboards, and stays intact for single-pairing devices.

You may need to move /var/lib/bluetooth/AD:AP:TE:RM:AC:00/cache/DE:VI:CE:MA:C0:00 file from old device mac to new device mac if you get following error:

src/device.c:read_device_records() Unable to load key file from /var/lib/bluetooth/AD:AP:TE:RM:AC:00/cache/DE:VI:CE:MA:C0:00: (No such file or directory)

@cfontes
Copy link

cfontes commented Jan 28, 2022

Works like a charm! Thanks for this!

@dwickycandralesmana
Copy link

dwickycandralesmana commented Feb 6, 2022

Thanks, it worked!

@Nielius
Copy link

Nielius commented Mar 27, 2022

I'm using Ubuntu 21.10, and I had to add the [LinkKey] section (it wasn't there before): I added

[LinkKey]
Key=7E22FCFB21A3C0918B765A3E05B31234
Type=4
PINLength=0

@danielw-mt
Copy link

danielw-mt commented Sep 18, 2022

Thank you! This is great. Works on Fedora 36

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