Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install KVM virtual machine in Ubuntu18.04 LTS

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to install the KVM virtual machine in Ubuntu18.04 LTS, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

This article introduces the method and steps of installing KVM virtual machine on Ubuntu 18.04LTS and shares it with you. The details are as follows:

A few days ago, KVM was installed on the latest Ubuntu 18.04 to virtualize a small VM cluster, documenting the main process and some of the problems encountered.

Preparatory work

First, you need to check if CPU supports virtualization, and execute a command to check if there are virtualization-related words in the / proc/cpuinfo file, indicating that CPU supports virtualization technology.

Egrep-c'(svm | vmx)'/ proc/cpuinfo

If the result of the above command execution returns 0, it means that CPU does not support virtualization technology. Of course, the virtualization technology in the motherboard BIOS may not be enabled by default. If it is not enabled, you need to enable it manually.

Install KVM

Execute the following command to install KVM

Sudo apt updatesudo apt install qemu qemu-kvm libvirt-bin bridge-utils virt-manager

Add libvirtd to self-startup

Sudo systemctl start libvirtd.servicesudo systemctl enable libvirtd.service

Network mode

After KVM is installed, you need to make network settings first. KVM supports four network modes:

Bridging mode

NAT mode

User network mode

Direct allocation device mode

Let's talk about the first two.

Bridge (Bridge) mode

In bridge mode, the host and the virtual machine share the same physical network device, and the network card in the virtual machine and the network card in the physical machine are parallel, so the virtual machine can be directly connected to the external network, and the virtual machine and the host have a level IP.

Originally, the host is connected to the external network through the network card eth0. The bridge mode creates a new bridge br0, takes over the eth0 to connect to the external network, and then binds the network card eth0 of the host and the virtual machine to the bridge.

Using bridging mode requires the following:

Edit / etc/network/interfaces and add the following

The auto br0iface br0 inet dhcp # bridge uses DHCP mode to obtain the name of the IPbridge_ports enp3s0 # network card from the DHCP server. Connect the external network card before the bridge is created, which can be viewed through the ifconfig command. The one with the IP address is bridge_stp on # to avoid a dead loop in the data link. Bridge _ fd 0 # sets the forwarding delay to 0

Next, you need to restart the networking service (if you are connected to the host through SSH, this step will cause network interruption. If there is a problem that may lead to failure of the host, it is best to operate directly on the host)

Systemctl restart networking.service

Use the ifconfig command to see if the IP has changed from enp3s0 (the network card before the bridge was created) to br0, and if there is no change, it needs to be restarted. If the host ip has been successfully changed to the bridge, and the host is able to access the Internet normally and the virtual machine cannot get the ip, it may be because ufw does not allow ip forwarding, and edit / etc/default/ufw allows ip forwarding.

DEFAULT_FORWARD_POLICY= "ACCEPT"

Restart the ufw service for the settings to take effect

Systemctl restart ufw.service

NAT (Network Address Translation) mode

NAT mode is the default network mode of KVM. KVM creates a virtual bridge called virbr0, but the host and the virtual machine are not equal to the bridge. The bridge hides the virtual machine behind, and the virtual opportunity is assigned a private network IP, but the virtual machine cannot be accessed from the external network.

Install the Linux virtual machine

Install the Linux virtual machine using the following command

Sudo virt-install-n ubuntu_3-- description "ubuntu_3"-- os-type=linux-- os-variant=ubuntu17.10-- ram=1024-- vcpus=1-- disk path=/var/lib/libvirt/images/ubuntu_3.img,bus=virtio,size=50 # disk location, size 50G-- network bridge:br0 # where the network chooses the bridging mode-- accelerate-- graphics vnc,listen=0.0.0.0,keymap=en-us # VNC listening port. Please select en-us as the key-map. Otherwise, the key layout may be messy-- cdrom / home/zzy/Downloads/ubuntu-18.04-live-server-amd64.iso # installation ISO path

Install the Windows 10 virtual machine

There is a problem without the virtio driver when installing the Windows 10 virtual machine, so the installer cannot find the hard disk. You need to download the virtio driver first.

Https://fedoraproject.org/wiki/Windows_Virtio_Drivers

When you create a virtual machine, add it to the CD-ROM

Sudo virt-install-n win10-description "win10"-- os-type=win-- os-variant=win10-- ram=4096-- vcpus=2-- disk path=/var/lib/libvirt/images/win_10.img,bus=virtio,size=100-- network bridge:br0-- accelerate-- graphics vnc,listen=0.0.0.0,keymap=en-us-- cdrom=/home/zzy/Downloads/ cn_windows_10_consumer_editions_version_1803_updated_march_2018_x64_dvd_12063766.iso--cdrom=/home/zzy/Downloads/virtio-win.iso

Connect to the virtual machine using the VNC client

Execute the following command to view a list of virtual machines

Sudo virus list

View the VNC port of a single machine through the list of virtual machines checked in the previous step

Sudo virsh vncdisplay ubuntu_3 # ubuntu_3 is the virtual machine name

Knowing the VNC port number, you can use the VNC client to connect to the virtual machine to complete the installation.

The above is all the contents of the article "how to install the KVM virtual machine in Ubuntu18.04 LTS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report