ubuntu24.04 中kvm如何实现与虚拟机共享复制和粘贴,及VirtIO 串口共享

Kvm、VMware、Virtualbox、Xen、Qemu 等
回复
头像
eremiter
帖子: 115
注册时间: 2017-04-22 19:12
系统: Ubuntu24.04

ubuntu24.04 中kvm如何实现与虚拟机共享复制和粘贴,及VirtIO 串口共享

#1

帖子 eremiter » 2025-03-02 14:22

环境:ubuntu24.04 + kvm + 虚拟机win11

1. QEMU Guest Agent 共享剪切板
sudo apt install qemu-guest-agent

配置虚拟机
打开 virt-manager,选择 Windows 10 虚拟机,点击 “打开”。
点击 “详细信息” -> “虚拟硬件详情” -> “添加硬件”,选择 “Channel”,在 “目标类型” 中选择 org.qemu.guest_agent.0。

代码: 全选

<channel type="qemu-vdagent">
  <source>
    <clipboard copypaste="yes"/>
  </source>
  <target type="virtio" name="org.qemu.guest_agent.0" state="disconnected"/>
  <alias name="channel1"/>
  <address type="virtio-serial" controller="0" bus="0" port="2"/>
</channel>
上面这一台设备类型, 不知要使用哪一个, 换了几个都不成功[unix/]

注意:尝试过 使用 SPICE 代理安装与配置, 下面这两步, 无法启动成功
sudo systemctl start spice-webdavd
sudo systemctl enable spice-webdavd

提示错误:

代码: 全选

 sudo systemctl start spice-webdavd
sudo systemctl enable spice-webdavd
[sudo] ubuntu 的密码: 
The unit files have no installation config (WantedBy=, RequiredBy=, UpheldBy=,
Also=, or Alias= settings in the [Install] section, and DefaultInstance= for
template units). This means they are not meant to be enabled or disabled using systemctl.
 
Possible reasons for having these kinds of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/, .requires/, or .upholds/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.
2. VirtIO 串口共享
sudo apt install virtiofsd

配置虚拟机:在 virt-manager 中,编辑 Windows 10 虚拟机的配置。添加一个新的 “Filesystem” 设备,选择 “VirtioFS” 作为设备类型,将宿主机上要共享的目录(如 /home/ubuntu/Downloads)设置为源路径,为其指定一个挂载标签(如 shared)。

代码: 全选

<filesystem type="mount" accessmode="passthrough">
  <driver type="virtiofs"/>
  <binary path="/usr/libexec/virtiofsd"/>
  <source dir="/home/ubuntu/Downloads"/>
  <target dir="Downloads"/>
  <alias name="fs0"/>
  <address type="pci" domain="0x0000" bus="0x05" slot="0x00" function="0x0"/>
</filesystem>
虚拟机win11设置
https://fedorapeople.org/groups/virt/vi ... le-virtio/
下载最新的 VirtIO 驱动,并在 Windows 10 虚拟机中安装。

下面步骤无法成功.

挂载共享目录:打开 “此电脑”,右键点击空白处,选择 “添加一个网络位置”,按照向导操作,选择 “选择自定义网络位置”,输入 \\wsl$\shared(shared 是在宿主机上设置的挂载标签),然后完成挂载
回复