如何运行 Spice Agent
如何在 Alpine 中运行 Spice Agent
本指南介绍如何在 Alpine Linux 3.12.1-standard 中运行 Spice Agent。
当在 Qemu/Libvirt VM 中运行 Alpine Linux 时,可以使用 Spice Agent 来获得一些额外的功能。
功能特性
工作正常
- 客户端鼠标模式
- X 会话分辨率的自动调整
- 剪贴板共享
无法工作
- Libvirt 中的
State
字段 - 即使在工作时也始终显示“disconnected”
未测试
- 传输文件
- 多个显示器/屏幕
开始之前
Spice Agent 的大多数功能仅在运行图形界面时才有用。我大致遵循了 AwesomeWM 指南,但将 awesome
替换为 i3wm
,因为那是我的偏好(您必须手动安装 i3status,并在 .xinitrc
文件中使用 i3
)。
为了使 Spice Agent 工作,请不要删除 Libvirt 自动添加的 Channel spice
。
构建 Spice Agent
安装依赖项
# apk add alpine-sdk autoconf automake glib-dev libxfixes-dev libxrandr-dev libxinerama-dev spice-protocol alsa-lib-dev dbus-dev libdrm-dev libpciaccess-dev
获取源代码
$ git clone https://gitlab.freedesktop.org/spice/linux/vd_agent.git $ cd vd_agent $ git checkout spice-vdagent-0.20.0
我们需要这个特定版本,因为最新版本需要的 spice-protocol
版本比仓库提供的版本(0.14.1 版本)更新。如果您使用更高版本的 Alpine 遵循本指南,您可能也希望从 git 获取更新的版本。
构建代码(仍然在 vd_agent 目录中)
$ ./autogen.sh $ make
安装程序(手动运行时应该是可选的,但我还没有尝试过不安装的情况)
# make install
运行 Spice Agent
手动运行
首先启动 spice-vdagentd
# modprobe uinput # mkdir /run/spice-vdagentd # spice-vdagentd -d -x -X
您也可以删除小写的 -x
标志以守护进程化 spice-vdagentd
。
然后启动 spice-vdagent
$ spice-vdagent -x -d
请注意,无需以 root 用户身份运行最后一个命令。
使用 init 脚本运行
这假设您在构建结束时运行了 make install
。如果您没有运行,则必须相应地更改此设置。它还需要可以使用 modprobe
加载 uinput
。如果您无法加载,请查看 #使用_virt_版本的_Alpine。
要使用 init 脚本运行,我们将使用 Gentoo init 脚本,尽管我们必须更改路径以使其正常工作(撰写本文时,最新提交是 b3b3e1d9a13c389f17e01c78c6c1a996d08420b5
)
$ wget https://gitweb.gentoo.org/repo/gentoo.git/plain/app-emulation/spice-vdagent/files/spice-vdagent.initd-4 $ sed 's,/var/run,/run,g;s,/usr/sbin,/usr/local/sbin,g' spice-vdagent.initd-4 > spice-vdagentd
然后我们将文件移动到正确的位置,更改所有权,使其可执行并将其添加到默认运行级别
# mv spice-vdagentd /etc/init.d/ # chown root:root /etc/init.d/spice-vdagentd # chmod +x /etc/init.d/spice-vdagentd # rc-update add spice-vdagentd default
上面将启动 spice-vdagentd
,但不会启动 spice-vdagent
。由于 spice-vdagent
应该与您正在使用的 de/wm 一起启动,因此没有一种通用的方法适用于所有设置。如果您想找到一种适合您的方法,Arch wiki 上有一个关于自动启动的不错页面。
使用 virt 版本的 Alpine
这目前在 virt 版本(3.12.1 版本)上不起作用,因为它在内核中没有启用 uinput
。但是,仍然有几种方法可以使其工作。
不使用 uinput 运行
您可以通过按如下方式启动 spice-vdagentd
,使其在没有 uinput 模块的情况下工作,但这将在 spice-vdagent
运行时禁用光标
# mkdir /run/spice-vdagentd # spice-vdagentd -d -x -X -u /dev/null -f
将 uinput 构建为模块
![]() 以下内容包含所有必要信息,但必须重写以使其更清晰。 |
按照 设置您的系统和帐户以构建软件包 中的步骤操作,然后 cd 到 aports/main/linux-lts 目录。检查您拉取的内核版本是否与您正在运行的内核版本相同,使用 uname -r
和 head APKBUILD
。如果它们不匹配,请检出具有相同内核版本的 aports 分支。如果它们相同,请继续执行以下步骤
$ abuild deps $ abuild fetch verify $ abuild unpack $ abuild prepare $ cd src/build-virt-x86_64
现在将 CONFIG_INPUT_UINPUT
从未包含更改为 CONFIG_INPUT_UINPUT=m
在 .config
文件中。然后按如下方式进行
$ make modules_prepare $ make drivers/input/misc/uinput.ko
这会在当前目录中构建 uinput
模块。每次您想要使用它时,都必须像这样加载它(仍然来自 aports/main/linux-lts/src/build-virt-x86_64)
# insmod drivers/input/misc/uinput.ko
在此之后,您可以按照 运行 Spice Agent 中所述使用 spice agent,除了 modprobe uinput
不是必需的。
或者,您可以通过将其复制到 /lib/modules/`uname -r`/extra(您很可能必须先创建它)并运行 depmod
(以 root 身份)来“安装”模块。在此之后,您可以像往常一样使用 modprobe uinput
加载模块。如果您想使用 #使用_init_脚本运行 中描述的 init 脚本,则这是必要的。
重新构建内核以包含 uinput
有关如何构建自定义内核的指针,请参阅 Custom_Kernel。您需要在配置中更改的选项是 CONFIG_INPUT_UINPUT
。