📶

Proxmoxの仮想サーバ上でBluetoothデバイスへアクセスする

2025/02/09に公開

実現したいこと

物理サーバであるミニPCのBluetoothを経由し、仮想サーバ上でBluetoothデバイスの情報へアクセスすることを目指します。

前提環境

  • (物理サーバ)ミニPC TRIGKEY G4
  • (物理サーバ)Proxmox VE 8.3.0
  • (仮想サーバ)Debian 12.8
  • Python 3.11

手順

物理サーバのBuetoothデバイス確認

user@物理サーバ:~$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 8087:0026 Intel Corp. AX201 Bluetooth
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

lsusbコマンドでUSBデバイス一覧を確認します。
Bus 001 Device 003がBluetoothデバイスです。IDを後続作業で使うので覚えてきます。

Proxmox上で仮想サーバへのUSBデバイス追加

ProxmoxのUI上からUSBデバイスとしてBluetoothハードウェアを追加(パススルー)します。
デバイスを選択時に先程のIDを選択します。

参考:Proxmox公式の解説

仮想サーバ上でBluetoothの動作確認

root@仮想サーバ:# systemctl status bluetooth
* bluetooth.service - Bluetooth service
     Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; preset: enabled)
     Active: active (running) since Sun 2025-02-09 12:00:59 JST; 51min ago
       Docs: man:bluetoothd(8)
   Main PID: 495 (bluetoothd)
     Status: "Running"
      Tasks: 1 (limit: 494)
     Memory: 4.7M
        CPU: 32ms
     CGroup: /system.slice/bluetooth.service
             `-495 /usr/libexec/bluetooth/bluetoothd --noplugin=sap

Feb 09 12:00:59 debian-base systemd[1]: Started bluetooth.service - Bluetooth service.
Feb 09 12:00:59 debian-base bluetoothd[495]: Starting SDP server
Feb 09 12:00:59 debian-base bluetoothd[495]: Excluding (cli) sap
Feb 09 12:00:59 debian-base bluetoothd[495]: profiles/audio/vcp.c:vcp_init() D-Bus experimental not enabled
Feb 09 12:00:59 debian-base bluetoothd[495]: src/plugin.c:plugin_init() Failed to init vcp plugin
Feb 09 12:00:59 debian-base bluetoothd[495]: profiles/audio/mcp.c:mcp_init() D-Bus experimental not enabled
Feb 09 12:00:59 debian-base bluetoothd[495]: src/plugin.c:plugin_init() Failed to init mcp plugin
Feb 09 12:00:59 debian-base bluetoothd[495]: profiles/audio/bap.c:bap_init() D-Bus experimental not enabled
Feb 09 12:00:59 debian-base bluetoothd[495]: src/plugin.c:plugin_init() Failed to init bap plugin
Feb 09 12:00:59 debian-base bluetoothd[495]: Bluetooth management interface 1.22 initialized

仮想サーバ上でBluetoothサービスの動作状況(Status: Running)を確認します。
Bluetoothサービスがそもそも入っていない場合は、bluezパッケージのインストールが必要です。
下部に出ているメッセージの確認も重要です。私の環境では3つのプラグインの初期化に失敗していますが、支障なく使えています。
一方で下記の対処は必要でした。

Bluetoothサービス起動時エラーに対する対処

仮想サーバの起動時にBluetoothのサービスに関してエラーが出たので、下記の対処をしました。
エラーはdmesgコマンドでも確認できます。
なお、対処後のリブートではエラーが解消されないこともありましたが、シャットダウン→起動とすると解消されるエラーもありました。(原因は不明です)

Bluetooth: hci0: Failed to load Intel firmware file intel/ibt-0040-1050.sfi (-2)

/lib/firmware/intelに移動します。(存在しない場合はディレクトリを作成します。)
ファームウェアを追加します。
「ibt-0040-1050」の部分は私の環境の例です。
読み込みエラーが発生しているファームウェアに応じて書き換えてください。

root@仮想サーバ:# wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/intel/ibt-0040-1050.sfi 
root@仮想サーバ:# wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/intel/ibt-0040-1050.ddc

profiles/sap/server.c:sap_server_register() Sap driver initialization failed.

/etc/systemd/system/bluetooth.target.wants/bluetooth.serviceをエディタで開き、ExexStart~~で始まる行の末尾に「--noplugin=sap」を追加します。
※SAPはSIMアクセスプロファイルです。使わないので読めなくてよいです。

ExecStart=/usr/libexec/bluetooth/bluetoothd --noplugin=sap

仮想サーバのBlutoothデバイスの確認

hciconfigコマンドでBluetoothデバイスにアドレス等が割り当てられているか確認します。

root@仮想サーバ:# hciconfig
hci0:   Type: Primary  Bus: USB
        BD Address: XX:XX:XX:XX:XX:XX  ACL MTU: 1021:4  SCO MTU: 96:6
        UP RUNNING 
        RX bytes:1014 acl:0 sco:0 events:70 errors:0
        TX bytes:2813 acl:0 sco:0 commands:70 errors:0

BDアドレスに数字が割り当てられていること、UP RUNNINGとなっていることを確認します。

Bluetoothデバイスのスキャン

bluetoothctlコマンドとscan onコマンドで実際にデバイスをスキャンしてみます。

root@仮想サーバ:# bluetoothctl
Agent registered
[CHG] Controller XX:XX:XX:XX:XX:XX Pairable: yes
[bluetooth]# scan on
Discovery started
[NEW] Device YY:YY:YY:YY:YY:YY ZZ-ZZ-ZZ-ZZ-ZZ-ZZ
・・・
[bluetooth]# scan off

できたこと

仮想サーバ上でBluetoothデバイスの情報を取得できるようになり、コーディングの準備が整いました。
なお、物理サーバ上のある一つのBluetooth(USB)デバイスの情報を複数の仮想サーバで同時に受信することはできません。よって、そのようなことをするにはこのサーバを中継役にして複数サーバへ情報を配信する必要がありそうです。

Discussion