KVM VM 添加 usb 设备

制作xml文件

参考链接:https://libvirt.org/formatdomain.html#usb-pci-scsi-devices

<hostdev mode='subsystem' type='usb'>
        <source>
                <vendor id='0x21c4'/>
                <product id='0x0cd1'/>
        </source>
</hostdev>

添加到虚拟机

virsh attach-device amzn2 add-usb.xml --live

OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--file] <string>  XML file
    --persistent     make live change persistent
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain

从虚拟机中删除

virsh detach-device amzn2 add-usb.xml

其他办法

dewan Work ~/vm% virt-xml --build-xml --hostdev type=usb       
<hostdev mode="subsystem" type="usb" managed="yes"/>

dewan Work ~/vm% virt-xml --build-xml --hostdev 21c4:0cd1,type=usb 
<hostdev mode="subsystem" type="usb" managed="yes">
  <source>
    <vendor id="0x21c4"/>
    <product id="0x0cd1"/>
  </source>
</hostdev>

dewan Work ~/vm% virt-xml amzn2 --update --add-device  --hostdev 21c4:0cd1,type=usb
Device hotplug successful.
Domain 'amzn2' defined successfully.
WARNING  XML did not change after domain define. You may have changed a value that libvirt is setting by default.
dewan Work ~/vm% virt-xml amzn2 --update --remove-device --hostdev 21c4:0cd1,type=usb
Device hotunplug successful.
Domain 'amzn2' defined successfully.
WARNING  XML did not change after domain define. You may have changed a value that libvirt is setting by default.

# To update the running VM configuration, add the --update option (but not all options/devices support updating the running VM configuration).

posted @ 2022-10-13 16:11  武平宁  阅读(251)  评论(0编辑  收藏  举报