A Virtual Machine (VM) is a computer running on the Virtual Layer. It is usually called a hypervisor. It does not really exist, but it can work like a real computer. The Virtual Layer of the Virtual Machine determines the Virtual Interface of the Virtual Machine. For operating systems running on the virtual machine, they are the corresponding Nic, memory, and hard disk. In a sense, virtual machines make the guest operating system mistakenly think that it is running on a specific physical device. These physical devices are actually simulated by virtual software, the virtual software is responsible for processing the interaction with the actual hardware. This is called hardware.
A Virtual Machine (VM) is a computer running on the Virtual Layer. It is usually called a hypervisor. It does not really exist, but it can work like a real computer. The Virtual Layer of the Virtual Machine determines the Virtual Interface of the Virtual Machine. For operating systems running on the virtual machine, they are the corresponding Nic, memory, and hard disk. In a sense, virtual machines make the guest operating system mistakenly think that it is running on a specific physical device. These physical devices are actually simulated by virtual software, the virtual software is responsible for processing the interaction with the actual hardware. This is called hardware simulation.
There is a compromise in virtual technology. Some virtual software runs on the operating system layer. This virtualization features poor flexibility and high speed and performance on the local machine. In addition, some virtual software runs directly or almost equal to bare metal, that is, the virtual software is either part of the operating system kernel or runs as an operating system, there is no other software layer between virtual software and physical hardware resources. This method is faster.
KVM
Kernel-based Virtual Machine (KVM) is part of the Linux Kernel. KVM does not provide hardware simulation, but only provides underlying operations. To run KVM, the processor must support hardware virtualization. Both Intel and AMD have introduced processor extensions to support hardware virtualization, including IntelVT-x and AMD-V.
Run the following command to check whether the CPU supports hardware Virtualization:
Egrep-C' (vmx | svm) '/proc/cpuinfo
If the return value is 0, the CPU does not support hardware virtualization. If the return value is 1 or higher, the CPU is supported. In general, hardware virtualization extensions are disabled by default and must be enabled by entering the BIOS settings.
Take X200 as an example to modify the BIOS: boot F12-> BootMenu-> -> Config-> CPU->
Select Intel (R) Virtualization Technology as Enabled
Intel (R) VT-d Feature is selected as Enabled
Run the following command to check whether the processor is 64-bit
Egrep-c 'lm '/proc/cpuinfo
If the return value is 0, the CPU usage is not 64-bit. If the return value is 1 or higher, the return value is 64-bit.
Run the following command to check whether the installed Ubuntu kernel is 64-bit:
Uname-m
X86_64 indicates that the system is 64-bit kernel, i386, i38, i586 or i686, And the Linux kernel is 32 bits.
View the installed Ubuntu version:
Cat/etc/lsb-release
View Linux kernel version
Cat/proc/version
Install kvm-OK to view the kvm status
Sudo apt-get install cpu-checker
Enter sudo kvm-OK on the terminal to check the current CPU status.
If the CPU does not support hardware virtualization, return:
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
If the CPU supports hardware virtualization but is not enabled, the following results are returned:
INFO: Your CPU supports KVM extensions
INFO: KVM (vmx) is disabled by your BIOS
HINT: Enter your BIOS setup and enable Virtualization Technology (VT ),
And then hard power off/power on your system
KVM acceleration can NOT be used
CPU supports hardware virtualization and returns if it is enabled normally
INFO:/dev/kvm does not exist
HINT: sudo modprobe kvm_intel
INFO: Your CPU supports KVM extensions
KVM acceleration can be used
Install kvm
Sudo apt-get install qemu-kvm libvirt-bin restart inst bridge-utils
Qemu-kvm is a required KVM user space component.
Libvirt-bin is a binary C toolkit that interacts with Linux virtual functions. It not only supports KVM, but also supports XEN and VirtualBox.
Virtinst is a series of command line tools for creating VMs
Bridge-utils is a tool set used to configure Linux Ethernet links
In addition, virt-viewer can be installed to provide a GUI and VNC interface for VMs. virt-manager provides a GUI for managing VMs. After installation, you can find it on the Dash homepage.
By default, network services can be used by the operating system installed with KVM, but are invisible to other computers on the network, that is, they cannot be accessed as servers by other systems. By default, the VMs IP address range is 10.0.2.0/24, and the customer's operating system can access the host through 10.0.2.2. If you want to change the network settings so that virtual machines can be accessed by the outside world, you need to establish a network connection to make them visible to other systems on the network. Note that you need to use the default network manager to control the hardware you have created. This method is feasible for wired networks and unavailable for wireless networks. First install libcap2-bin. Then you need to grant the QEMU permission to manage the network by setting cap_net_admin.
Run the following command to set a 64-bit system:
Sudo setcap cap_net_admin = ei/usr/bin/qemu-system-x86_64
For a 32-bit system, run the following command:
Sudo setcap cap_net_admin = ei/usr/bin/qemu-system-i386
Add the following lines in/etc/network/interfaces and use DHCP to create a bridge interface br0:
Auto br0
Iface br0 inet dhcp
Bridge_portseth 0
Bridge_stp off
Bridge_fd 0
Bridge_maxwait 0
Run the following command to restart the network:
Sudo/etc/init. d/networking restart
Finally, you need to create the customer VMs through the bridge network. Use this new br0 interface to manually define your customer operating system, which is the same as what you usually define in the operating system.
You can create a VM using KVM in several ways. One of the methods is through vmbuilder. Run the sudo apt-get install python-vm-builder command to install the SDK. The two parameters required by Vmbuilder are the virtual software name and the operating system name to be used. Vmbuilder is very powerful. You can enter vmbuilder kvm ubuntu -- help in the command line. The example here is based on KVM and Ubuntu12.04 LTS
Sudo vmbuilder kvm ubuntu -- suite precise -- flavor virtual -- arch i386-o -- libvirt qemu: // system -- ip 192.168.0.100 -- hostname lovelace -- bridge br0
-- Suite specifies the Ubuntu release version, -- flavor specifies that we want to use the virtual kernel (this is used to build the JeOS image), -- arch indicates that we want to create a 32-bit machine, -o requires vmbuilder to overwrite the VM of the previous version. -- libvirt reports the local virtual environment and adds the result VM to the list of valid machines.
Vmbuilder has powerful functions and is more suitable for basic users. In addition, we can use virtinst for KVM usage and configuration. Virtinst includes many tools. Here we will briefly introduce virt-install and virt-clone. The former is used to create virtual machines, and the latter is used to copy existing virtual machines. We can use virt-install to implement the function of using vmbuilder just now. The difference is that the parameter options are different. In addition, virt-install allows you to create a desktop image containing the GUI, which can be accessed by VNC.
Sudo virt-install-n hopper-r 512 -- disk path =/var/lib/libvirt/images/hopper. img, size = 20-c/dev/cdrom -- accelerate -- connect = qemu: // system -- vnc -- noautoconsole-v
-N hopper defines the Virtual Machine name;-r 512 specifies the memory allocated to the virtual machine, in MB; -- disk path =... it is the path of a virtual hard disk. It can be a file, a partition, or a logical space. In the/var/lib/libvirt/images directory, a 20 GB file named hopper is created. img;-c/dev/cdrom is the host's CD-ROM device path, or you can use an ISO file; -- accelerate enables kernel acceleration; -- connect defines the hypervisor used; -- customers in vnc VNC virtual console are everywhere; -- noautoconsole prevents automatic links to the Virtual Machine console;-v creates a fully virtualized customer.
To copy a virtual machine, you can use virt-clone
Sudo virt-clone-o hopper-n knuth-f/var/lib/libvirt/images/knuth. img -- connect = qemu: // system
-O hopper defines the name of the source virtual machine;-n knuth defines the name of the target virtual machine;-f defines the path of the file/partition/logical space used by the new virtual machine;-connect defines the hypervisor used.
To open a virtual machine, run the following command:
Virsh-c qemu: // system start hopper
To disable a virtual machine, run the following command:
Virsh-c qemu: // system shutdown hopper
When a virtual machine is installed and running, you can connect it through the configured IP address. You can also use the GUI
Virt-view-c qemu: // system hopper
You can use the GUI to manage your virtual machines.
Virt-manager-c qemu: // system
In addition, common virtual software includes VirtualBox, VMware, and Xen. VirtualBox is easy to use. You can download it from the Ubuntu software library, or download the latest software from the www.virtualbox.org/wiki/downloadswebpage. VMware is a paid enterprise-level virtual platform. Ubuntu currently does not support Xen.