212

When dual-booting Windows and Linux Mint/Ubuntu, you may find yourself having to re-pair your Bluetooth devices again and again. This will happen every time you switch OS.

Now, how do you prevent this?

I'm answering my own question with the following guide, which has been tested on:

  • Ubuntu 14.4
  • Ubuntu 20.04
  • Ubuntu 22.10
  • Linux Mint 17.X
  • Linux Mint 18.X
  • Linux Mint 21.X
  • Fedora 25

On the Windows side, this works with 7, 10, and 11.

2 Answers2

293

Why does this happen?

Basically, when you pair your device, your Bluetooth service generates a unique set of pairing keys. First, your computer stores the Bluetooth device's MAC address and pairing key. Second, your Bluetooth device stores your computer's MAC address and the matching key. This usually works fine, but the MAC address for your Bluetooth port will be the same on both Linux and Windows (it is set on the hardware level). Thus, when you re-pair the device in Windows or Linux and it generates a new key, that key overwrites the previously stored key on the Bluetooth device. Windows overwrites the Linux key and vice versa.

Bluetooth LE Devices: These may pair differently. I haven't investigated myself, but this may help Dual Boot Bluetooth LE (low energy) device pairing

How to fix

Using the instructions below, we'll first pair your Bluetooth devices with Ubuntu/Linux Mint, and then we'll pair Windows. Then we'll go back into our Linux system and copy the Windows-generated pairing key(s) into our Linux system.

  1. Pair all devices w/ Mint/Ubuntu
  2. Pair all devices w/ Windows
  3. Copy your Windows pairing keys in one of two ways:
    • Use psexec -s -i regedit.exe from Windows (harder). You need psexec as normal regedit doesn't have enough permissions to show this values.

      1. Go to "Device & Printers" in Control Panel and go to your Bluetooth device's properties. Then, in the Bluetooth section, you can find the unique identifier. Copy that (you will need it later). Note: on newer versions of windows the route to the device's properties is to go through Settings -> Bluetooth & devices -> Devices -> More devices and printer settings
      2. Download PsExec from http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx.
      3. Unzip the zip you downloaded and open a cmd window with elevated privileges. (Click the Start menu, search for cmd, then right-click the CMD and click "Run as Administrator".)
      4. cd into the folder where you unzipped your download.
      5. Run psexec -s -i regedit.exe
      6. Navigate to find the keys at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\BTHPORT\Parameters\Keys.  If there is no CurrentControlSet, try ControlSet001.
      7. You should see a few keys labels with the MAC addresses - write down the MAC address associated with the unique identifier you copied before. Note: If there are no keys visible after pairing, you likely need to add permissions to read (right click -> permissions) Keys\
      8. For convenience export it as a text file. click file -> export -> as text and save it to a shared partition/cloud.
    • Use chntpw from your Linux distro (easier). Start in a terminal then:

      1. sudo apt-get install chntpw

      2. Mount your Windows system drive in read-write mode

        • To find the drive use sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL. Depending on how your dual boot is setup its usually the first ntfs partition on the drive with /boot/efi. Note the NAME.
        • sudo mkdir /mnt/c
        • sudo mount --read-only /dev/<NAME> /mnt/c
        • To safely unmount the drive sudo umount /mnt/c
          • If you need to try a different drive or when finished all these instructions
      3. cd /[WindowsSystemDrive]/Windows/System32/config

        • on Windows 10 the root folder is "Windows", on Windows 7 it is "WINDOWS"
      4. chntpw -e SYSTEM opens a console

      5. Run these commands in that console:

        > # If there is no ControlSet001, then try CurrentControlSet
        > # on Windows 7, "services" below is lowercased.
        > cd ControlSet001\Services\BTHPORT\Parameters\Keys
        > ls
        # shows you your Bluetooth port's MAC address
        Node has 1 subkeys and 0 values
          key name
          <aa1122334455>
        > cd aa1122334455  # cd into the folder
        > ls  
        # lists the existing devices' MAC addresses
        Node has 0 subkeys and 1 values
          size     type            value name             [value if type DWORD]
            16  REG_BINARY        <001f20eb4c9a>
        > # Get the value of the REG_BINARY entry
        > hex 001f20eb4c9a
        => :00000 XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX XX ...ignore..chars..
        # ^ the XXs are the pairing key
        
      6. Make a note of which Bluetooth device MAC address matches which pairing key. The Mint/Ubuntu one won't need the spaces in-between.  Ignore the :00000.

  4. Go back to Linux (if not in Linux) and add our Windows key to our Linux config entries. Just note that the Bluetooth port's MAC address is formatted differently when moving from Windows to Linux - referenced as aa1122334455 in Windows in my example above. The Linux version will be in all caps and punctuated by ':' after every two characters - for example AA:11:22:33:44:55.  Based on your version of Linux, you can do one of these:
    • Before Mint 18/16.04 you could do this:
      1. sudo edit /var/lib/bluetooth/[MAC address of Bluetooth]/linkkeys - [the MAC address of Bluetooth] should be the only folder in that Bluetooth folder.

      2. This file should look something like this:

        [Bluetooth MAC]   [Pairing key]                 [digits in pin]  [0]
        AA:11:22:33:44:55 XXXXXXXXxxXXxXxXXXXXXxxXXXXXxXxX 5 0
        00:1D:D8:3A:33:83 XXXXXXXXxxXXxXxXXXXXXxxXXXXXxXxX 4 0
        
      3. Change the Linux pairing key to the Windows one, minus the spaces.

    • In Mint 18 (and Ubuntu 16.04) and later you may have to do this:
      1. Switch to root: sudo -i (In old versions of Ubuntu, 'su -')

      2. cd to your Bluetooth config location /var/lib/bluetooth/[bth port MAC addresses]

      3. Here you'll find folders for each device you've paired with. The folder names being the Bluetooth devices' MAC addresses and contain a single file info. In these files, you'll see the link key you need to replace with your Windows ones, like so:

        [LinkKey]
        Key=B99999999FFFFFFFFF999999999FFFFF
        
  5. Once updated, restart your Bluetooth service in one of the following ways, and then it works!
    • Ubuntu, Mint, Arch:

      sudo systemctl restart bluetooth 
      
    • Alternatively, reboot your machine into Linux.

  6. Reboot into Windows - it works!
Neil G
  • 218
  • 2
  • 14
  • 1
    This works thank you. Sad to say that Bluetooth in Windows works with no fuss. BT in Linux just sucks. I'm using Linux Mint 17.3 and my headset connects and then almost immediately disconnects. Every time I try BT in Linux it is a battle to get it to work. – RyanNerd Feb 24 '16 at 11:00
  • 7
    I came here having just installed Ubuntu 16.04LTS (dualboot with Windows) and having already paired my keyboard and mouse with it. Instead of copying the key from Windows to Ubuntu, I did it in reverse using chntpw: After mounting your windows partition and doing all the chntpw stuff @Mario Flores did, do ed "value name" in the chntpw terminal.

    Take the "Key=" in your bluetooth device's info file on Ubuntu and enter it like this in chntpw: ": XX XX XX XX XX ...." where XX is every 2 letters/numbers in the key. Then type s and it will be saved to the registry.

    Repeat if needed.

    – Sameer Puri Sep 17 '16 at 03:07
  • 6
    should it be: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters (so HLKM) – TiloBunt Sep 18 '16 at 00:44
  • My linkkey file was empty (like this guy http://askubuntu.com/questions/554053/where-are-bluetooth-link-keys-stored-in-ubuntu-14-10) ; Just added the mouse one

    28:18:zz:zz:zz:zz 0zzz84zzz1e4f51110a2zzzzezzzzd7b 0 6

    – TiloBunt Sep 18 '16 at 01:26
  • 1
    Only one upvote?! That is a travesty, because this is an excellent, awesome answer. – Mark E. Haase Nov 22 '16 at 17:46
  • These steps were very helpful, but for reasons unknown to me, it didn't work moving the Windows 10 key to the Fedora 25 key. Fortunately, moving the Fedora 25 key to Windows 10 worked great and now I don't need to pair/etc. anymore in either OS. – rickhg12hs Mar 12 '17 at 21:48
  • Copying keys from Ubuntu to Windows worked for me after copying the other way around fails. – Mygod Mar 18 '17 at 03:23
  • 1
    Perhaps a guide of relevance for others - https://brokkr.net/2015/09/26/bluetooth-dual-booting-sharing-a-bluetooth-device-between-linux-and-windows/ – consideRatio Oct 24 '17 at 09:19
  • 2
    Note that this process changes slightly for a distro that uses systemd. On Arch Linux, I used the Mint 18 method in step 4, and to restart the bluetooth service, I used systemctl restart bluetooth.service. – Caleb Reister Jan 09 '18 at 04:56
  • 1
    Saved me so much headache! – Malachi Mar 18 '18 at 13:36
  • 8
    By the way, if you've got a Bluetooth LE device, there will be a few more things to do and https://unix.stackexchange.com/questions/402488 may help you. – Frederick Zhang May 20 '18 at 11:39
  • used today on Ubuntu 18.04. works – TiloBunt Jun 18 '18 at 21:41
  • Not working for me. Based on this https://unix.stackexchange.com/questions/402488/dual-boot-bluetooth-device-pairing I think my Logitech MX Master mouse is pairing as Bluetooth LE in arch linux, but normal Bluetooth in Windows. That is, the registry entry in windows under local-adapter-mac only contains MasterIRK, and an entry for the mouse mac. – Todd Freed Jul 12 '18 at 18:58
  • 4
    In Windows 10, you'll find your keys at "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys". – Thomas Aug 16 '18 at 22:27
  • For some reason, there was no [LinkKey] there, I think it was buggy before. So I just added it at the end and it worked too. I wish I could upvote this everytime I come here, it's like the 4th time. – George Rappel Sep 25 '18 at 00:02
  • Still works on ubuntu 18.10, however this has spawned a second set of the same device on the gnome bluetooth manager. I simply had to choose the second unpaired device and it connected with no issues. Would love to give 100 rep to this, thanks! – MacK Feb 14 '19 at 12:59
  • If your BT device needed a PIN to pair in Windows (for example a keyboard), you probably need to make the Type=X part of the [LinkKey] section appear as Type=4. If the device needed no PIN to pair (such a mouse), most likely you will use Type=0. In Fedora 29, my mouse info file had no [LinkKey] section at all. I created it with the key value as described here, and Type=0 and PINLength=0 also in the [LinkKey] section. Values for the Link Key Type are defined here: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth.git/tree/include/net/bluetooth/hci.h#n467 . – Greg Apr 28 '19 at 22:55
  • 29
    Note, if you're doing it from Linux, but target recent Windows 10, the correct path is \ControlSet001\Services\BTHPORT\Parameters\Keys. – Dalibor Karlović Aug 02 '19 at 08:48
  • 1
    This would need to be repeated every time a device is re-paired, and for each new device. How about spoofing a different bluetooth mac address on one OS instead? – stewSquared Nov 25 '19 at 19:22
  • Awesome answer! I'm not sure why, but restarting the service wasn't working. I did a full reboot and now it's working. – OozeMeister Jan 03 '20 at 18:42
  • @stewSquared spoofing a different Bluetooth mac address on one OS instead would work if your device supports multiple hosts. It depends on your peripherals. At the time I wrote this, mine did not. – Mario Olivio Flores Jan 06 '20 at 15:13
  • 1
    You need sudo systemctl restart bluetooth-mesh.service on arch (and maybe other newer systems) And now for the less useful part of the comment: You @MarioOlivioFlores deserv a cookie for the genius way to remind people to up vote a good answer! :D – Emil Vatai Apr 03 '20 at 07:32
  • 1
    @EmilVatai Lol. Thanks. I updated the answer with your note about Arch. Thanks. :) – Mario Olivio Flores Apr 04 '20 at 11:49
  • Awesome answer, but shouldn’t the sentence “This usually works fine, but the MAC address for your Bluetooth port will be the same on both Linux and Windows” have the word “NOT” in it - as in, “will NOT be the same”? If the keys were the same on both systems to begin with, we wouldn’t have to do this song-and-dance, right? – Rob Cranfill Sep 04 '20 at 17:22
  • 1
    @RobCranfill actually, no. It is the key that is different, not the MAC address. – Mario Olivio Flores Sep 10 '20 at 07:29
  • This didn't work for me but the inverse did, i.e., copying the key from linux to windows. Just proceed the same way to retrieve the key from linux, but then use 'ed' in chntpw on the value in the windows registry, delete the current, and then write the key with spaces. Save it at the end. – Christian Fritz Feb 03 '21 at 20:41
  • 3
    On Ubuntu 20.04.2 LTS the bluetooth keys are stored under /var/lib/bluetooth/[bluetooth adapter address]/[bluetooth device address]/info – LMB Mar 11 '21 at 07:08
  • 1
    My Keys folders are completely empty. Might have to do something with the MPOW Dongle I'm using? – ptmr.io Apr 15 '21 at 08:08
  • My keys folder is empty too! I'm not using any dongle. Further, it's an LE device but those parameters are not found even in a global search of the entire HKLM hive. – Milind R Jun 30 '21 at 08:30
  • Nevermind! @ptmr.io the Keys folder is empty under normal regedit, but shows the expected content when run under under psexec. – Milind R Jun 30 '21 at 08:38
  • 1
    In Windows 10 recently I had to add 1 subfolder inside the Step 3. 6. \ControlSet001\Services\BTHPORT\Parameters\Keys

    \ControlSet001\Services\BTHPORT\Parameters\Keys\[mac port number]

    – euDennis Aug 07 '21 at 17:10
  • 1
    It seems things have been changed. In the folder there is no "single" key but different entries: AuthReq, EDIV, ERand (that could be a key), Keylength and LTK (could be a key too). In Linux Mint the file is probably "info" - but it seems to have more than just a key: I found at a different device [IdentityResolvingKey] Key=750AE663F5EF3DBA25C189C9D7DF4FC3

    [LocalSignatureKey] Key=ED912049F33B91D3A853DA38A921D8EE Counter=0 Authenticated=false

    [LongTermKey] Key=FEB7958C48325EA8EAF35DAE8306E660 Authenticated=0 EncSize=16 EDiv=48107 Rand=3746798756775818174

    – Arno Oct 29 '21 at 08:22
  • This suggestion is great, but it isn't working properly with Ubuntu 20.04 + Windows 11 (I know, recent upgrades). In the info file from the Ubuntu bluetooth config settings for my device I can only see [SlaveLongTermKey] which has many subfields: Key, Authenticated, EncSize, EDiv, Rand. I could find all of them from Windows using the suggestion above, but when replacing them they don't end up in the device pairing as it should. Leaving this here for those having the same issue as me! – schmat_90 Nov 09 '21 at 22:19
  • https://gist.github.com/Mygod/f390aabf53cf1406fc71166a47236ebf this script automates extracting Windows Bluetooth paring keys and it supports BLE.

    For BLE (Bluetooth Low Energy), you need more than LinkKey, which is under \ControlSet001\Services\BTHPORT\Parameters\Keys\[local MAC]\[remote MAC]

    – sdaffa23fdsf Jan 03 '22 at 07:29
  • This just worked for me on Ubuntu 20.04 + Windows 11. I am delighted to have come across this solution. – Steven C. Howell Apr 26 '22 at 14:19
  • Is there a way to get the bluetooth key from Windows when the filesystem is read-only due to hibernation? Why do chntpw and reged require a read/write filesystem just to read information? – SystemParadox Jan 15 '23 at 14:31
  • great, works on Ubuntu 22.10 – razor Feb 12 '23 at 10:39
  • still working in 2023 this solution :) – Carlos Jul 17 '23 at 19:17
  • 1
    I will add that I found it works either way. I just recorded the [LinkKey] from Linux and was able to edit the registry value to match that, and the device connected. – Steven C. Howell Sep 15 '23 at 16:42
  • I'm using a MX Master 3S mouse which supports connecting up to 3 devices, so the easiest thing for me to do is just use the "easy-switch & connect" button on the bottom when switching between Linux/Windows since it can store 3 pairing keys. Probably doesn't apply to everyone but thought I'd toss in my experience. – Bilbo Baggins Feb 06 '24 at 22:30
6

Firstly, many answers advise replacing the key in [linkKey] section of the /var/lib/bluetooth/<ADAPTOR_MAC_ADDRESS>/<DEVICE_MAC_ADDRESS>/info file. This section now seems to be called [LongTermKey]. Also, [LocalSignatureKey] seems to now be [IdentityResolvingKey]. Some answers only mention changing the key in [linkKey], but you also need Enc,Ediv and Rand entries and the key for [IdentityResolvingKey].

Secondly, the device mac address may not be constant. In the case of my Logitech G604 it increments by one each time I pair. I updated these scripts here to resolve this.

Instructions

  1. Boot into Linux and pair bluetooth device(s). You'll need the newly generated info and attributes files in /var/lib/bluetooth/<ADAPTOR_MAC_ADDRESS>/<DEVICE_MAC_ADDRESS>/.
  2. Reboot into Windows and pair bluetooth device(s).
  3. Download PSExec and run the following command from a Command Prompt running in Administator mode:
PsExec64.exe -s -i regedit /e C:\BTKeys.reg HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys
  1. Copy the C:\BTKeys.reg file to a USB key (or leave on C: drive if it's accessible from the Linux OS).
  2. Turn off bluetooth device(s) and boot back into Linux. Don't pair the device again in Linux. It might generate a new mac address, which will break the Windows pairing. (I don't know if this is normal, but it's what happens with my Logitech G604).
  3. Copy the BTKeys.reg file to your Linux filesystem.
  4. Run clean_reg_file.py --file_path BTKeys.reg --output clean.reg to clean the file (converts encoding to UTF8 and strips quotation marks).
  5. Run bluetooth_fix.py --reg_path clean.reg.
  6. From a terminal with sudo, navigate to /var/lib/bluetooth/<ADAPTOR_MAC_ADDRESS>/.
  7. Make a new directory corresponding to the device mac address from BTKeys.reg.
  8. Copy info and attributes from the old mac address directory to the new one.
  9. Open /var/lib/bluetooth/<ADAPTOR_MAC>/<NEW_DEVICE_MAC>/info and modify the values as per output from step 8.
  10. Restart bluetooth with sudo systemctl restart bluetooth.