Can libvirt be used for managing virtual devices which are not PCs? - virtual-machine

I work in developing and creating virtual printers, with QEMU as the hypervisor (no KVM-only Qemu). Can libvirt library be used to manage virtual printers? Currently, I am investigating on how to convert the qemu command line parameters into dom.xml and try bringing up the virtual printer using virsh. I see that libvirt adds it's own parameters apart from the one provided (like for example vga), which are more suitable for a PC and not necessary for virtual devices like a printer.
Has livirt been successfully used to virtualize other devices or is it specifically aimed only for a PC environment?

Libvirt will only automatically add an <video> element for VGA, if you have asked for a <graphics> element. So you can just leave out the latter to avoid this extra VGA device being added. What you're trying todo is pretty uncommon, so there may be other edge cases you hit like this.

Related

How to emulate USB-device as "alive" on VM?

Step by step:
My PC has connected printer via USB (I know VID:XXXX and PID:YYYY)
I took image of my PC and put inside virtual machine (VMWare)
Of course image on my VM doesn't has connected USB-printer (because real printer is connected to my real USB-port on my real PC).
One program is running and checking accessibility of printer by check connection with the printer via USB (I don't know how exactly - maybe via WMI, maybe via other way).
Results:
a) on my real PC this program works
b) on image doesn't work
QUESTION: is possible to emulate on VM-side that USB-port (VID:XXXX and PID:YYYY) is alive?
Thanks.
P.S. I don't want to install USB-redirect-via-TCP or similar approach.
You should switch to the QEMU emulator and to Linux to do that. VMWare probably doesn't support this of thing especially in a Windows environment.
If you are already on Linux, QEMU has hardware emulation of the xHCI and you can assign the host USB devices to KVM (read here: https://www.linux-kvm.org/page/USB_Host_Device_Assigned_to_Guest).
On Windows, I don't think this will be possible.

Is it possible to have different dev VM environments and access graphics card?

What I want to do on my laptop:
Develop and Run on windows with Visual Studio (CUDA, TensorRT,...)
Develop and Run on Linux (CUDA, TensorRT,...)
Environment to edit videos, photoshop,...
Play games
Environment for general use (web browser, outlook, word,...)
Environment to test applications
Possibly connecting some external GPU to offload the work (cuda,...) from my laptop's graphics card. Since I'm new to this, I haven't researched enough to understand how it can be done. But, this is in my plans.
What I did and reaserched:
As a start, I created VM environements in my host Windows OS using VirtualBox for #1 and #2, but I cannot run inside VM, since it doesn't provide access to graphics card. Even if it did, I still need somehow to switch to a different environment when I want to play games for example.
I probably need hypervisor type 1 if I want to have environment to play games? But, in this case I'll need a second laptop to access it, right?
Is this even possible to do on one laptop (I have strong laptop with enough RAM and SSD)
Graphics cards (GPU) are PCI devices, so they can be passed to VMs with PCI Passthrough. A device is not accessible to the host during passthrough. Hot plug can be used to reattach a graphics card to a different VM or the host without rebooting.
I don't know if a Windows host supports GPU passthrough (maybe you need Windows Server), but Linux host and Windows guest seems to work.
Setting this up is easier if you have a second GPU that remains attached to the host or another computer to control the host during GPU passthrough, for example via SSH.

make virtual machine appear a real machine to applications

I am using VmWare Workstation 14 and when I install an operating system (any of them) some programs and apps are able to identify that I am using a virtual machine.
I have seen the vm is using virtualized devices that are really named virtual. like for example VmWare Network Card or etc. Is there any way to install fake real like hardware drivers on these virtual machines? Can this simple change make the app see this vm as a real machine?
How to make this virtual machine appear as a real machine to applications?
Is there really any way?
This was asked as a yes-or-no question so my answer is:
Yes... probably. But it's a lot of work.
There's a 2006 presentation by Tom Liston and Ed Skoudis that talks about this: https://handlers.sans.org/tliston/ThwartingVMDetection_Liston_Skoudis.pdf
It focuses on VMware, but some of it would also apply to other types of Virtual Machine Environments (VMEs).
In summary, they identify as many things as they can find that would allow VM detection, which would each have to be addressed, and they also mention some VMware-specific mitigations for them.
VME artifacts in processes, file system, and/or Windows registry. These would include the VMtools service and "over 50 different references in the file system to 'VMware' and vmx" and "over 300 references in the Registry to 'VMware'", all of which would have to be deleted or changed.
VME artifacts in memory. Specific regions of memory tend to be different in guests (VMs) than hosts, namely the Interrupt Descriptor Table (IDT), Global
Descriptor Table (GDT), and Local Descriptor Table (LDT). The method by which the VM is built may allow these to appear the same in guests as they do in hosts.
VME-specific virtual hardware. This would include the drivers you mention like VmWare Network Card. The drivers would have to be removed or replaced with drivers that do not match the names or code signatures of any virtual drivers. Probably easiest to do on an open-source system, simply by modifying the driver source code and build.
VME-specific processor instructions and capabilities. Some VMEs add non-standard machine language instructions, or modify the behaviour of existing instructions. These can be changed or removed by editing the VME source code, at the cost of convenient host-guest interaction.
VME differences in behaviour. A VM might respond differently on the network, or fail at time synchonization. This could be mitigated with additional source code changes (on both host and guest) to make the network traffic look closer to normal, and providing sufficient CPU cores to the VM would help make sure it does not run more slowly than wall clock time.
Again this is from 2006, so if anyone has a more up-to-date reference, I'd love to see their answer.

How vmware copies data from guest to host?

Because of VMware tools I can copy a string from guest OS to host OS and vice a versa. I want to know how this functionality works ? what VMware performs so that clipboard is shared between two different OS.
Yesterday, I learnt about VARIANT struct in Microsoft COM. VARIANT is like a middle ware on which some engine will run and allow data of one type accessible in other format of some other language.[please correct me if this is wrong or I am not talking right]
So just want to ask, is something like this works in virtual machines ? Because this functionality is so so helpful that I want understand this concept.
I have not tried in virtual box yet but if it supports same functionality then how do they work ? I would like to read about it if any links found.
Since your virtual machine still runs on the true hardware of your host machine it although uses its peripheral devices and hardware.
So vmware or virtual machines in general has to "root" this device to your virtual OS.
So what Vmware (especially VMWARE Tools) does is when you have copied something into your clipboard, to synchronize this data with the second clipboard. So it provides interfaces between your host data like clipboard or date an time and sets it in your virtual OS.
Have a look here:
http://smallbusiness.chron.com/sharing-clipboard-vmware-35825.html
http://www.vmware.com/support/ws55/doc/new_guest_tools_ws.html.
This does not exactly answers your question, but should give some ideas on further research.

How do programs create virtual hardware?

I've seen programs like magicdisc create virtual cd drives and mount them on the machine. How do these programs trick the operating system into thinking there is a new hardware device attached to it?
I imagine I would have to write a driver for the virtual hardware, and I am comfortable in C so that doesn't sound terrible, but how do I make the OS think there is a piece of hardware attached to it that isn't?
Thanks!
Usually the operating system has different layers and libraries, at some point there is a library that sits between something above it and the actual hardware, you fake it there, if there is some sort of read sector call, you pretend to read a sector using that sector address, read it from a file, whatever. Each operating system (windows, linux, etc) may do things a different way.
Probably you are familiar with C as application level, which is above OS.
The virtual driver is a piece a software, but need to write in proper locations the settings: Registry at Windows, some config file at some Linux. You need to handle OS level calls and callbacks at Kernel level. Than you will desire the software too to communicate with your device, probably integrated into OS Shell. At least 2 layes will be , if not 3 or more.
For eg windows xp you can make a virtual graphic card(and intercept various things), for Vista not, just with a trick :)
It is very-very OS specific.