Creating a Virtual Machine for Windows 10
[code language=”bash”]
virt-install \
–name=Windows10-VM1 \
–ram=4096 \
–cpu=host \
–vcpus=2 \
–os-type=windows \
–os-variant=win7 \
–disk /srv/dev-disk-by-label-SSD/kvm/Windows10-VM1,size=200,sparse=true,bus=virtio \
–disk /zfs-pool-1/kvm/iso/Windows10.iso,device=cdrom,bus=ide \
–disk /zfs-pool-1/kvm/iso/virtio-win.iso,device=cdrom,bus=ide \
–network bridge=br0 \
–graphics vnc,listen=0.0.0.0
[/code]
Click on Load Driver and browse for the Windows 10 viostor driver. Remember amd64 = 64 bits Windows and x86 = 32 bits.
Set VNC Password
1. Run
[code language=”bash”]virsh edit Windows10-VM1[/code]
2. Add paremeter passwd to element graphics with parameter type=”vnc”
[code language=”xml”]
<graphics type=’vnc’ port=’-1′ autoport=’yes’ listen=’0.0.0.0′ passwd=’yourpassword’>
<listen type=’address’ address=’0.0.0.0’/>
</graphics>
[/code]
3. stop the virtual machine and then start it again
[code language=”bash”]virsh shutdown Windows10-VM1
virsh start Windows10-VM1[/code]
Change network driver
Default is rtl8139 whish is 10/100 Mbit/s change to virtio to get 10Gb/s
1. Run
[code language=”bash”]virsh edit Windows10-VM1[/code]
2. change parameter type to virtio on element model in element interface
[code language=”xml”]
<interface type=’bridge’>
<mac address=’52:54:00:46:16:01’/>
<source bridge=’br0’/>
<model type=’virtio’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x03′ function=’0x0’/>
</interface>[/code]
USB passthrough
Add USB 3.0 Deciv
First change usb driver from USB 2.0 to USB 3.0
1. Run
[code language=”bash”]virsh edit Windows10-VM1[/code]
2. Remove all usb controllers in the devices element
[code language=”xml”]
<controller type=’usb’ index=’0′ model=’ich9-ehci1′>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x04′ function=’0x7’/>
</controller>
<controller type=’usb’ index=’0′ model=’ich9-uhci1′>
<master startport=’0’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x04′ function=’0x0′ multifunction=’on’/>
</controller>
<controller type=’usb’ index=’0′ model=’ich9-uhci2′>
<master startport=’2’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x04′ function=’0x1’/>
</controller>
<controller type=’usb’ index=’0′ model=’ich9-uhci3′>
<master startport=’4’/>
<address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x04′ function=’0x2’/>
</controller>
[/code]
3. Add a new USB 3 controller
[code language=”bash”]
<controller type=’usb’ index=’0′ model=’nec-xhci’>
</controller>
[/code]
Add USB Device (Testing)
1. Find your device, run lsusb. Result will look like below, find the usb device you want to use, you want the vendor and product id.
[code language=”bash”]
root@dalesjo-nas:~# lsusb
Bus 006 Device 002: ID 8087:8000 Intel Corp.
Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 002: ID 8087:8008 Intel Corp.
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 152d:0551 JMicron Technology Corp. / JMicron USA Technology Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
[/code]
2. Create an xml file with the following data, i used the JMicron Technology Corp. / JMicron USA Technology Corp from above
[code language=”xml”]
<hostdev mode=’subsystem’ type=’usb’>
<source>
<vendor id=’0x152d’/>
<product id=’0x0551’/>
</source>
</hostdev>
[/code]
3. Start you virtual machine and then attach your usb device.
[code language=”bash”]
virsh start Windows10-VM1
virsh attach-device Windows10-VM1 test.xml
virsh detach-device Windows10-VM1 test.xml
[/code]
PCI passthrough
Needs PCI passthrough to passthrough entire USB Controller.
Enable IOMMU
First enable IOUMMA in grub.
[code language=”bash”]
root@dalesjo-nas:~# nano /etc/default/grub
…
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"
…
[/code]
References
How to add kernel boot parameters via GRUB on Linux
How to configure PCI-passthrough on virt-manager
Find the correct device
1. run lsusb to find your device. I wanted USB Controller Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M
[code language=”bash”]
root@dalesjo-nas:~# lsusb -t
/: Bus 06.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/3p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/8p, 480M
/: Bus 05.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/2p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/6p, 480M
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 5000M
|__ Port 6: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/15p, 480M
|__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 1: Dev 2, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
[/code]
2. Next run lsusb and check the parameter iSerial for Bus 2 port 1
[code language=”bash”]
root@dalesjo-nas:~# lsusb -v -s 2:1 | grep iSerial
iSerial 1 0000:00:14.0
[/code]
3. create and hub.xml file
[code language=”xml”]
<hostdev mode=’subsystem’ type=’pci’ managed=’yes’>
<source>
<address domain=’0x0000′ bus=’0x00′ slot=’0x14′ function=’0x0’/>
</source>
</hostdev>
[/code]
4. Test attachment
[code language=”bash”]
virsh attach-device Windows10-VM1 hub-pci.xml
virsh detach-device Windows10-VM1 hub-pci.xml
[/code]
5. Add to virtual Machine (static)
Run
[code language=”bash”]virsh edit Windows10-VM1[/code]
Add the entire hostdev element to the element devices
[code language=”xml”]
<hostdev mode=’subsystem’ type=’pci’ managed=’yes’>
<source>
<address domain=’0x0000′ bus=’0x00′ slot=’0x14′ function=’0x0’/>
</source>
</hostdev>[/code]