重要提醒
警告⚠:如果在lxc中的键盘鼠标没有反馈,而且也完成了event测试确实有输出的,请重启宿主机,或者更换USB键盘进行测试。在我的设备上,我的无线键鼠在拔出再插入时,需要等相当一段时间,才会被检测到。
警告⚠:总体来说,我建议使用usb键盘完成简单的测试,再进行更复杂的绑定操作。
警告⚠:在lxc中,绑定对应的event、id时,名称不可以太长,任意名称都是可以的
警告⚠:lxc可能由于启动先后顺序问题,无法直接加载声卡和键鼠必要信息,因此需要手动操作
绑定原理
有event、id、usb透传三种方式。本文介绍input/by-id。这也是我推荐使用的方式。
宿主机查组
宿主机查询键鼠情况,发现设备的用户是root,归属于input组
ls -l /dev/input/ root@pve:~# ls -l /dev/input/ total 0 drwxr-xr-x 2 root root 140 Mar 3 06:58 by-id drwxr-xr-x 2 root root 160 Mar 3 06:58 by-path crw-rw---- 1 root input 13, 64 Mar 3 06:58 event0 crw-rw---- 1 root input 13, 65 Mar 3 06:58 event1 crw-rw---- 1 root input 13, 74 Mar 3 06:58 event10 crw-rw---- 1 root input 13, 75 Mar 3 06:58 event11 crw-rw---- 1 root input 13, 76 Mar 3 06:58 event12 crw-rw---- 1 root input 13, 66 Mar 3 06:58 event2 crw-rw---- 1 root input 13, 67 Mar 3 06:58 event3 crw-rw---- 1 root input 13, 68 Mar 3 06:58 event4 crw-rw---- 1 root input 13, 69 Mar 3 06:58 event5 crw-rw---- 1 root input 13, 70 Mar 3 06:58 event6 crw-rw---- 1 root input 13, 71 Mar 3 06:58 event7 crw-rw---- 1 root input 13, 72 Mar 3 06:58 event8 crw-rw---- 1 root input 13, 73 Mar 3 06:58 event9 crw-rw---- 1 root input 13, 63 Mar 3 06:58 mice crw-rw---- 1 root input 13, 32 Mar 3 06:58 mouse0
宿主机查询
root@pve:~# ls /dev/input/by-id/ usb-RAPOO_Rapoo_2.4G_Wireless_Device-event-if01 usb-RAPOO_Rapoo_2.4G_Wireless_Device-event-mouse usb-RAPOO_Rapoo_2.4G_Wireless_Device-if02-event-kbd usb-RAPOO_Rapoo_2.4G_Wireless_Device-mouse
查LXC中组GID
在LXC中查询对应组GID
l@CT101:~$ getent group input input:x:101:
LXC配置
所以LXC配置中添加
dev2: /dev/input/event3,gid=101 dev2: /dev/input/by-id/usb-RAPOO_Rapoo_2.4G_Wireless_Device-event-if01,gid=101 dev3: /dev/input/by-id/usb-RAPOO_Rapoo_2.4G_Wireless_Device-event-mouse,gid=101 dev4: /dev/input/by-id/usb-RAPOO_Rapoo_2.4G_Wireless_Device-if02-event-kbd,gid=101 dev5: /dev/input/by-id/usb-RAPOO_Rapoo_2.4G_Wireless_Device-mouse,gid=101
LXC中验证权限
权限归属与宿主机一致,无问题。
l@CT101:~$ ls /dev/input/by-id/ usb-RAPOO_Rapoo_2.4G_Wireless_Device-event-if01 usb-RAPOO_Rapoo_2.4G_Wireless_Device-event-mouse usb-RAPOO_Rapoo_2.4G_Wireless_Device-if02-event-kbd usb-RAPOO_Rapoo_2.4G_Wireless_Device-mouse
lxc接受事件
需要在lxc中接受事件。我猜测是启动顺序问题,设备事件无法正确被映射,需要手动定义。
这里再强调一遍,像RAPOO Rapoo 2.4G Wireless Device System Control这种名称,太长了没有必要直接抄,抄了就识别不到!!!请改为几个单词或任意几个字符即可
你要调整的是Identifier “Rapoo 2.4G Wireless Device”,不是Option “Device” “/dev/input/by-id/usb-RAPOO_Rapoo_2.4G_Wireless_Device-event-if01”
写错就是为了防止你直接抄。
root@CT101:~# apt install xserver-xorg-input-evdev -y root@CT101:~# nano /etc/X11/xorg.conf.d/10-evdev.conf Section "InputDevice" Identifier "Rapoo 2.4G Wireless Device" Option "Device" "/dev/input/by-id/usb-RAPOO_Rapoo_2.4G_Wireless_Device-event-if01" Option "AutoServerLayout" "true" Driver "evdev" EndSection Section "InputDevice" Identifier "Rapoo 2.4G Wireless Device" Option "Device" "/dev/input/by-id/usb-RAPOO_Rapoo_2.4G_Wireless_Device-event-mouse" Option "AutoServerLayout" "true" Driver "evdev" EndSection Section "InputDevice" Identifier "Rapoo 2.4G Wireless Device" Option "Device" "/dev/input/by-id/usb-RAPOO_Rapoo_2.4G_Wireless_Device-if02-event-kbd" Option "AutoServerLayout" "true" Driver "evdev" EndSection Section "InputDevice" Identifier "Rapoo 2.4G Wireless Device" Option "Device" "/dev/input/by-id/usb-RAPOO_Rapoo_2.4G_Wireless_Device-mouse" Option "AutoServerLayout" "true" Driver "evdev" EndSection
重启xorg
root@CT101:~# systemctl restart lightdm