Virtual machine
Virtual machines generally include two concepts, virtual machine software and virtual servers running on virtual machine software.
When a virtual machine is used as software, it is software that realizes the functions of a virtual machine. It is used to simulate a set of independent computer operating systems and implement all the functions of the second computer system in the existing computer system. For example, On Windows systems, run macOS. At the same time, the two systems are completely independent and will not affect each other.
When a virtual machine is used as a virtual server, it refers to a set of independent computer operating systems that we mentioned earlier, such as a Windows system or a macOS system.
Virtual machine principle
The realization of virtual machine mainly includes three parts: virtualization of CPU, virtualization of memory, and virtualization of I/O.
Virtualization of CPU: The hypervisor creates a data structure for each virtual CPU, simulates the values of all registers of the CPU, tracks and modifies these values at the appropriate time, so as to deceive the upper-level program and achieve a CPU that is used by multiple VMs. Purpose.
Memory virtualization: The hypervisor virtualizes memory by creating a shadow page table. Under normal circumstances, a page table can be used to implement translation from virtual memory to physical memory. In the case of virtualization, since the so-called physical memory is still virtual, the shadow page table should be done: virtual memory -> virtual physical memory -> real physical memory.
I/O virtualization: When the hypervisor receives a page fault and finds that the virtual physical memory address actually corresponds to an I/O device, the hypervisor uses software to simulate the operation of the device and returns. For example, when the CPU wants to write to the disk, the hypervisor writes the corresponding things to a file on the host OS, which actually simulates a virtual disk.
Virtual Machine Classification
At present, virtual machines are mainly divided into two categories: system virtual machines and process virtual machines.
System Virtual Machine, which can run different operating systems in the software, such as Linux or Windows, so it can also be called a "fully-virtualized virtual machine". For example, VMware and VirtualBox belong to this type of virtual machine;
Process virtual machines can only execute certain specific programs that can run on other operating systems in the existing computer operating system environment, without running a complete operating system. The well-known JVM (JAVA Virtual Machine) belongs to this.
Advantage of the VM
Quickly switch platforms
Due to the coexistence of Windows, macOS, Linux, and other operating systems, the software you need to use and your operating system may not be completely matched. For example, you may need to use software that only supports Windows systems in macOS, or you may need to use Windows laptops to develop iOS APPs. In these usage scenarios, you can use virtual machines to quickly switch between different system platforms.
Reduce hardware costs
By installing virtual machine software on a physical device, multiple systems can coexist, effectively reducing hardware costs.
Reduce operation and maintenance costs
The virtual machine can realize the centralized management of the terminal, reducing the maintenance difficulty of the operation and maintenance personnel.
Common virtual machine software
Common virtualization software includes Huawei FusionSphere, WMware Workstation, QEMU, Citrix Hypervisor, and so on.