Ubuntu 18.04系统下RTL8761BU蓝牙适配器驱动问题终极解决方案最近在给一台运行Ubuntu 18.04的台式机添加蓝牙5.0适配器时遇到了一个颇为棘手的驱动问题。这款型号为RTL8761BU的蓝牙芯片在Linux系统中的支持并不完善导致许多用户在安装后无法正常使用。本文将详细介绍从问题诊断到最终解决的完整流程帮助遇到类似问题的开发者快速找到解决方案。1. 问题诊断与初步排查当我们将RTL8761BU蓝牙适配器插入Ubuntu 18.04系统的USB接口后首先需要确认系统是否识别到了这个设备。打开终端执行以下命令查看USB设备列表lsusb在输出结果中你应该能看到类似这样的条目Bus 001 Device 004: ID 0bda:8771 Realtek Semiconductor Corp. Bluetooth Radio如果设备没有被列出可能是物理连接问题或USB端口供电不足。尝试更换USB端口或使用带电源的USB集线器。接下来检查内核日志以获取更详细的错误信息dmesg | grep -i bluetooth典型的错误输出可能包含以下关键信息[ 123.456789] Bluetooth: hci0: RTL: examining hci_ver0a hci_rev000b lmp_ver0a lmp_subver8761 [ 123.456790] Bluetooth: hci0: RTL: rom_version status0 version1 [ 123.456791] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761a_fw.bin [ 123.456792] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761a_config.bin [ 123.456793] Bluetooth: hci0: RTL: unknown project id 14这里有几个关键点需要注意系统错误地尝试加载rtl8761a的固件而实际上我们需要的是rtl8761bu的固件unknown project id 14错误表明固件与硬件不匹配内核驱动存在识别错误需要修正2. 获取正确的固件文件RTL8761BU蓝牙适配器需要两个固件文件才能正常工作rtl8761bu_fw.binrtl8761bu_config.bin这些文件通常不包含在标准的Linux固件包中需要手动获取。以下是获取固件的几种方法方法一从Linux内核源码仓库获取wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/rtl_bt/rtl8761bu_fw.bin wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/rtl_bt/rtl8761bu_config.bin方法二从GitHub社区获取wget https://github.com/Realtek-OpenSource/android_hardware_realtek/raw/rtk1395/bt/rtkbt/Firmware/BT/rtl8761bu_fw wget https://github.com/Realtek-OpenSource/android_hardware_realtek/raw/rtk1395/bt/rtkbt/Firmware/BT/rtl8761bu_config mv rtl8761bu_fw rtl8761bu_fw.bin mv rtl8761bu_config rtl8761bu_config.bin获取固件后将它们复制到正确的目录sudo cp rtl8761bu_*.bin /lib/firmware/rtl_bt/ sudo chmod 644 /lib/firmware/rtl_bt/rtl8761bu_*.bin3. 修改内核驱动以正确识别RTL8761BU即使有了正确的固件文件Ubuntu 18.04默认的内核驱动可能仍然无法正确识别RTL8761BU芯片。这是因为驱动中存在设备识别表需要更新。3.1 获取当前内核源码首先确定当前运行的内核版本uname -r输出类似5.4.0-80-generic然后获取对应的内核源码sudo apt-get install linux-source-$(uname -r | cut -d- -f1) tar xf /usr/src/linux-source-$(uname -r | cut -d- -f1).tar.xz cd linux-source-$(uname -r | cut -d- -f1)3.2 修改蓝牙驱动代码我们需要修改drivers/bluetooth/btrtl.c文件添加对RTL8761BU的支持。找到static const struct id_table部分添加以下条目{ IC_MATCH_FL_LMPSUBV, 0x8761, rtl8761bu, .config_needed true, .has_rom_version true, .fw_name rtl_bt/rtl8761bu_fw.bin, .cfg_name rtl_bt/rtl8761bu_config.bin},同时在static const struct id_table数组中添加RTL8761BU的USB设备ID{ USB_DEVICE_INTERFACE_CLASS(0x0bda, 0x8771, 0xe0) },3.3 编译并安装修改后的驱动保存修改后编译并安装新的驱动模块make -C /lib/modules/$(uname -r)/build M$(pwd)/drivers/bluetooth modules sudo cp drivers/bluetooth/btrtl.ko /lib/modules/$(uname -r)/kernel/drivers/bluetooth/ sudo depmod -a4. 加载驱动并验证功能完成上述步骤后重新加载蓝牙驱动sudo modprobe -r btusb btrtl sudo modprobe btusb插入蓝牙适配器再次检查内核日志dmesg | grep -i bluetooth正确的输出应该显示加载了正确的固件[ 123.456789] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761bu_fw.bin [ 123.456790] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761bu_config.bin [ 123.456791] Bluetooth: hci0: RTL: fw version 0x0999646b使用hciconfig检查蓝牙设备状态hciconfig -a输出应显示设备已正确初始化hci0: Type: Primary Bus: USB BD Address: 00:1A:7D:DA:71:13 ACL MTU: 1021:8 SCO MTU: 64:1 UP RUNNING PSCAN ISCAN RX bytes:1002 acl:0 sco:0 events:54 errors:0 TX bytes:3595 acl:0 sco:0 commands:54 errors:0 Features: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH HOLD SNIFF PARK Link mode: SLAVE ACCEPT5. 常见问题与高级调试即使按照上述步骤操作仍可能遇到一些问题。以下是几个常见问题及其解决方案问题1固件加载成功但蓝牙功能不正常尝试重置蓝牙适配器sudo hciconfig hci0 reset问题2设备频繁断开连接可能是USB电源管理导致的问题禁用USB自动挂起echo options btusb enable_autosuspend0 | sudo tee /etc/modprobe.d/btusb_disable_autosuspend.conf sudo modprobe -r btusb sudo modprobe btusb问题3蓝牙管理器无法发现设备确保蓝牙设备处于可发现模式hciconfig hci0 piscan对于更深入的调试可以使用bluetoothctl工具bluetoothctl [bluetooth]# power on [bluetooth]# agent on [bluetooth]# default-agent [bluetooth]# scan on6. 自动化脚本与长期解决方案为了简化整个过程可以创建一个安装脚本来自动完成这些步骤。以下是一个示例脚本#!/bin/bash # 下载固件 wget -O /tmp/rtl8761bu_fw.bin https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/rtl_bt/rtl8761bu_fw.bin wget -O /tmp/rtl8761bu_config.bin https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/rtl_bt/rtl8761bu_config.bin # 安装固件 sudo mkdir -p /lib/firmware/rtl_bt sudo cp /tmp/rtl8761bu_*.bin /lib/firmware/rtl_bt/ sudo chmod 644 /lib/firmware/rtl_bt/rtl8761bu_*.bin # 安装编译依赖 sudo apt-get update sudo apt-get install -y build-essential linux-headers-$(uname -r) # 下载并修改内核源码 git clone --depth 1 -b v$(uname -r | cut -d- -f1) git://git.launchpad.net/~ubuntu-kernel/ubuntu/source/linux/git/bionic cd bionic/drivers/bluetooth # 应用补丁 cat EOF | patch -p1 --- a/btrtl.c b/btrtl.c -XXX,XX XXX,XX { IC_MATCH_FL_LMPSUBV, 0x8761, rtl8761bu, .config_needed true, .has_rom_version true, .fw_name rtl_bt/rtl8761bu_fw.bin, .cfg_name rtl_bt/rtl8761bu_config.bin}, EOF # 编译并安装驱动 make -C /lib/modules/$(uname -r)/build M$(pwd) modules sudo cp btrtl.ko /lib/modules/$(uname -r)/kernel/drivers/bluetooth/ sudo depmod -a # 重新加载驱动 sudo modprobe -r btusb btrtl sudo modprobe btusb echo 安装完成请重新插入蓝牙适配器将此脚本保存为install_rtl8761bu.sh然后赋予执行权限并运行chmod x install_rtl8761bu.sh sudo ./install_rtl8761bu.sh7. 系统升级与兼容性考虑Ubuntu 18.04使用的Linux内核版本较旧对新硬件的支持有限。如果可能考虑升级到更新的Ubuntu版本如20.04或22.04这些版本的内核已经包含了对RTL8761BU的更好支持。对于必须使用Ubuntu 18.04的环境可以考虑安装更新的HWEHardware Enablement内核sudo apt-get install --install-recommends linux-generic-hwe-18.04升级内核后可能不再需要手动修改驱动代码只需确保固件文件正确安装即可。