2 minute read

Problem Description

In a dual-boot system with Windows and Linux (Ubuntu), the same Bluetooth device (e.g., mouse, keyboard, headset, etc.) cannot automatically connect to PC when switching from one OS to another.

Analysis

Each hardware device has a unique MAC address that is used for identification and communication. When a Bluetooth device connects to an OS, the OS stores the MAC address and encryption keys for that device. After switching to another OS, the new OS does not have the corresponding encryption keys stored, making it impossible for the Bluetooth device to connect automatically.

Solution

To resolve this issue, two OSes need to share the same Bluetooth device information, including MAC addresses and encryption keys. This can be achieved by manually copying the Bluetooth configuration parameters from one OS to another.

Steps to Share Bluetooth Configuration Between Windows and Ubuntu

Case: Bluetooth Low Energy (BLE) devices

1. Pair the Bluetooth device with Ubuntu first. Then switch to Windows and pair the same device there.

Screenshot: Ubuntu showing paired device MAC address

Screenshot: Windows showing paired device MAC address

2. Go back to Ubuntu and open two terminal windows.

3. In the first terminal, navigate to the Bluetooth configuration directory for Ubuntu:

sudo su -
cd /var/lib/bluetooth/<your-ubuntu-bluetooth-controller-mac-address>/<your-device-mac-address>/
nano info

Attention: Must check the <your-device-mac-address> folder name, it should be the same as the device MAC address you paired in Windows. If not, use command mv <old-name> <new-name> to rename it. (Check step 4 for Windows to find out the correct device MAC address.)

4. In the second terminal, navigate to the Bluetooth configuration directory for Windows:

cd /media/<your-ubuntu-username>/<your-windows-partition>/Windows/System32/config
chntpw -e SYSTEM
cd ControlSet001/Services/BTHPORT/Parameters/Keys/<your-windows-bluetooth-controller-mac-address>/<your-device-mac-address>/

Screenshot: Links Linux, Rechts Windows

Screenshot: Detailed Windows path to Bluetooth keys

5. Copy the corresponding key values from Windows to Ubuntu:

  • In Windows, use command cat IRK to look for the keys: IRK, LTK, EDIV, and ERand.
  • Attention: The byte order of ERand has to be inverted and then converted to a decimal value. For example, if ERand is 88 79 6A 5B 4C 3D 2E 1F, it should be converted to 1F2E3D4C5B6A7988 in hex, which is 2246800662264969608 in decimal. Then use this decimal value in Ubuntu.
  • In Ubuntu, open the info file in nano and locate the corresponding fields. Replace the values in Ubuntu with those from Windows.

Screenshot: Copying keys from Windows to Ubuntu

6. Save the changes in the info file in Ubuntu and exit nano.

7. Restart the Bluetooth service in Ubuntu:

sudo systemctl restart bluetooth

Note on Classic Bluetooth (BR/EDR) Devices

The steps above are for BLE devices. For classic Bluetooth devices (BR/EDR), the process is simpler. You only need to copy the LinkKey value from Windows to Ubuntu.

After completing these steps, the Bluetooth device should be able to connect automatically when switching between Windows and Ubuntu in a dual-boot system.

Q&A

  1. What if there are multiple Bluetooth devices? Situation - Multiple Devices Number
    • In Ubuntu terminal, check the info file for each device. The file includes the device name. An example entry looks like this:
      [General]
      Name=MX Anywhere 3s
      

      Screenshot: Situation - Multiple Devices Number - Correct Info

  2. What if the device still doesn’t connect?
    • Ensure the keys are copied correctly and the byte order for ERand is inverted properly and converted to decimal. Double-check the MAC addresses to ensure they match.
    • The device MAC address should be the same in both OSes. If they differ, rename the folder in Ubuntu to match the Windows MAC address. Screenshot: MAC Address
    • Step 3 shows how to rename the folder in Ubuntu.

Updated: