Skip to content

Instantly share code, notes, and snippets.

@diffficult
Last active April 20, 2024 06:06
Show Gist options
  • Star 41 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save diffficult/574eb4807a7c61284dfe901f04382087 to your computer and use it in GitHub Desktop.
Save diffficult/574eb4807a7c61284dfe901f04382087 to your computer and use it in GitHub Desktop.
Bluetooth Pairing one device on Dual Boot of Windows & Linux - Stop having to Pair Devices

Bluetooth Pairing one device on Dual Boot of Windows & Linux - Stop having to Pair Devices

You may have experienced when dual booting that you need to re-pair your bluetooth devices (ie., Headphones, mouse, keyboard, etc) this usually happens because you have already paired the device with another operating system using the same bluetooth adapter when dual booting (either Linux or Windows).

Some devices cannot handle multiple pairings associated with the same MAC address (ie., bluetooth adapter). As per suggested on the ArchWiki you can fix this by re-pairing the device each time, but there's actually another solution to not do so each time you choose to use your device on a different OS.

How can we accomplish this?

Easy, just pair the device on a OS and copy the bluetooth keys generated to the other OS so our device doesn't notice the difference.

  1. Pair the devices on Linux
  2. Pair the devices on Windows
  3. Reboot to your Linux install and obtain the keys from Windows;
    • Install chntpw, we will use it to access the Windows install config registry values.
      1. Mount your Windows system drive,
      2. cd /[WindowsSystemDrive]/Windows/System32/config If you are using Nautilus probably it's mounted on /run/media/[username]
      3. chntpw -e SYSTEM, which in turn will open a new console
      4. while in that new console we need to navigate to the relevant registry key to extract the bluetooth key we need:
      >cd ControlSet001\Services\BTHPORT\Parameters\Keys
      >ls                           #to display the mac addresses of the bluetooth controller or dongle we use
      Node has 1 subkeys and 0 values
      key name
      <aa1122334455>
      >cd aa1122334455              #to get into our bluetooth controller
      >ls                           #again we use 'ls' to list all the currently associated bluetooth devices
      Node has 0 subkeys and 1 values
      size     type            value name             [value if type DWORD]
        16   REG_BINARY      <001f20eb4c9a>
      >hex 001f20eb4c9a            # we use 'hex' to display the value that belongs to this device mac address
      => :00000 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ...ignore..chars..
              # ^ the XXs after :0000 are the pairing key we are looking for, you can copy that for later
      1. You can now press q and press enter to quit chntpw and unmount your Windows system drive.
  4. Now in Linux let's just write the bluetooth key we got into our device config;
    • (This part of the process could vary from distro to distro, these instructions are working on Arch)
      • Open a terminal and switch to root with su
      • cd to your Bluetooth config location at /var/lib/bluetooth/BT:MA:CA:DD:RE:SS
      • Here you will find directories named after the MAC address of the devices you currently have associated, if you follow these instructions you can alreaddy see a directory named as your device MAC (ie.,AA:BB:CC:DD:EE:FF), what we want to do is to get into that directory as well and modify a file called info
      • using your favourite editor edit info and look for this at the end of the file
      [LinkKey]
      Key=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
      • replace the key with the one we already got from Windows, no spaces and save the file.
  5. After updating the key, all we need to do is to restart the bluetooth service, sudo systemctl restart bluetooth will do
  6. To test it turn on bluetooth on your computer and also your device and just click connect.
  7. After rebooting do the same on Windows, remember, you don't need to re-pair it anymore.

Sources
@TheDokT0r
Copy link

Thank you so much. It actually works!

@iliis
Copy link

iliis commented Jul 14, 2023

Thank you, this seems to work fine on Ubuntu 23.04 as well.

@MarM25
Copy link

MarM25 commented Jul 22, 2023

Just works, thanks a lot :)

@m1nicrusher
Copy link

For those devices that you cannot find [LinkKey] section in info, it might be a Bluetooth LE device which utilise a different pairing method. Check out the tutorial here for such devices.

@diffficult
Copy link
Author

For those devices that you cannot find [LinkKey] section in info, it might be a Bluetooth LE device which utilise a different pairing method. Check out the tutorial here for such devices.

thanks a lot for the heads up. I will double check on this gist and what you linked since I've recently reinstalled my linux machine but haven't used my Win11 install for a while so I need to repair a joystick and a couple of headphones.

@texeltexel2009
Copy link

Worked wonderfully!
No more frustrating removing-pairing each time I switch between OS.
Thx!

@AnkushMalaker
Copy link

Is there any way to turn this into a script? I can put everything till going into the chntpw shell into a bash or fish script, but after that I don't know what to do.

@diffficult
Copy link
Author

@AnkushMalaker I honestly didn't try to script it since I have setup this just a couple of times in my desktop. Seems that there's no way to automate the chntpw shell part since you leave your shell and you are into a new one once you load it.

After a quick search, there seems to be a workaround to pull data from that shell and automating inputs using expect. Since we are only getting data out the shell and not making changes there's a chance this is doable if you input the Bluetooth mac address so the script goes straight to look for that and just outputs the key value stored.

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