I decided to ask Bing Copilot about Linux virtualization stack. This is area where I have some knowledge, but I haven’t fully understood. I paste chat log below, but first my impressions.
Copilot didn’t make any complete blunders. It understood what I asked for and provided relevant answers. However, I felt it just copies / rephrases data it found on web, without trying to put them in any novel light.
It seems to be confused about QEMU. It says it’s user-space component for KVM, pushing all heavy-lifting to KVM. Then it says it’s user-space emulation that can work without KVM at all. That sounds contradictory, or just QEMU is all these things and has badly-defined scope
.
Definition of type 1 hypervisor doesn’t make much sense to me - it says that this is hardware thing below the OS, and then lists things that are definitely software and part of OS. KVM, being part of Linux, is most definitely running “inside operating system”. Wikipedia page for type 1 hypervisor is also a mess, and it seems to me that meaning of the term has changed multiple times since it was first coined.
When I asked to relate virsh to other things, it just printed definitions, completely ignoring the relationships I was most interested in.
Overall, I feel gaps in my knowledge are about the same as they were before. If I didn’t know anything about this, then answers could give me very short summary that isn’t completely wrong. At the same time, I don’t feel these answers help in actual deep understanding, but maybe it’s just this topic is very confusing. Copilot also gives me references to websites where I could try to learn more, if I wanted to.
Q: I’m confused by Linux virtualization stack. Can you give me short overview? What are the key components? How do they relate to each other? What is each one used for?
A: Sure, I’d be happy to provide an overview of the Linux virtualization stack. Here are the key components and their roles:
-
Hypervisor (KVM): The Kernel-based Virtual Machine (KVM) is a type of hypervisor that turns Linux into a host for running multiple virtual machines[^10^]. It enables and controls the processor’s hardware virtualization capabilities, allowing virtual machines to run at close to native speed[^10^].
-
QEMU: This is a user-space component that implements virtual servers on the host using KVM functionality⁸. It provides hardware emulation and a low-level interface to the virtual machine[^10^].
-
libvirt: This is a toolkit for managing virtual servers⁸. It provides an interface for operations on virtual machines such as starting, stopping, or migrating them[^10^]. It also confines QEMU processes for security[^10^].
These components work together to create a full-featured and secure virtualization stack[^10^]. The hypervisor (KVM) provides the core virtualization infrastructure, QEMU implements the virtual servers, and libvirt manages these servers⁸[^10^].
Virtualization allows physical compute, memory, network, and storage resources to be divided between multiple virtual entities¹². Each virtual device acts as a standalone entity, providing more secure applications with no visible connectivity between environments¹². This enables quick provisioning and destruction of virtual machines as needed¹².
I hope this helps! Let me know if you have any other questions…
Q: Why do both QEMU and libvirt exist? Since both work in user space, could I just use QEMU and skip libvirt? What would be benefits and drawbacks of that, assuming I can? Could I use libvirt without QEMU?
A: QEMU and libvirt serve different purposes in the Linux virtualization stack, and while they often work together, they can also function independently depending on the use case¹².
QEMU is a type 2 hypervisor that provides full system emulation and hardware virtualization capabilities¹. It can emulate various hardware including CPU and I/O devices². QEMU can interpret instructions sent to the virtual machine’s vCPU to real instructions and send them to the physical CPU². It has its own GUI and CLI and can run independently without any other virtualization software².
Libvirt, on the other hand, is a management framework that abstracts the underlying virtualization technologies and provides a unified management interface across different hypervisors¹⁶. It doesn’t create or manage virtual machines but rather maps the command issued by the user to one or a series of API calls to the underlying hypervisor². It provides CLI tools such as virsh
, virt-manager
, virt-install
².
Using QEMU without libvirt: It’s possible to use QEMU without libvirt⁷. The benefit of this approach is that you have direct control over the QEMU command line, which can be useful for debugging or when you need to use QEMU features that libvirt does not yet support⁷. However, the drawback is that you lose the convenience of libvirt’s management and abstraction capabilities¹². You would need to manually manage the QEMU processes and configuration⁷.
Using libvirt without QEMU: Libvirt is hypervisor-agnostic and can manage different hypervisors, not just QEMU¹². So yes, you could use libvirt without QEMU. However, you would need another hypervisor for libvirt to manage, such as KVM, Xen, or LXC².
In summary, while QEMU and libvirt can function independently, they are often used together because they complement each other. QEMU provides the emulation and virtualization capabilities, while libvirt provides a convenient and consistent way to manage and interact with the virtual machines¹².
Q: What is “type 2 hypervisor”? What other types hypervisors are available? What would be examples of them in Linux?
A: Hypervisors are a crucial part of virtualization technology. They are classified into two types: Type 1 and Type 2³⁴.
Type 1 Hypervisor (Bare-Metal Hypervisor): This type of hypervisor runs directly on the host’s hardware to control the hardware and manage guest operating systems³. It provides excellent performance and stability since it does not run inside any other operating system³. Examples of Type 1 hypervisors include VMware ESXi, Microsoft Hyper-V, and Kernel-based Virtual Machine (KVM) which is built into the Linux kernel¹.
Type 2 Hypervisor (Hosted Hypervisor): This type of hypervisor runs on a conventional operating system just like other computer programs³⁷. It abstracts guest operating systems from the host operating system¹. Since it works on top of an operating system, Type 2 hypervisors are not as fast, efficient, or secure as Type 1 hypervisors⁹. An example of a Type 2 hypervisor includes VMware Player².
In the context of Linux, KVM (Kernel-based Virtual Machine) is a popular Type 1 hypervisor that is built into the Linux kernel¹. It allows the Linux kernel to function as a hypervisor, enabling multiple operating systems to share a single hardware host¹. Another example is Xen, an open-source Type 1 hypervisor¹.
It’s important to note that the choice between Type 1 and Type 2 hypervisors depends on the specific needs and constraints of your project. Type 1 hypervisors are generally used in server environments where performance and isolation are critical, while Type 2 hypervisors are typically used in desktop environments for tasks like testing and development³.
Q: I also heard about thing called “virsh”. What is that? How does it relate to KVM, QEMU and libvirt?
A: virsh
is a command-line interface tool for managing guest virtual machines⁶. It’s built on the libvirt
management API and serves as the primary means of controlling virtualization⁶⁸. virsh
can be used to create, deploy, and manage guest virtual machines⁶. It’s particularly useful for advanced Linux administrators interested in scripting or automating some aspects of managing their virtual machines⁹.
Here’s how virsh
relates to KVM
, QEMU
, and libvirt
:
- KVM: Kernel-based Virtual Machine (KVM) is a type 1 hypervisor that’s part of the Linux kernel¹. It provides the core virtualization infrastructure¹.
- QEMU: QEMU is a type 2 hypervisor that provides hardware emulation¹. It can run independently without any other virtualization software¹.
- libvirt: libvirt is a virtualization API that provides a unified way to interact with various hypervisors, including KVM and QEMU¹². It doesn’t create or manage virtual machines but rather maps the command issued by the user to one or a series of API calls to the underlying hypervisor¹.
- virsh: virsh is a command-line tool built on top of the libvirt API⁶. It provides a way to manage virtual machines created by various hypervisors, including KVM and QEMU¹².
In summary, virsh
is a command-line tool that uses libvirt
to manage virtual machines. libvirt
, in turn, interacts with the underlying hypervisors (KVM
and QEMU
) to create and manage these virtual machines¹². This layered architecture allows for a high degree of flexibility and control in managing virtual machines in a Linux environment…