我试图在 Vagrant(操作系统:Windows 10)中制作可见的 USB 设备,这就是为什么我将这两行添加到 Vagrant 文件中
vb.customize ['modifyvm', :id, '--usb', 'on']
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
vb.gui = true
# # Configure dongle
vb.customize ['modifyvm', :id, '--usb', 'on']
vb.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'VC', '--vendorid', '0x046E', '--productid', '0x0001']
Run Code Online (Sandbox Code Playgroud)
结尾
但是当我使用时,我vagrant up看不到这个 USB 设备。它在 VirtualBox 设备管理器中标记为未知设备。设备在本地 PC 上可见,有时在几个vagrant reload命令后它变得可见。但我正在寻找稳定的解决方案,使我能够在机器启动后立即使 USB 设备可见。
这可以通过 VirtualBox 设置 -> USB -> USB 设备过滤器来完成,或者通过Vagrantfile.
该usermod定义允许用户通过 VirtualBox 扩展包访问 USB 设备,该扩展包实现了主机和来宾机器之间的 USB 集成。
在使用vagrant up以下命令启动 VM 之前:
# You need the virtualbox-extensions package to enable USB
sudo apt install virtualbox-ext-pack # accept the license to install
# add host user to 'vboxusers' group
sudo usermod -a -G vboxusers $USER
# You will need to logout and back in or reboot to get access to USB
# Make sure you have the stuff below in your Vagrantfile, then:
vagrant up
Run Code Online (Sandbox Code Playgroud)
注意:- $USER 应该解析为主机上的当前用户。
在 Vagrantfile 中定义 USB 集成的属性之前,您应该运行VBoxManage以帮助您获取当前安装在主机上的 USB 信息:
sudo VBoxManage list usbhost
[sudo] password for rohan:
Host USB Devices:
UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
VendorId: 0x0781 (0781)
ProductId: 0x5575 (5575)
Revision: 1.39 (0139)
Port: 0
USB version/speed: 2/2
Manufacturer: SanDisk
Product: Cruzer Glide
SerialNumber: xxxxxxxxxxxxxxxxxxxx
Address: sysfs:/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1//device:/dev/vboxusb/001/011
Current State: Busy
Run Code Online (Sandbox Code Playgroud)
现在,Vagrantfile 可以实现配置属性(如上确定):
# Enable USB Controller on VirtualBox
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--usb", "on"]
vb.customize ["modifyvm", :id, "--usbehci", "on"]
end
# Implement determined configuration attributes
config.vm.provider "virtualbox" do |vb|
vb.customize ["usbfilter", "add", "0",
"--target", :id,
"--name", "Any Cruzer Glide",
"--product", "Cruzer Glide"]
end
Run Code Online (Sandbox Code Playgroud)
如果需要对属性进行更多结果或任何修改,则config.vm.provider根据VBoxManage
以下是您可以定义的属性usbfilter:
usbfilter add <index,0-N>
--target <uuid|vmname>|global
--name <string>
--action ignore|hold (global filters only)
[--active yes|no] (yes)
[--vendorid <XXXX>] (null)
[--productid <XXXX>] (null)
[--revision <IIFF>] (null)
[--manufacturer <string>] (null)
[--product <string>] (null)
[--remote yes|no] (null, VM filters only)
[--serialnumber <string>] (null)
[--maskedinterfaces <XXXXXXXX>]
Run Code Online (Sandbox Code Playgroud)
上面定义后,USB 设备可以安装在来宾计算机上vagrant halt,然后是vagrant up, 或vagrant provision,然后是vagrant reload。
注意:由于 USB 设备可能会不时变化,因此很难提前预测,应该在 Vagrantfile 中定义哪个设备。因此,通过 VirtualBox GUI(设置 > USB > USB 设备过滤器)定义 USB 过滤器,比上述 Vagrantfile 实现更受欢迎。
我找到了解决方案。这是基于使用 devcon 工具的简短 PowerShell 脚本。
# Set location where devcon tool is placed
Set-Location "D:\MSSDK\Tools\x64"
# Disconnect USB from host machine
.\devcon.exe remove *VID_096E*
# Reconect USB to virtual machine
.\devcon.exe rescan
Run Code Online (Sandbox Code Playgroud)
devcon.exe 是 MS SDK 工具包的一部分。即使没有物理断开连接,您也可以移除和连接任何 USB 设备。USB 与主机断开连接后,我会重新扫描,并且 USB 设备在 VirtualBox 中可见后。
| 归档时间: |
|
| 查看次数: |
9719 次 |
| 最近记录: |