Skip to content

Instantly share code, notes, and snippets.

@madkoding
Last active February 23, 2025 13:56
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.

If this helps u:

Please consider donate a little in this humble bitcoin wallet: bc1qrd3mexqu43qn0597d248725kdp3tr28252q64p

@noam-no
Copy link

noam-no commented Jan 3, 2025

Hello, my \ControlSet001\Services\BTHPORT\Parameters\Keys[Mac Address] is empty, what can I do ?
Screenshot from 2025-01-03 19-12-15

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

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

Thank you for the additional explanation. Only in "sudo su - " mode, it is possible to edit the contents inside [Unique ID], otherwises those files are "permission denied" and thus cannot be edited.

@A1exan10er
Copy link

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

Above, a comment has mentioned,
sudo reged -x "<WINDOWS_MOUNTPOINT>/Windows/System32/config/SYSTEM" "HKEY_LOCAL_MACHINE\SYSTEM" "\ControlSet001\Services\BTHPORT\Parameters\Keys" "/tmp/bt_keys.reg"
This will put everything into the file. Then read it using cat /tmp/bt_keys.reg.
I just completed the setup, works well.

@JoaoLucasGdS
Copy link

It half worked for me, now my linux install can ALWAYS connect, but my windows 11 need to forget and connect again every time, does anyone know how can this be solved?

@QkiZMR
Copy link

QkiZMR commented Feb 8, 2025

Retrieve the pairing key (hex code) associated with your device.

This part is incomplete. How do I receive pairing code, there's no command.

@QkiZMR
Copy link

QkiZMR commented Feb 8, 2025

service bluetooth restart

After restart BT adapter is unavailable.

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