如何在Ubuntu上安装KVM和创建虚拟机

如何在Ubuntu上安装KVM和创建虚拟机

If you’re using Linux, you don’t need VirtualBox or VMware to create virtual machines. You can use KVM – the kernel-based virtual machine – to run both Windows and Linux in virtual machines.

如果您使用的是Linux,则不需要VirtualBox或VMware创建虚拟机。 您可以使用KVM(基于内核的虚拟机)在虚拟机中同时运行Windows和Linux。

You can use KVM directly or with other command-line tools, but the graphical Virtual Machine Manager (Virt-Manager) application will feel most familiar to people that have used other virtual machine programs.

您可以直接使用KVM或将其与其他命令行工具一起使用,但是使用过其他虚拟机程序的人会最熟悉图形化的虚拟机管理器(Virt-Manager)应用程序。

安装KVM (Installing KVM)

KVM only works if your CPU has hardware virtualization support – either Intel VT-x or AMD-V. To determine whether your CPU includes these features, run the following command:

仅当您的CPU具有硬件虚拟化支持时才可以使用KVM-Intel VT-x或AMD-V。 要确定您的CPU是否包含这些功能,请运行以下命令:

egrep -c ‘(svm|vmx)’ /proc/cpuinfo

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

A 0 indicates that your CPU doesn’t support hardware virtualization, while a 1 or more indicates that it does. You may still have to enable hardware virtualization support in your computer’s BIOS, even if this command returns a 1 or more.

0表示您的CPU不支持硬件虚拟化,而1或1以上表示它支持硬件虚拟化。 即使此命令返回1或更大,您仍可能必须在计算机的BIOS中启用硬件虚拟化支持。

如何在Ubuntu上安装KVM和创建虚拟机

Use the following command to install KVM and supporting packages. Virt-Manager is a graphical application for managing your virtual machines — you can use the kvm command directly, but libvirt and Virt-Manager simplify the process.

使用以下命令安装KVM和支持软件包。 Virt-Manager是用于管理虚拟机的图形应用程序-您可以直接使用kvm命令,但libvirt和Virt-Manager可以简化该过程。

sudo apt-get install qemu-kvm libvirt-bin bridge-utils virt-manager

须藤apt-get install qemu-kvm libvirt-bin bridge-utils virt-manager

Only the root user and users in the libvirtd group have permission to use KVM virtual machines. Run the following command to add your user account to the libvirtd group:

只有root用户和libvirtd组中的用户才有权使用KVM虚拟机。 运行以下命令以将您的用户帐户添加到libvirtd组:

sudo adduser name libvirtd

sudo adduser 名称 libvirtd

如何在Ubuntu上安装KVM和创建虚拟机

After running this command, log out and log back in. Run this command after logging back in and you should see an empty list of virtual machines. This indicates that everything is working correctly.

运行此命令后,注销并重新登录。重新登录后运行此命令,您应该会看到虚拟机的空列表。 这表明一切正常。

virsh -c qemu:///system list

virsh -c qemu:///系统列表

如何在Ubuntu上安装KVM和创建虚拟机

创建虚拟机 (Creating Virtual Machines)

Once you’ve got KVM installed, the easiest way to use it is with the Virtual Machine Manager application. You’ll find it in your Dash.

一旦安装了KVM,最简单的使用方法就是使用Virtual Machine Manager应用程序。 您会在Dash中找到它。

如何在Ubuntu上安装KVM和创建虚拟机

Click the Create New Virtual Machine button on the toolbar and the Virtual Machine Manager will walk you through selecting an installation method, configuring your virtual machine’s virtual hardware, and installing your guest operating system of choice.

单击工具栏上的“创建新的虚拟机”按钮,虚拟机管理器将引导您选择安装方法,配置虚拟机的虚拟硬件以及安装所选的来宾操作系统。

如何在Ubuntu上安装KVM和创建虚拟机

The process will by familiar if you’ve ever used VirtualBox, VMware, or another virtual machine application. You can install from a disc, ISO image, or even a network location.

如果您曾经使用过VirtualBox,VMware或其他虚拟机应用程序,则该过程将很熟悉。 您可以从光盘,ISO映像甚至网络位置进行安装。

如何在Ubuntu上安装KVM和创建虚拟机

To assign more than 2GB of memory to a virtual machine, you’ll need a 64-bit Linux kernel. Systems running 32-bit kernels can assign a maximum of 2 GB of RAM to a virtual machine.

要将超过2GB的内存分配给虚拟机,您将需要64位Linux内核。 运行32位内核的系统最多可以为虚拟机分配2 GB的RAM。

如何在Ubuntu上安装KVM和创建虚拟机

By default, KVM gives you NAT-like bridged networking – your virtual machine won’t appear on the network as its own device, but it will have network access through the host operating system. If you’re running server software in your virtual machine and want it accessible from other devices on the network, you’ll have to tweak the networking settings.

默认情况下,KVM为您提供类似于NAT的桥接网络-虚拟机不会作为自己的设备出现在网络上,但可以通过主机操作系统进行网络访问。 如果您在虚拟机中运行服务器软件,并希望可以从网络上的其他设备访问该软件,则必须调整网络设置。

如何在Ubuntu上安装KVM和创建虚拟机

After selecting your installation method, Virt-Manager will boot the guest operating system in a window. Install the guest operating system as you would on a physical machine.

选择安装方法后,Virt-Manager将在一个窗口中启动客户机操作系统。 就像在物理计算机上一样安装来宾操作系统。

如何在Ubuntu上安装KVM和创建虚拟机

管理虚拟机 (Managing Virtual Machines)

The Virtual Machine Manager window displays a list of your installed virtual machines. Right-click virtual machines in the window to perform actions, including starting, shutting down, cloning, or migrating them.

“虚拟机管理器”窗口显示已安装的虚拟机的列表。 在窗口中右键单击虚拟机以执行操作,包括启动,关闭,克隆或迁移它们。

如何在Ubuntu上安装KVM和创建虚拟机

You can view information about the virtual machine and configure its virtual hardware by clicking the i-shaped toolbar icon in the virtual machine’s window.

您可以通过单击虚拟机窗口中的i形工具栏图标来查看有关虚拟机的信息并配置其虚拟硬件。

如何在Ubuntu上安装KVM和创建虚拟机

翻译自: https://www.howtogeek.com/117635/how-to-install-kvm-and-create-virtual-machines-on-ubuntu/