9

I have an iMac with both macOS and Ubuntu on it. I want to be able to use my Bluetooth mouse and keyboard with both operating systems without re-pairing every time I switch OS.

Has anyone had this problem and figured out a solution?

2
  • How did you install dual-boot (Mac OSX with Ubuntu 18.04 ?) - is Ubuntu installed on to extern usb-harddisk and grub is running on usb-harddisk ? - or is it different at your site ? Sep 23, 2018 at 21:26
  • is this not for safety purpose, that bluetooth is disabled, when you leave the OS ? - in case computer would be stand-by after log-out ... and in case bluetooth is enabled, then there would be less safety ... Sep 23, 2018 at 21:39

1 Answer 1

12
+500

The answers to this question give you the general idea, though a bit vague on the macOS side, so I'll spell out the procedure I used.

OS versions as follows. The file names and locations appear to be subject to change according to versions, so this is what worked for me.

  • MacOS High Sierra 10.13.1
  • Ubuntu 17.04

I am assuming that you have a filesystem (USB key or whatever) that is at least read-write in MacOS and readable in Ubuntu.

The general idea is that when you pair a device to an OS, a unique link key is generated, which is necessary for authentication next time the pairing is active. You can transfer these link keys from MacOS pairings to Ubuntu pairings such that the pairings work in both OSes.

  1. Boot Ubuntu
  2. Pair device(s) as usual
  3. Reboot into MacOS
  4. Pair device(s) as usual
  5. In a terminal window type: sudo defaults read com.apple.bluetoothd.plist LinkKeys. This will give you output something like:
{
    "a0-99-9b-16-43-d2" =     {
        "00-1f-20-47-e5-22" = <4d6b002f 37584c09 ee219365 b78ba03e>;
        "04-0c-ce-3d-15-4d" = <fe998c62 4bb29a7c 40b2e670 10db71ed>;
    };
}

Here a0-99-9b-16-43-d2 is the MAC address of the bluetooth adapter on my system.

Following that are the MAC addresses of devices that I have paired (00-1f-20-47-e5-22 and 04-0c-ce-3d-15-4d and the link keys associated with those pairings (4d6b002f 37584c09 ee219365 b78ba03e and fe998c62 4bb29a7c 40b2e670 10db71ed respectively).

  1. Redirect this output to a file visible to both MacOS and Ubuntu:
sudo defaults read com.apple.bluetoothd.plist LinkKeys > /Volumes/4T/linkkeys.txt
  1. Switch off all devices that you have paired
  2. Reboot into Ubuntu. Do not turn on your bluetooth devices yet. Hopefully you have a wired keyboard and mouse to use at this point
  3. Open a terminal window
  4. Stop the bluetooth service:
sudo service bluetooth stop
  1. Look in the directory /var/lib/bluetooth. You should see a subdirectory entry for the bluetooth adapter MAC address, formatted like A0:99:9B:16:43:D2. Inside that you should see subdirectories for each device MAC address, like 00:1F:20:47:E5:22 and 04:0C:CE:3D:15:4D. Inside those directories you will find files named info. Edit these files with your favourite editor:
sudo gedit /var/lib/bluetooth/A0:99:9B:16:43:D2/00:1F:20:47:E5:22/info
sudo gedit /var/lib/bluetooth/A0:99:9B:16:43:D2/04:0C:CE:3D:15:4D/info
  1. In these files you'll find a Key entry. This key needs to be made the same as what you found in MacOS, but with some important formatting differences:
    • spaces removed
    • hex digits in uppercase
    • byte-swapped 128-bit integer (i.e. split into 2 hex digit chunks and reversed)

You can achieve this as follows:

$ echo 4d6b002f 37584c09 ee219365 b78ba03e | sed 's/ //g;s/../\U&\n/g' | tac | tr -d '\n' ; echo
3EA08BB7659321EE094C58372F006B4D
$ echo fe998c62 4bb29a7c 40b2e670 10db71ed | sed 's/ //g;s/../\U&\n/g' | tac | tr -d '\n' ; echo
ED71DB1070E6B2407C9AB24B628C99FE
$ 

Edit these reformatted keys into the Key entry of the appropriate info files. Most likely sudo will be required.

  1. Re-start the bluetooth service:
sudo service bluetooth start
  1. Now turn on your bluetooth devices. They should be recognised and the pairings active/valid in both MacOS and Ubuntu.

Update: The pairings seem to have persisted through upgrades on both MacOS and Ubuntu. I'm now running 10.13.6 and 18.04 respectively and have not yet had to redo this procedure.

5
  • 1
    I cannot comment to Digital Trauma's answer, so I will mention here that the bluetooth key format in MacOs has been altered recently, and the reversion is meanwhile no longer needed. So, when copying the key form MacOs to Linux (step 12), one needs only to transform the letters to uppercase.
    – Nizar
    Mar 16, 2020 at 5:11
  • @Nizar thanks for the info. Once I get a chance to try it out, I'll update. Mar 16, 2020 at 15:27
  • Can you use this solution for 2 separate computers? How would it work for 2 computers being on at the same time?
    – stpoa
    Nov 9, 2020 at 14:12
  • @stpoa I don't see any reason why it wouldn't work for 2 separate computers. But yes, if the 2 computers are on at the same time, both within bluetooth connectivity distance of the keyboard, then I doubt it will go very well. I don't know the details of the bluetooth protocol, but I would imagine you'd get MAC address collisions, much like you do with ethernet when you have duplicate MAC addresses. If you're lucky, one of the computers might disable its BT pairing. If not, I would expect all kinds of undefined, unexpected behavior. xkcd.com/292 Nov 9, 2020 at 16:35
  • 1
    This does not work anymore in Monterey. Bluetooth keys are now stored in the keychain. See askubuntu.com/a/1382510/435809
    – whoKnows
    Jan 8, 2022 at 2:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .