How to use bluetooth devices under two different operation systems

bluetoothmulti-boot

I've got an magic mouse and an apple bluetooth keyboard.

I usually run ubuntu on my computer, but sometimes I need to use windows 7 from an external disk.

Whenever I boot into the other system I have to pair my devices again.

Is there a way to make this work? I've already tried setting the hostname to be the same, but this didn't work.

Best Answer

Here I share what I learned about this, after struggled with it for quite a few days. I have a dual boot system with Windows 10 and up-to-date Debian testing, and would like to share the same Bluetooth mouse. Mine is a Razer Orochi mouse. I am giving all the credits for the following people and their work:

  1. http://forum.notebookreview.com/threads/dual-booting-and-bluetooth.739236/
  2. https://forums.solydxk.com/viewtopic.php?f=7&t=5251#p53746
  3. https://www.insanelymac.com/forum/topic/268837-dual-boot-bluetooth-pairing-solved/
  4. https://ubuntuforums.org/showthread.php?t=2390542&highlight=bluetooth+mouse+reboot (to obtain missing LinkKey in Ubuntu 18.04)

*EDIT: I discovered that a more consistent way is to pair it with Linux first, then go to Windows to change the pair key. Therefore, I am revising the answers here so it is a complete tutorial you can follow.

-- Linux First Method (so far so good!)

Before you start, I assume you have paired the mouse in both Windows and Linux at least once, so the corresponding registries are set. Boot to Linux and make sure the mouse works. I use Debian testing with KDE (Plasma 5), so it is pretty easy to pair it using the standard build-in Bluetooth packages. I am not too sure about Ubuntu, but I suppose the underlying processes are similar. Make sure the mouse is usable.

Change to root user (sudo won't do here) (just use command su or sux), navigate into the following location:

/var/lib/bluetooth/AA:AA:AA:AA:AA:AA/BB:BB:BB:BB:BB:BB

Where AAs are the adapter of your laptop, BBs are the mouse. There is one file in there called info. Edit this file with vi, nano or your favorite editor. Inside "info", you should see the following entry called LinkKey. The Key is a 32 character hex string. Copy and save this string in a text file somewhere in which both Linux and Windows can access, for example an external flash drive.

[LinkKey]
Key=XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Type=4
PINLength=0

Now boot into Windows. Without using the Bluetooth mouse (turn it off or set aside), under an administrator terminal, run this: psexec -s -i regedit.exe. You will have to download psexec first.

Navigate to the following key:

(LM)\ControlSet001\Services\BTHPORT\Parameters\Keys\(ID_Adapter)

In there, you should be able to see another ID that matches with your mouse. Right-click on the key and choose "Modify Binary Data".

Now it is time to find that file you saved and enter the 32 characters in 16 groups in the "normal order". Don't reverse the order, which is a Mac thing.

After this, close the registry and turn on the mouse! Wolla!

--- Windows First Method (not consistent, only for the record here)

First, you need to pair the mouse with Windows 10, and obtain the linkkey. To achieve this, you can either use the chntpw method in Linux (see link 1), or the psexec method in Windows. In Windows, under an administrator terminal, run this: psexec -s -i regedit.exe. You will have to download psexec first.

Obtain and export the key from the following place. Save it to a text file you can access later in Linux.

(LM)\ControlSet001\Services\BTHPORT\Parameters\Keys

Then boot to Linux; in this case, you probably have attempted pairing the mouse at least once before. I am assuming you did.

Change to a root user, go into the following location:

/var/lib/bluetooth/AA:AA:AA:AA:AA:AA/BB:BB:BB:BB:BB:BB

Where AAs are the adapter of your laptop, BBs are the mouse. There is one file in there called info. Edit this file with vi, nano or your favorite editor.

[LinkKey]
Key=A7XXXXXXXXXXXXXXXXXXXXXXXXXXXX89
Type=4
PINLength=0

The goal is to sandwich your key (all spaces and commas removed) between A7 and 89. A7 and 89 are critical for making this work. Why the sandwich? Honestly, I have no idea, but without it, it won't work for me. The key is no longer 8 bytes, but 16 bytes! So you will have 32 characters to sandwich. The final key will have a total length of 36 characters.

Reboot your Linux with fingers crossed. Finally, yah!