windows - USB 设备在 Vagrant 中不可见

标签 windows vagrant

我试图在 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']

结束

但是当我使用 vagrant up 时,我看不到这个 USB 设备。它在 VirtualBox 设备管理器中标记为未知设备。设备在本地 PC 上是可见的,有时它会在几个 vagrant reload 命令后变得可见。但我正在寻找稳定的解决方案,使我能够在机器启动后立即显示 USB 设备。

最佳答案

这可以通过 VirtualBox 设置 -> USB -> USB 设备过滤器,或通过 Vagrantfile 定义属性来完成。

usermod 定义允许用户通过 VirtualBox Extension Pack 访问 USB 设备,VirtualBox Extension Pack 实现了主机和 guest 计算机之间的 USB 集成。

在使用 vagrant up 启动虚拟机之前,运行以下命令:

# 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

注意:- $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

现在,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

如果需要对属性进行更多的结果或任何修改,则根据 VBoxManageconfig.vm.provider 中添加值

以下是您可以针对 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>]

在上面定义之后,USB 设备可以在 vagrant halt 之后挂载到客户机上,然后是 vagrant up,或者 vagrant provision,然后是通过 vagrant reload

Note: Since USB devices may vary from time to time, it is difficult to predict ahead of time, which device should be defined within the Vagrantfile. Therefore, defining a USB filter via the VirtualBox GUI (Settings > USB > USB Device Filters), is many times preferred over the above Vagrantfile implementation.

引用:using terminal , using UI

关于windows - USB 设备在 Vagrant 中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38956127/

相关文章:

ruby - 安装后无法使用 compass

php - 您的 Composer 依赖项需要 PHP 版本 ">= 8.0.0"。您正在运行 7.4.11

centos - Vagrant 错误 - 未定义方法 `gsub!' 为 nil :NilClass (NoMethodError)

windows - 如何在控制台程序中向 DirectSound SetCooperativeLevel 提供 HWND?

windows - MATLAB:设置非java命令窗口的标题

windows - 创建一个与另一个表单具有相同 z 顺序的新表单

vagrant - Boot2Docker 专用网络设置

c# - 如何获取(逻辑)桌面上的项目总数(C#)

windows - 以编程方式删除 .git .idx .pack 文件

Php:在 ubuntu 上的 laravel homestead(vagrant)上安装 v8js 时出错