Появилась задача пробросить USB флешку в гостевую FreeBSD. На сервере используется виртуализация KVM.
USB and PCI devices attached to the host can be passed through to the guest using the hostdev element. since after 0.4.4 for USB and 0.6.0 for PCI (KVM only)
Находим, на какой шине находится устройство USB:
# lsusb Bus 007 Device 002: ID 058f:6387 Alcor Micro Corp. Transcend JetFlash Flash Drive Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Создаем конфиг для устройства, следующего плана (с учетом данных, полученных ранее):
# cat usb.device.xml <hostdev mode='subsystem' type='usb' managed='yes'> <source> <address bus='007' device='002'/> </source> </hostdev>
Подключаем к VPS:
# virsh attach-device <domain> <file>
В нашем случае примерно так:
# virsh attach-device vm300 usb.device.xml
Где vm300 — это имя VM (VPS) или домен, как принято называть. А usb.device.xml — это конфиг в формате XML с данными USB устройства.
Таким образом устройство сразу же должно стать доступным внутри гостевой OS. Чтобы закрепить данные, т.е. обновить XML конфиг самой виртуальной машины, делаем:
# virsh dumpxml <domain> > /full/path/to/<domain>.xml # virsh define <file>
Что для нашего пример выглядит так:
# virsh dumpxml vm300 > vm300.xml # virsh define vm300.xml
Полный конфиг может выглядеть так:
<domain type='kvm' id='23'> <name>vm300</name> <uuid>11b6aa11-e215-e4f0-20a3-c76a0c0958b7</uuid> <memory>524288</memory> <currentMemory>524288</currentMemory> <vcpu>1</vcpu> <os> <type arch='i386' machine='pc'>hvm</type> <boot dev='hd'/> </os> <features> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/kvm-freebsd</emulator> <disk type='block' device='disk'> <source dev='/dev/pool1/vm300'/> <target dev='hda' bus='ide'/> </disk> <disk type='file' device='cdrom'> <source file='/home/isos/freebsd/7.4/FreeBSD-7.4-RELEASE-i386-disc1.iso'/> <target dev='hdc' bus='ide'/> <readonly/> </disk> <interface type='bridge'> <mac address='54:52:00:79:b5:eb'/> <source bridge='kvmbr0'/> <target dev='vnet2'/> </interface> <interface type='bridge'> <mac address='54:52:00:47:5c:72'/> <source bridge='kvmbr1'/> <target dev='vnet3'/> </interface> <serial type='pty'> <source path='/dev/pts/6'/> <target port='0'/> </serial> <console type='pty' tty='/dev/pts/6'> <source path='/dev/pts/6'/> <target port='0'/> </console> <input type='mouse' bus='ps2'/> <hostdev mode='subsystem' type='usb'> <source> <address bus='7' device='2'/> </source> </hostdev> </devices> </domain>
Полезные ссылки:
|
Комментариев нет:
Отправить комментарий