USB passthrough to a KVM guest instance:
Main server running: CentOS 7.7 x64 latest version. KVM guest machine running RHEL-7.4 (Maipo) but it can be any linux flavor.
USB flash drive attached to the main server USB port.
I tried all the guides that I could find on internet and even contacted RedHat regarding this. I was not able to expose the USB flash drive to the KVM guest instance.
In the end, in order to do that, the steps bellow are to be performed:
1. Connect via SSH to the compute node where the USB stick is attached:
1 | ssh root@main-server-ip |
2. Issue a lsscsi command (the output will be something like the one bellow):
1 2 3 4 5 6 7 8 9 10 11 12 | [root@9ef082b846664b2cb2b36246eb2c29e6 ~]# lsscsi [6:0:0:0] disk ATA SSDSC2KB240G8L LX35 /dev/sda [7:0:0:0] disk ATA SSDSC2KB240G8L LX35 /dev/sdb [14:0:0:0] disk SCST_BIO 9eee7d60-4761-41 340 /dev/sde [15:0:0:0] disk SCST_BIO 9eee7d60-4761-41 340 /dev/sdd [16:0:0:0] disk SCST_BIO 9eee7d60-4761-41 340 /dev/sdg [17:0:0:0] disk SCST_BIO 9eee7d60-4761-41 340 /dev/sdf [18:0:0:0] disk SCST_BIO 4b97b991-caf7-4a 340 /dev/sdh [19:0:0:0] disk SCST_BIO 4b97b991-caf7-4a 340 /dev/sdi [20:0:0:0] disk SCST_BIO 4b97b991-caf7-4a 340 /dev/sdk [21:0:0:0] disk SCST_BIO 4b97b991-caf7-4a 340 /dev/sdj [24:0:0:0] disk SMI USB DISK 1100 /dev/sdc |
In this case, the USB drive is: [24:0:0:0] disk SMI USB DISK 1100 /dev/sdc
3. Create a xml file to define some USB parameters that will be used to attach the USB device to the running vm (with the following content):
1 2 3 4 5 6 7 8 | <hostdev mode='subsystem' type='scsi' managed='no'> <source> <adapter name='scsi_host24'/> <address bus='0' target='0' unit='0'/> </source> <alias name='hostdev0'/> <address type='drive' controller='0' bus='0' target='1' unit='0'/> </hostdev> |
4. Check the ID of the running kvm guest:
1 2 3 4 | [root@9ef082b846664b2cb2b36246eb2c29e6 ~]# virsh list You will get a list with all the running instances on that node. In our test case the output is something like this: rhel7-usb e4a91527-a663-486d-bd25-ca69173e8176 running 10.10.10.100/b4:d1:35:00:11:5e 1 |
5. Attach the USB device to the kvm guest instance
1 | virsh attach-device e4a91527-a663-486d-bd25-ca69173e8176 --file scsi.xml |
At the end you should see a message like: Device attached successfully
6. Now if you go to that kvm guest instance you should be able to see the USB drive and use it.