From Fedora Project Wiki

< Getting started with virtualization

Revision as of 05:19, 4 February 2013 by Was4444 (talk | contribs) (安装虚拟化软件包)

本文将解决如何在 Fedora 中创建并管理虚拟机。关于如何使用 Fedora 作为一个虚拟机,请参看 使用虚拟机安装 Fedora。关于 Fedora 中其他的虚拟化技术,请参看 专门页面

在 Fedora 上使用虚拟化

Fedora 使用 libvirt 系列工具作为其虚拟化解决方案。默认情况下,Feodra 将使用 Qemu 来运行虚拟用户实例。


Qemu 能够在软件层面模拟虚拟主机,或在硬件支持情况下使用 KVM 提供更加快速而全面的虚拟化。


为虚拟 guests 安装配置 Fedora

本节包括在您的系统上配置 libvirt 。成功完成本节后您将可以创建虚拟 guest 操作系统。


Fedora 上虚拟化基本系统要求是:

  • 至少为每个 guest 准备 600MB 的硬盘。一个最小化的命令行 fedora 系统需要 600MB 硬盘。标准 fedora 桌面则要求至少 3GB 的硬盘空间。
  • 至少为每个 guest 准备 256MB 的 RAM 再加上主机基本系统本身 256MB RAM。建议为每个现代操作系统 guest 分配至少 756MB 内存。 一个好的原则是考虑正常情况下操作系统需要多少内存就分配多少给虚拟 guest

KVM 要求 CPU 有虚拟化扩展功能,近些年生产的很多 CPU 都具有该类扩展功能。这些扩展功能被称为 Intel VT 或 AMD-V 。使用如下命令检查您的 CPU 是否支持虚拟化:

$ egrep '^flags.*(vmx|svm)' /proc/cpuinfo 

如果没有任何输出,则说明您的系统不支持相关扩展功能。您仍然可以使用 QEMU/KVM ,但是虚拟将只能使用软件虚拟化(想当慢)。


当安装 Fedora 时,可以通过勾选安装基本组中的虚拟化组以安装虚拟化软件包。

在已经完成 Fedora 安装的系统中, QEMU、KVM和其他一些虚拟化工具的安装可以通过运行如下命令安装虚拟化组:

su -c "yum install @virtualization"

该命令将安装 qemu-kvmpython-virtinstqemuvirt-managervirt-viewer 以及所有需要的依赖软件包。

su -c "systemctl start libvirtd"

确认所有 kvm 内核模块已正常加载:

$ lsmod | grep kvm
kvm_amd                55563  0 
kvm                   419458  1 kvm_amd

如果该命令没有列出 kvm_intel 或 kvm_amd, 则说明 KVM 没有正常配置。参看 确保系统正常使用 KVM 以获得解决问题的建议。

Networking Support

By default libvirt will create a private network for your guests on the host machine. This private network will use a 192.168.x.x subnet and not be reachable directly from the network the host machine is on, but virtual guests can use the host machine as a gateway and can connect out via it. If you need to provide services on your guests that are reachable via other machines on your host network you can use iptables DNAT rules to forward in specific ports, or you can setup a Bridged env.

See the libvirt networking setup page for more information on how to setup a Bridged network.

Creating a Fedora guest

The installation of Fedora guests using anaconda is supported. The installation can be started on the command line via the virt-install program or in the GUI program virt-manager.

Creating a guest with virt-install

virt-install is a command line based tool for creating virtualized guests. To start the interactive install process, run the virt-install command with the --prompt parameter.

su -c "/usr/bin/virt-install --prompt"

The following questions for the new guest will be presented.

  1. What is the name of your virtual machine? This is the label that will identify the guest OS. This label is used with virsh commands and virt-manager(Virtual Machine Manager).
  2. How much RAM should be allocated (in megabytes)? This is the amount of RAM to be allocated for the guest instance in megabytes (eg, 256). Note that installation with less than 256 megabytes is not recommended.
  3. What would you like to use as the disk (path)? The local path and file name of the file to serve as the disk image for the guest (eg, /var/lib/libvirt/images/name.img). This will be exported as a full disk to your guest. It's best to specify the default /var/lib/libvirt/images/ directory.
  4. How large would you like the disk to be (in gigabytes)? The size of the virtual disk for the guest (only appears if the file specified above does not already exist). 4.0 gigabytes is a reasonable size for a "default" install
  5. What is the install CD-ROM/ISO or URL? This is the path to a Fedora installation tree in the format used by anaconda. NFS, FTP, and HTTP locations are all supported. Examples include:

These options can be passed as command line options, execute virt-install --help for details.

virt-install can use kickstart files, for example virt-install -x ks=kickstart-file-name.ks.

If graphics were enabled, a VNC window will open and present the graphical installer. If graphics were not enabled, a text installer will appear. Proceed with the fedora installation.

Creating a guest with virt-manager

Start the GUI Virtual Machine Manager by selecting it from the "Applications-->System Tools" menu, or by running the following command:

su -c "virt-manager"

If you encounter an error along the lines of "Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash", trying running virt-manager not as root (without the su -c). The GUI will prompt for the root password.

  1. Open a connection to a hypervisor by choosing File-->Add connection...
  2. Choose "qemu" for KVM, or "Xen" for Xen.
  3. Choose "local" or select a method to connect to a remote hypervisor
  4. After a connection is opened, click the new icon next to the hypervisor, or right click on the active hypervisor and select "New" (Note - the new icon is going to be improved to make it easier to see)
  5. A wizard will present the same questions as appear with the virt-install command-line utility (see descriptions above). The wizard assumes that a graphical installation is desired and does not prompt for this option.
  6. On the last page of the wizard there is a "Finish" button. When this is clicked, the guest OS is provisioned. After a few moments a VNC window should appear. Proceed with the installation as normal.

Remote management

The following remote management options are available:

  • (easiest) If using non-root users via SSH, then setup instructions are at:
  • If using root for access via SSH, then create SSH keys for root, and use ssh-agent and ssh-add before launching virt-manager.
  • To use TLS, set up a local certificate authority and issue x509 certs to all servers and clients. For information on configuring this option, refer to

Guest system administration

When the installation of the guest operating system is complete, it can be managed using the GUI virt-manager program or on the command line using virsh.

Managing guests with virt-manager

Start the Virtual Machine Manager. Virtual Machine Manager is in the "Applications-->System Tools" menu, or execute:

su -c "virt-manager"

{1} If you are not root, you will be prompted to enter the root password. ChooseRun unprivileged to operate in a read-only non-root mode.

  • Choose the host you wish to manage and click "Connect" in the "Open Connection" dialog window.
  • The list of virtual machines is displayed in the main window. Guests that are running will display a ">" icon. Guests that are not running will be greyed out.
  • To manage a particular guest, double click on it, or right click and select "Open".
  • A new window for the guest will open that will allow you to use its console, see information about its virtual hardware and start/stop/pause it.

For further information about virt-manager consult the project website

Bugs in the virt-manager tool should be reported in BugZilla against the 'virt-manager' component

Managing guests with virsh

The virsh command line utility that allows you to manage virtual machines. Guests can be managed on the command line with the virsh utility. The virsh utility is built around the libvirt management APIl:

  • virsh has a stable set of commands whose syntax and semantics are preserved across updates to the underlying virtualization platform.
  • virsh can be used as an unprivileged user for read-only operations (e.g. listing domains, listing domain statistics).
  • virsh can manage domains running under Xen, Qemu/KVM, esx or other backends with no perceptible difference to the user
A valid URI may be passed to virsh with "-c' to connect to a remote libvirtd instance. For details, see

To start a virtual machine:

su -c "virsh create <name of virtual machine>"

To list the virtual machines currently running:

su -c "virsh list"

To list all virtual machines, running or not:

su -c "virsh list --all"

To gracefully power off a guest:

su -c "virsh shutdown <virtual machine (name | id | uuid)>"

To non gracefully power off a guest:

su -c "virsh destroy <virtual machine (name | id | uuid)>"

To save a snapshot of the machine to a file:

su -c "virsh save <virtual machine (name | id | uuid)> <filename>"

To restore a previously saved snapshot:

su -c "virsh restore <filename>"

To export the configuration file of a virtual machine:

su -c "virsh dumpxml <virtual machine (name | id | uuid)"

For a complete list of commands available for use with virsh:

su -c "virsh help"

Or consult the manual page: man 1 virsh

Bugs in the virsh tool should be reported in BugZilla against the 'libvirt' component.

Other virtualization options

QEMU/KVM without Libvirt

QEMU/KVM can be invoked directly without libvirt, however you won't be able to use tools such as virt-manager, virt-install, or virsh. Plain QEMU (without KVM) can also virtualize other processor architectures like ARM or PowerPC. See How to use qemu


Fedora can run as a Xen Guest OS, but using Fedora as a Xen Host is currently not supported. There is an experimental repo available at


OpenStack consists of a number services for running IaaS clouds. They are the Object Store (Swift), Compute (Nova) and Image (Glance) services. It is a Fedora 16 feature.


OpenNebula is an Open Source Toolkit for Data Center Virtualization.


The oVirt project is an open virtualization project providing a feature-rich, end to end, server virtualization management system with advanced capabilities for hosts and guests, including high availability, live migration, storage management, system scheduler, and more.

Troubleshooting, bug reporting, and known issues

For a list of known unresolved issues, as well as troubleshooting tips, please see How to debug virtualization problems