在 Fedora 中使用 Cockpit 创建虚拟机
Cockpit 虚拟机
![](/data/attachment/album/201912/26/113924y1f69u9zl1kzwnjk.jpg)


本文向你展示如何在 Fedora 31 上使用安装 Cockpit 所需软件来创建和管理虚拟机。Cockpit 是一个[交互式管理界面](https://cockpit-project.org/)，可让你在任何受支持的 Web 浏览器上访问和管理系统。随着 [virt-manager 逐渐被废弃](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/8.0_release_notes/rhel-8_0_0_release#virtualization_4)，鼓励用户使用 Cockpit 来替换它。


Cockpit 是一个正在活跃开发的项目，它有许多扩展其工作的插件。例如，其中一个是 “Machines”，它与 libvirtd 交互并允许用户创建和管理虚拟机。


### 安装软件


先决所需软件是 `libvirt`、`cockpit` 和 `cockpit-machines`。要将它们安装在 Fedora 31 上，请在终端[使用 sudo](https://fedoramagazine.org/howto-use-sudo/) 运行以下命令：



```
$ sudo dnf install libvirt cockpit cockpit-machines
```

Cockpit 也在 “Headless Management” 软件包组中。该软件组对于仅通过网络访问的基于 Fedora 的服务器很有用。在这里，请使用以下命令进行安装：



```
$ sudo dnf groupinstall "Headless Management"
```

### 设置 Cockpit 服务


安装了必要的软件包后，就该启用服务了。`libvirtd` 服务运行虚拟机，而 Cockpit 有一个激活的套接字服务，可让你访问 Web GUI：



```
$ sudo systemctl enable libvirtd --now
$ sudo systemctl enable cockpit.socket --now
```

这应该足以运行虚拟机并通过 Cockpit 对其进行管理。（可选）如果要从网络上的另一台设备访问并管理计算机，那么需要将该服务开放给网络。为此，请在防火墙配置中添加新规则：



```
$ sudo firewall-cmd --zone=public --add-service=cockpit --permanent
$ sudo firewall-cmd --reload
```

要确认服务正在运行并且没有发生任何问题，请检查服务的状态：



```
$ sudo systemctl status libvirtd
$ sudo systemctl status cockpit.socket
```

此时一切都应该正常工作。Cockpit Web GUI 应该可通过 <https://localhost:9090> 或 <https://127.0.0.1:9090> 访问。或者，在连接到同一网络的任何其他设备上的 Web 浏览器中输入本地网络 IP。（如果未设置 SSL 证书，那么可能需要允许来自浏览器的连接。）


### 创建和安装机器


使用系统的用户名和密码登录界面。你还可以选择是否允许在此会话中将密码用于管理任务。


选择 “Virtual Machines”，然后选择 “Create VM” 来创建一台新的虚拟机。控制台为你提供几个选项：


* 使用 Cockpit 的内置库下载操作系统
* 使用系统上已下载的安装媒体
* 指向系统安装树的 URL
* 通过 [PXE](https://en.wikipedia.org/wiki/Preboot_Execution_Environment) 协议通过网络引导媒体


输入所有必要的参数。然后选择 “Create” 启动新虚拟机。


此时，将出现一个图形控制台。大多数现代 Web 浏览器都允许你使用键盘和鼠标与 VM 控制台进行交互。现在，你可以完成安装并使用新的 VM，就像[过去通过 virt-manager](https://fedoramagazine.org/full-virtualization-system-on-fedora-workstation-30/) 一样。


*照片由 [Miguel Teixeira](https://flickr.com/photos/miguelteixeira/) 发布于 [Flickr](https://flickr.com/photos/miguelteixeira/2964851828/)（CC BY-SA 2.0）*




---


via: <https://fedoramagazine.org/create-virtual-machines-with-cockpit-in-fedora/>


作者：[Karlis Kavacis](https://fedoramagazine.org/author/karlisk/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
This article shows you how to install the software you need to use Cockpit to create and manage virtual machines on Fedora 31. Cockpit is [an interactive admin interface](https://cockpit-project.org/) that lets you access and manage systems from any supported web browser. With [virt-manager being deprecated](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/8.0_release_notes/rhel-8_0_0_release#virtualization_4) users are encouraged to use Cockpit instead, which is meant to replace it.

Cockpit is an actively developed project, with many plugins available that extend how it works. For example, one such plugin is “Machines,” which interacts with libvirtd and lets users create and manage virtual machines.

## Installing software

The required software prerequisites are *libvirt*, *cockpit* and *cockpit-machines*. To install them on Fedora 31, run the following command from a terminal [using sudo](https://fedoramagazine.org/howto-use-sudo/):

$ sudo dnf install libvirt cockpit cockpit-machines

Cockpit is also included as part of the “Headless Management” package group. This group is useful for a Fedora based server that you only access through a network. In that case, to install it, use this command:

$ sudo dnf groupinstall "Headless Management"

## Setting up Cockpit services

After installing the necessary packages it’s time to enable the services. The *libvirtd* service runs the virtual machines, while Cockpit has a socket activated service to let you access the Web GUI:

$ sudo systemctl enable libvirtd --now $ sudo systemctl enable cockpit.socket --now

This should be enough to run virtual machines and manage them through Cockpit. Optionally, if you want to access and manage your machine from another device on your network, you need to expose the service to the network. To do this, add a new rule in your firewall configuration:

$ sudo firewall-cmd --zone=public --add-service=cockpit --permanent $ sudo firewall-cmd --reload

To confirm the services are running and no issues occurred, check the status of the services:

$ sudo systemctl status libvirtd $ sudo systemctl status cockpit.socket

At this point everything should be working. The Cockpit web GUI should be available at [https://localhost:9090](https://localhost:9090) or [https://127.0.0.1:9090](https://127.0.0.1:9090). Or, enter the local network IP in a web browser on any other device connected to the same network. (Without SSL certificates setup, you may need to allow a connection from your browser.)

## Creating and installing a machine

Log into the interface using the user name and password for that system. You can also choose whether to allow your password to be used for administrative tasks in this session.

Select *Virtual Machines* and then select *Create VM* to build a new box. The console gives you several options:

- Download an OS using Cockpit’s built in library
- Use install media already downloaded on the system you’re managing
- Point to a URL for an OS installation tree
- Boot media over the network via the
[PXE](https://en.wikipedia.org/wiki/Preboot_Execution_Environment)protocol

Enter all the necessary parameters. Then select *Create* to power up the new virtual machine.

At this point, a graphical console appears. Most modern web browsers let you use your keyboard and mouse to interact with the VM console. Now you can complete your installation and use your new VM, just as you would [via virt-manager in the past](https://fedoramagazine.org/full-virtualization-system-on-fedora-workstation-30/).

*Photo by Miguel Teixeira on Flickr (CC BY-SA 2.0).*

## Lucas

The software is great and is very easy to use.

What if my computer does not support virtualization technology at all ?

because i tried to install and setting up new machine in my fedora 30 and it gave

me an error.

## Karlis Kavacis

It is possible that your computer simply does not permit running Virtual Machines, you can check the BIOS settings to see if virtualization is simply disabled and enable it. If you have an Intel based system the configuration related to Virtualization will be called something like “Intel VT-d” or “Enable Intel Virtualization”. On AMD systems it will be called something like “AMD-V” or just “Enable Virtualization”. In either case the configuration to enable/disable virtualization usually can be found under CPU settings or under Advanced settings in BIOS – the exact procedure to access BIOS settings or how Virtualization settings are named in BIOS differs between different manufacturers, so it’s best to consult the user manual.

Additionally, if you’re sure Virtualization is enabled in BIOS, you can check if the system meets the requirements by running: “virt-host-validate” (comes with libvirt and should already be available).

## RaphGro

You should also take a look into Ravada VDI. We’ve it as a package in Fedora called ravada.

https://ravada.readthedocs.io/en/latest/

## OppaErich

Well, that failed fast. I’ve tried to setup a VM for FreeDOS but it does not start. There’s a red ‘OOPS’ and no VM.

No VM is running or defined on this host

## OppaErich

Hi,

I can’t edit so I add another. Another try discovered a permission denied on the ISO.

[oppa@oppa-labor ~]$ ls -l ~/Downloads/FD12CD.iso

-rw-rw-r–. 1 root root 438777856 28. Nov 16:43 /home/oppa/Downloads/FD12CD.iso

WTH? Why is this owned by root? Do I become root in Chrome by using this Cockpit thing?

This is scary, I’ll stop using Cockpit.

## Karlis Kavacis

Normally, no – Chrome doesn’t run as root when accessing Cockpit, however, tasks executed while authenticated in Cockpit and with the checkbox “Reuse my password for privileged tasks” will be run as elevated.

You can try setting the ownership of the ISO media to “qemu:qemu” (“sudo chown qemu:qemu INSTALLATION.iso”) and see if that resolves the issue. If that wasn’t enough, SE Linux might have restricted Libvirt to access the installation ISO – you can set the context with “sudo chcon system_u:object_r:virt_content_t:s0 INSTALLATION.iso”.

## Stephen Gallagher

SELinux requires that the ISO have the context virt_image_t set on it or it won’t read it. So try

## David

I don’t understand why virt-manager is being deprecated. Cockpit seems to be very limited in functionality compared to virt-manager. In Cockpit, I cannot even select UEFI instead of BIOS for the virtual machine, virtio-scsi controller, enable discard unmap feature etc.

## Karlis Kavacis

Personally, I agree – at this moment virt-manager does offer more configuration available in GUI than Cockpit. At the same time, you still have access to virsh – the commandline interface that allows for more complex configurations than either in Cockpit or virt-manager.

Switching over to Cockpit was a change that was made by Red Hat, I’m sure there was a good reason for it. In the meantime, Cockpit is a constantly evolving project – new features are added all the time. And I’m sure virt-manager won’t stop functioning or disappear from the repositories anytime soon or before the same functionality has been introduced in Cockpit. You can head over to GitHub and follow the progress of development and take part in improving it – https://github.com/cockpit-project/cockpit

## Stephen Gallagher

First, I’ll note that “deprecated” is not the same as “removed”. virt-manager is still available as part of the libvirt upstream.

The main reason I expect it’s being replaced by Cockpit is so that users are not required to have a Linux workstation system around just to manage their VMs. The virt-manager tool requires a full graphical environment in which to run, whereas Cockpit can run in any modern web browser.

## Bryce Hardy

I get an error message saying:

“ERROR authentication failed: access denied by policy”

## Rudolph

Might have to add your user to the libvirt group?

## dtw

I just tried cockpit and I can see how it replaces virt-manager for creating, starting and stopping VMs. What I don’t understand is how I access the VM itself from cockpit? Is the assumption that we only run headless VMs?

## Eddie Jennings

I know I’ve had Cockpit work in the past (and it was a pretty slick interface). I’m currently working on trying to figure why my Fedora 31 server’s resetting TCP connections when I try to connect to Cockpit using Firefox.

## Eddie Jennings

Update:

Looks like what I’m not alone with what I experienced with Fedora 31. Here’s a bug report that describes the exact problem.

https://bugzilla.redhat.com/show_bug.cgi?id=1775489

## Severo Acevedo

How to work it on Fedora SilverBlue?