Basic concepts of virtual machines

foreword

A virtual machine (Virtual Machine) refers to a complete computer system that is simulated by software and has complete hardware system functions and runs in a completely isolated environment. Everything that can be done on a physical computer can be done on a virtual machine. When creating a virtual machine on a computer, part of the hard disk and memory capacity of the physical machine needs to be used as the hard disk and memory capacity of the virtual machine. Each virtual machine has an independent CMOS, hard disk and operating system , and the virtual machine can be operated like a physical machine. It uses special virtualization technology to provide users with an abstract, unified and simulated computing environment by hiding the actual physical characteristics of a specific computing platform.

insert image description here

virtual technology

Virtual machine technology is a kind of virtualization technology. The so-called virtualization technology is to transform things from one form to another. The most commonly used virtualization technology is the virtualization of memory in the operating system. The memory space may be much larger than the memory size of the physical machine. Using memory virtualization technology, users can virtualize part of the hard disk into memory, which is transparent to users. As another example, virtual private network technology (VPN) can be used to virtualize a safe and stable "tunnel" in the public network, so that users feel like they are using a private network.

virtualization system

The virtual system generates a new virtual image of the existing operating system, which has exactly the same functions as the real windows system. After entering the virtual system, all operations are carried out in this new independent virtual system, which can independently install and run software, save Data, with its own independent desktop, will not have any impact on the real system, and has a type of operating system that can flexibly switch between the existing system and the virtual image.

The differences between virtual systems and traditional virtual machines (Parallels Desktop, Vmware, VirtualBox, Virtual pc) are :

1 ) The virtual system will not reduce the performance of the computer. Starting the virtual system does not need to take as much time as starting the windows system, and it is more convenient and quick to run the program.
2 ) The virtual system can only simulate the same environment as the existing operating system, while the virtual machine can simulate other types of operating systems; and the virtual machine needs to simulate the underlying hardware instructions, so the running speed of the application program is slower than the virtual system much.

virtualization method

First Class Hypervisor

Technically, a Type 1 hypervisor is like an operating system because it is the only program running at the highest privilege level. It runs on bare metal and has multiprogramming capabilities. The hypervisor presents several virtual machines to the upper layers, which are exact replicas of the bare metal hardware. Since each virtual machine is identical to bare metal, any different operating system can run on different virtual machines.

The virtual machine runs as a process in user mode, and sensitive instructions are not allowed to be executed. However, the operating system on the virtual machine thinks that it is running in the kernel state (in fact, it is not), which is called the virtual kernel state. A user process in a virtual machine thinks it is running in userland (and it is). When the virtual machine operating system executes an instruction that is allowed to be executed only when the CPU is in the kernel state, it will fall into the virtual machine management program. On CPUs that support virtualization, the hypervisor checks whether the instruction was executed by the operating system in the virtual machine or by a user program. If it is an operating system, the virtual machine management program will arrange the correct execution of the function of this instruction; if it is the latter, the virtual machine management program will simulate the behavior of real hardware when facing user mode to execute sensitive instructions.

On CPUs that did not support virtualization in the past, the real hardware would not directly execute sensitive instructions in the virtual machine, and these sensitive instructions would be converted into calls of the virtual machine hypervisor, and the virtual machine hypervisor would simulate the functions of these instructions.

Type II Hypervisor

It is a program that relies on operating systems such as Windows and Linux to allocate and schedule resources, much like an ordinary process. The second class of hypervisors still pretends to be a full computer with a CPU and all sorts of hardware. VMware Workstation was the first type 2 hypervisor on the X86 platform.

Operating systems that run on both types of hypervisors are called guest operating systems. For the second type of hypervisor, the operating system running on the underlying hardware is called the host operating system.

When booted for the first time, a second type of hypervisor behaves like a freshly powered-on computer, expecting to find a drive that can be a virtual device. Then install the operating system onto the virtual disk (really just a file in the host operating system). Once the guest operating system is installed, it is up and running.

Resource allocation for virtual machines

Virtual machine resources involve the allocation of CPU, memory, network, and disk. The relationship between these resources should be considered when planning a virtual machine, otherwise, unreasonable allocation of resources will lead to poor performance of applications within the virtual machine.

1)CPU

Each vCPU (the CPU of the virtual machine management system) of a virtual machine only runs on one physical core, so the higher the CPU frequency, the higher the running speed of the virtual machine, and the more vCPUs, it helps to improve the performance of the application. If the virtual machine takes up a lot of CPU time, you can consider assigning a second vCPU to the virtual machine. However, assigning more than two vCPUs to the virtual machine does not necessarily make the application run faster, because only multi-threaded applications can effectively Use multiple vCPUs.

2)RAM

RAM (main memory, which is the internal memory that exchanges data directly with the CPU) is usually limited, so you need to be careful when allocating RAM to a virtual machine. After the physical memory is completely used up, it is necessary to determine which virtual machines can retain physical memory and which virtual machines should release physical memory. This is called "memory reclamation". When the physical memory occupied by the virtual machine is reclaimed, there is a risk that the performance of the virtual machine will be affected. The more memory a virtual machine is reclaimed, the greater the corresponding risk.

3) Network bandwidth

Network bandwidth includes the bandwidth between the virtual machine and the virtual switch and the bandwidth between the virtual switch and the external network . For connections to external physical networks, it is important to ensure that the host has the fastest physical NIC. Because of the virtual machine that does a lot of network transmission, the transmission of virtual machines and data packets will consume CPU time. Therefore, a virtual machine running on a CPU-constrained server may face low network throughput due to the CPU's inability to respond to requests quickly.

4) Disk performance

The virtual machine waits for disk IO and the virtual machine CPU is idle, and the performance impact of the two is very different. VMs waiting for IO can't do other work, so high I/O wait time means performance will definitely suffer. A careful storage design to avoid this situation is critical.

The main use of virtual machines

  1. Demonstration environment, various demonstration environments can be installed to facilitate various examples
  2. Ensure the fast operation of the host, reduce unnecessary garbage installation programs, programs that are used occasionally, or programs for testing run on virtual machines
  3. Avoid reinstalling every time, commonly used tools such as banks are not used frequently, and require better confidentiality, and run in a separate environment
  4. Want to test unfamiliar applications, install and completely delete them in the virtual machine
  5. Experience different versions of operating systems, such as Linux, Mac, etc.

Terminal virtualization is sought after because of the substantial reduction in maintenance costs it brings—such as reducing the footprint, reducing the cost of purchasing hardware and software equipment, saving energy and lower maintenance costs. It has more cost-effective advantages than actual terminal devices, and virtualization technology can greatly improve system security.

Guess you like

Origin blog.csdn.net/m0_67021058/article/details/130014092