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?

  • 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 ? – dschinn1001 Sep 23 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 ... – dschinn1001 Sep 23 at 21:39
up vote 10 down vote

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
$ echo fe998c62 4bb29a7c 40b2e670 10db71ed | sed 's/ //g;s/../\U&\n/g' | tac | tr -d '\n' ; echo

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.