The article details the process of seamlessly configuring a Dell Bluetooth keyboard for dual-system use with Windows 11 and Ubuntu 22, covering pairing, registry key migration, and Bluetooth configuration adjustments for optimal performance.
A few months ago, I purchased a Dell Bluetooth keyboard for use with my desktop PC, which has both Windows 11 and Ubuntu 22 installed. This article will share my findings and the steps I have taken to get the keyboard to work seamlessly with both operating systems.
This is essentially what I have done:
- Pair the keyboard on Ubuntu 22 first, so as to create the necessary configuration files
- Reboot to Windows and pair it under Windows, so as to create the needed registry keys
- Reboot to Ubuntu and update various Bluetooth configuration files to reflect the latest values from the attempt to pair with Windows
Step (3) is needed because most Bluetooth devices will generate new pairing keys if you pair them with a new host, invalidating any previously paired connections. If your device can pair with a new host without invalidating existing connections, a simpler workaround would be to pair the device under Ubuntu as usual, purchase a separate Bluetooth dongle and configure Windows to use this Bluetooth dongle instead of the built-in Bluetooth device. This is trivial and will not be covered in this article.
To note, the default installation of Ubuntu 22 may have problems with Bluetooth keyboard on some hardware. If this is the case for you, please follow the instructions here to update to the latest Bluetooth kernel. The commands that I have used are summarized below:
wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.66.tar.xz
tar xvf bluez-5.66.tar.xz
cd bluez-5.66
sudo apt-get update
sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev python3-docutils
./configure --enable-library
make
sudo make install
reboot
It goes without saying that you need not attempt the above steps if your Bluetooth keyboard already works with the default Ubuntu installation.
To migrate the Bluetooth pairing keys from Windows to Ubuntu, I followed the instructions from this Github note, adjusted to suit my installation. For what it’s worth, you will not be able to view the registry branch which contains the Bluetooth pairing keys (HKLM\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys) using regedit
due to Microsoft security policy. If you try to do so, you will simply see an apparently empty branch:
Fortunately, these keys can easily be viewed on Ubuntu by using the chntpw
package. Install it first with apt-get
:
sudo apt-get install chntpw
Once installed, open the Windows registry file:
cd /[MountedDrive]/Windows/System32/config
chntpw -e SYSTEM
cd \ControlSet001\Services\BTHPORT\Parameters\Keys
ls
Use ls
to list the unique IDs and find the Bluetooth controller MAC address. There should only be one or two entries and it should not take long to identify the one we are interested in. Next, identify the keyboard MAC address. The MAC address should be similar to the address shown inside Ubuntu’s Bluetooth configuration panel. Some recent devices, like my Dell keyboard, will generate a new MAC address upon every new pairing attempt, which only slightly differs from the old address by a few bytes. If this happens to you, you will need to be careful in order to pick the right address.
Once you have picked the correct address, switch to the selected registry branch with cd
and type hex LTK
to view the value of the Long Term Key (LTK) associated with the pairing. In the following example, the controller MAC address is d4:54:8b:59:37:af
and the keyboard MAC address is dc:80:ca:19:0c:00
.
cd d4548b5937af
cd dc80ca190c00
(...)\Parameters\Keys\d4548b5937af\dc80ca190c00> hex LTK
Value <LTK> of type REG_BINARY (3), data length 16 [0x10]
:00000 6F 52 A9 23 F6 E9 DE 53 EE 46 06 BA 9B FF AB B7 oR.#...S.F......
Now that we have identified the LTK value, port it over to Ubuntu by editing the Bluetooth configuration file:
sudo nano /var/lib/bluetooth/[Controller Unique ID]/[Device Mac Address]/info
You will then see the contents of this file:
[General]
Name=Dell
Appearance=0x03c1
AddressType=static
SupportedTechnologies=LE;
Trusted=true
Blocked=false
WakeAllowed=true
Services=00001800-0000-1000-8000-00805f9b34fb;0000180a-0000-1000-8000-00805f9b34fb;0000180f-0000-1000-8000-00805f9b34fb;
[ConnectionParameters]
MinInterval=6
MaxInterval=7
Latency=23
Timeout=300
[IdentityResolvingKey]
Key=144EAC2271704E8D0A3D38B51B819257
[LongTermKey]
Key=354D32244559AD7D14AA8518B55B0F83
Authenticated=1
EncSize=16
EDiv=22491
Rand=7153367595019908080
[DeviceID]
Source=2
Vendor=2362
Product=10336
Version=8
Replace the Key
value in the [LongTermKey]
with the pairing key taken from Windows registry. For example, if the value from the Windows registry is 6F 52 A9 23 F6 E9 DE 53 EE 46 06 BA 9B FF AB B7
, you should update the value in the info file to 6F52A923F6E9DE53EE4606BA9BFFB7
. Take note that the names of the keys may vary slightly depending on the types of Bluetooth devices you are connecting. If necessary, repeat the same steps to also migrate the value of the IRK under over to Ubuntu, under section [IdentityResolvingKey]
. If the MAC address of the device as stored in Ubuntu differs from the one stored in Windows, you will need to rename the Linux folder to reflect the value stored in Windows, which is also the latest value used by the device.
Save the configuration file and restart Blueooth services:
sudo service bluetooth restart
At this point, try to open Ubuntu’s Bluetooth configuration panel and connect to your keyboard. If you are lucky, everything will be in order and your Bluetooth keyboard should work fine.
If things don’t work yet, take note that some Bluetooth devices will generate other keys which will also need to be transferred from Windows. Navigate to the registry branch which contains the pairing info, and list all keys with ls
:
ls
Node has 0 subkeys and 8 values
size type value name [value if type DWORD]
16 3 REG_BINARY <LTK>
4 4 REG_DWORD <KeyLength> 16 [0x10]
8 b REG_QWORD <ERand>
4 4 REG_DWORD <EDIV> 6398 [0x18fe]
16 3 REG_BINARY <IRK>
8 b REG_QWORD <Address>
4 4 REG_DWORD <AddressType> 1 [0x1]
4 4 REG_DWORD <AuthReq> 45 [0x2d]
Here, you will see that there are other values such as KeyLength
, ERand
and EDIV
that might need to be migrated. Take, for example, the value for ERand
:
Value <ERand> of type REG_QWORD (b), data length 8 [0x8]
:00000 10 9F B4 C0 9C 4F ED F7 .....O..
Windows stores the values of ERand
as hexadecimal with its least significant byte first (little-endian format) whereas Ubuntu stores the value as a decimal value. We will therefore need to convert the values appropriately. In the above example, the hexadecimal value is F7ED4F9CC0B49F10
, therefore the decimal value is 17865022831515180816
. In the Bluetooth info configuration file, under section LongTermKey
, we will then need to update the value of Rand=
to this value:
[LongTermKey]
Key=354D32244559AD7D14AA8518B55B0F83
Authenticated=1
EncSize=16
EDiv=22491
Rand=17865022831515180816
Repeat the same steps for other values such as EncSize
and EDiv
. For EDiv
, take note that if the key type is REG_DWORD
, you will only need to transfer the value over without having to convert it. Only REG_BINARY
and REG_QWORD
values need to be converted. For EncSize
, the default value of 16 should work for most devices and you usually do not have to modify this value.
Once you have confirmed that all key values are correct, restart the Bluetooth service (or reboot the machine if necessary), and you will now be able to use your Bluetooth keyboard under both Windows and Ubuntu. The same steps can be applied to other Bluetooth devices such as mice or speakers, to allow for seamless functionality across both Windows and Ubuntu operating systems.