跳到主要内容

VM 设置

Setting up a VM on Unraid is a flexible way to run full operating systems - such as Windows, Linux, or other platforms - alongside your containers and native apps. Whether you want to test new software, run legacy applications, host a desktop environment, or utilize hardware passthrough for gaming or creative work, Unraid's VM Manager makes the process approachable for all skill levels.

New 在 Unraid 7.0 中

Unraid 7.x brings significant enhancements to VMs, including:

  • %%VM|虚拟机%% 克隆和快照
  • 用户创建的 %%VM|虚拟机%% 模板
  • 内联 XML 编辑/查看
  • 高级 GPU 共享和直通功能

查看 %%VM|虚拟机%% 管理器功能 部分以了解更多详情。

在准备好系统和设置好偏好后,您可以使用 WebGUI 创建新的 %%虚拟机 (VM)|虚拟机%%。

创建您自己的虚拟机

With your system prepared and preferences set, you can create a new VM using the WebGUI.

Before 开始
  • 虚拟机 页面中点击 添加 VM
  • 上传您的操作系统安装 ISO,以及适用于 Windows %%VM|虚拟机%% 的最新 %%VirtIO|virtio%% 驱动程序 ISO 到 isos 共享。
  • 决定是否使用 GPU 直通VNC 进行图形处理。

要创建一个基本的 %%VM|虚拟机%%:

  1. 虚拟机 页面中点击 添加 VM
  2. 模板 设置为 自定义,或者为常见发行版选择预定义的操作系统模板。
  3. 输入 %%VM|虚拟机%% 的 名称,并可选提供描述。
  4. 如果希望 %%VM|虚拟机%% 随 %%array|array%% 自动启动,请切换 自动启动
  5. 选择操作系统类型。这也会调整VM图标。
  6. 分配给VMCPU核心。您可以分配最多与主机上的物理核心数相等的数量。
  7. 指定VM初始内存(RAM)。请参阅您的来宾操作系统文档以获得建议值。
  8. isos 共享中选择 OS 安装 ISO
  9. 配置 主 vDisk(位置、大小和类型)。
    • vDisk 存储 VM 的操作系统。
    • 使用加号按需添加附加的 vDisk
  10. 选择 显卡
    • 选择 VNC 以进行远程访问或选择物理 GPU 进行直通。
    • 如果使用物理GPU,请分配USB键盘/鼠标。
    • 如果需要,请设置 VNC 密码。
  11. 分配 声卡(可选,但对于通过GPU实现HDMI音频是必须的)。
  12. 按需分配 USB 设备
    • 设备必须在启动 %%VM|虚拟机%% 之前连接(不支持 USB 热插拔)。
    • Unraid USB 闪存设备无法进行分配。
  13. 点击创建VM。除非您取消勾选创建后启动VM,否则VM将自动启动。

用户 VM 模板

Unraid 7.1+引入了用户VM模板,使得保存和重用您自定义的VM配置变得容易。用户模板简化了VM的部署,并确保设置的一致性。

创建用户模板:

  1. 编辑您想要模板化的 %%VM|虚拟机%%。
  2. 选择 创建/修改模版 并输入名称。
  3. 您的模板现在将可在 添加 VM 屏幕上的用户模板区域中使用。

使用用户模板:

  • On the VMs page, click Add VM and select your template from the User Templates section.

导入/导出:

  • 将鼠标悬停在用户模板上,然后单击箭头将其导出到服务器或下载它。
  • 在另一台 Unraid 系统上,使用 从文件导入上传 来添加模板。

Unraid 7.x 新增功能:VM 管理器

Unraid 7.x introduces a range of powerful enhancements to the VM Manager, streamlining the process of running and managing VMs. These features cater to beginners and advanced users, making deploying, customizing, and optimizing your VMs simpler.

:::tip[Highlights]

  • 通过 %%VM|虚拟机%% 克隆、快照和可重用模板节省时间
  • 通过高级直通和存储选项优化性能和兼容性
  • 通过使用情况统计和内联 XML 编辑享受更好的可见性和控制

:::

增强的图形和 GPU 共享
  • VM clones & snapshots: Duplicate VMs or quickly save/restore their state for testing or backup.
  • User VM templates: Save your custom VM configurations and deploy new VMs with just a few clicks.
  • 内联 XML 查看/编辑: 立即查看或复制 WebGUI 生成的 XML;切换到 XML 模式以进行高级编辑。
  • 自动启动禁用: 选择哪些 %%VM|虚拟机%% 随您的 %%array|array%% 自动启动。
  • 计时器/偏移配置选项
工作流增强
  • PCI 多功能/其他: 为高级直通场景分配复杂的 PCI 设备或组。
  • QEMU 命令行直通: 添加自定义 QEMU 参数以进行专家级别的 %%VM|虚拟机%% 调优。
  • 存储覆盖: 指定每个 VM 的 虚拟磁盘 的存储位置。
  • SSD 标志与 unmap: 优化 vDisk 性能使其适用于 SSD,并启用 discard/unmap 支持。
  • SR-IOV 用于 Intel iGPU: 在多个 %%VM|虚拟机%% 之间共享集成 Intel 图形。
  • ZFS 的 VM 名称验证: 防止在 ZFS 存储池 使用不受支持的字符。
高级硬件与存储选项
  • VirGLQXL 虚拟 GPU: 在多个 Linux %%VM|虚拟机%% 间共享 Intel/AMD GPU,或利用 QXL 进行多屏幕/内存选项。
  • CPU 绑定 可选: 允许 Unraid 自动管理 CPU 分配,或根据需要手动设置核心。
增强的图形和 GPU 共享
  • View all graphics cards and VM-assigned IP addresses in the VM tab
  • 支持 QEMU ppc64 target 和 qemu:override
  • Windows %%虚拟机%% 的 hypervclock 支持
  • 仿真 CPU 的“可迁移”开/关
  • 计时器/偏移配置选项
  • 不支持的特定用例的 no keymap/nogpu 选项
  • 改进的 %%VM|虚拟机%% 图标选择与编辑
  • 当设置主 GPU 作为直通时的警告(可能需要vBIOS
  • 通过 QXL 视频驱动程序,将 Unraid %%VM|虚拟机%% 启动到 GUI 模式
  • XML 视图中修复路径和图标问题

VM snapshots

VM snapshots allow you to save the current state of your VM at a specific point in time. You can revert to that state if something goes wrong or use snapshots to test changes safely. This is particularly useful before installing new software, making configuration changes, or performing system updates.

How VM snapshots work

When you create a snapshot, Unraid generates an "overlay file" that captures all changes made to your VM after that point. You can think of it like this:

  • Original VM disk: This represents your VM's current state (similar to a photograph).
  • Snapshot overlay: This is a separate file that records all changes made after the snapshot (like a list of edits).
  • VM continues running: Your VM uses both the original disk and the overlay file together.

This setup allows you to create multiple snapshots, with each one generating its own overlay file. This means you can easily revert to any previous state.

Example scenario:

  1. You create a snapshot called "Clean Windows Install."
  2. You install some software and make changes.
  3. You create another snapshot called "After Software Install."
  4. You can now revert to either the clean install or the state after the software installation.
  5. You can also use Block Commit or Block Pull to make changes permanent.

To create a snapshot of your VM:

  1. Go to the VMs page in the WebGUI.
  2. Click on the VM name to expand its details.
  3. Look for the Snapshots section and click Create Snapshot.
  4. Enter a descriptive name for your snapshot (for example, "Before Windows Update" or "Clean Install State").
  5. Memory dump option: In current Unraid builds, the "Memory dump" checkbox is not preselected by default. Checking it includes the VM's RAM for a full memory-backed snapshot (captures the live running state, but is larger and slower to create/restore). Leaving it unchecked creates a disk-only, crash-consistent snapshot (smaller and faster, but any unsaved in-memory data will be lost). Choose based on whether you need full live state preservation or just disk recovery.
  6. Click Create to save the snapshot.
Best 实践
  • Create snapshots before making significant changes to your VM.
  • Use descriptive names that help you remember what the snapshot contains.
  • Choose Memory dump based on your needs: enable it for full live state preservation, or leave it off for faster disk-only recovery.
  • Keep snapshots for important milestones, but delete old ones to save storage space.

Snapshot storage

Snapshots use storage space on your system. Each snapshot saves only the differences between the current state and the snapshot state; however, these differences can still accumulate over time.

Here are some points to consider:

  • QCOW2 disks support snapshots and work well with this feature.
  • Storage location: Snapshots are stored with your VM files, so make sure you have enough space on your cache pools or array.

Snapshot storage location:

  • Snapshot metadata is stored in /etc/libvirt/qemu/snapshotdb/VM_name/.
  • Actual snapshot data is stored alongside your VM files on cache pools or array.
Advanced snapshot concepts

For more detailed technical information about how VM snapshots work, including block diagrams and advanced scenarios with multiple snapshots, see the QEMU snapshots documentation.

Common use cases
  • Before system updates: Create a snapshot before installing Windows updates or Linux package updates. If something goes wrong, you can quickly revert to a previous version.
  • Testing software: Install new applications or make configuration changes. If you're not satisfied with the results, revert to your clean VM snapshots from before the changes.
  • Development work: Create snapshots at different stages of your project. This lets you experiment freely and return to known good states.
  • Backup strategy: While not a replacement for proper backups, snapshots provide quick recovery for recent changes.

使用虚拟 GPU 和 GPU 共享

Unraid 现在支持通过 VirGLQXL 的高级 GPU 共享适用于 Linux %%VM|虚拟机%%(及支持 Nouveau 驱动的某些 Nvidia GPU)。

  • 使用 VirGL:将 显卡 设置为 虚拟,并将 VM 控制台视频驱动 设置为 VirtIO(3D)
  • 使用 QXL:将 显卡 设置为 虚拟,并将 VM 控制台视频驱动 设置为 QXL (最好)
  • VirGL 不输出到物理显示器,并且不兼容 Windows %%VM|虚拟机%% 或标准 Nvidia 插件。
  • QXL 支持多屏幕和可配置的视频内存。

高级选项

展开此部分查看有关更多高级选项的指南

添加 VM 页面上切换到 高级视图 以访问其他设置。

以下是最重要的高级选项,分为集中部分:

CPU 模式:

  • 主机直通:向 %%虚拟机%% 暴露所有主机 CPU 功能以获得最佳性能。
  • 仿真:使用通用 CPU 模型,减少兼容性问题,但性能有限。

内存气球:

  • 设置 最大内存 值以启用动态内存分配(内存气球)。
  • 具有 PCI 设备分配(例如 GPU 直通)的 %%虚拟机%% 不可用。

机器类型:

BIOS 类型:

  • SeaBIOS:传统 BIOS,适用于旧版操作系统。
  • OVMFUEFI BIOS,适用于 Windows 8+、大多数现代 Linux 发行版,以及 GPU 直通
备注

仅在创建新的VM时才可以设置BIOS类型。

Hyper-V 扩展:

  • 对于 Windows %%虚拟机%%,启用 Hyper-V 扩展以提高兼容性和性能。

VirtIO 驱动 ISO:

  • 如有需要,尤其是在测试或使用更新驱动时,覆盖默认的 VirtIO ISO。

vDisk 类型:

  • RAW:最佳性能,快照功能较差。
  • QCOW2:支持快照但性能稍差。

VirtFS 映射(Linux %%虚拟机%%):

  • 添加多个 VirtFS (9p) 共享以实现主机和来宾之间的文件系统集成。
  • 参阅 QEMU 9p 文档。

网络设置:

  • 修改 网络 MAC 地址 或选择备用 网络桥
  • 单击刷新符号以自动生成新 MAC 地址。
  • 根据需要添加额外的虚拟网络接口。
Troubleshooting 提示
  • 如果您的 %%VM|虚拟机%% 启动失败,请仔细检查您的 ISO 和 %%vDisk|vdisk%% 路径。
  • 对于 GPU 直通,确保您的硬件和 BIOS 设置支持 IOMMU/VT-d/AMD-Vi。
  • 某些 USB 设备可能在直通时工作不稳定 - 测试并咨询 Unraid 论坛 以获得设备特定建议。

绑定 PCI 设备以进行直通

Before you can assign a GPU or any PCI device to a VM, it's important to "bind" the device to the vfio-pci driver. This process hides the device from Unraid and dedicates it solely to your VM.

要绑定PCI设备(GPU、USB控制器、NVMe等)以进行直通:

  1. 定位到 WebGUI 中的 工具→系统设备
  2. 查看所有检测到的 PCI 设备及其 IOMMU 组的列表。
  3. 选中您希望绑定到 vfio-pci 的每个设备的复选框(以将其从 Unraid 隐藏)。
    • 注意,Unraid 已使用的设备(例如磁盘控制器和网卡)无法选择。
    • 如果选择了 GPU,请选择相关的声音设备。
  4. 单击 绑定选择到 VFIO 开机时 以保存更改。
  5. 重新启动服务器以使绑定生效。
注意

GPU透传允许您将物理显卡直接分配给虚拟机 (VM),为游戏、创作工作或机器学习提供近乎原生的性能。

绑定后,绑定设备将在编辑或创建 %%虚拟机|虚拟机%% 时出现在 其他 PCI 设备 下拉菜单中。

故障排除
  • 如果您之前使用过 VFIO-PCI 配置插件,请卸载它 - 这项功能已经集成。
  • 要重置所有绑定,删除 /boot/config/vfio-pci.cfg 并重新启动系统。
  • 重启后,在系统设备页面上使用查看VFIO-PCI日志按钮进行高级故障排除。
  • 请记住,如果您绑定了唯一的 GPU,Unraid 可能无法引导到 GUI。请确保对此有规划。
  • 有关更多信息,请查看Unraid论坛官方指南

GPU透传用于虚拟机

GPU passthrough allows you to assign a physical graphics card directly to a VM, providing near-native performance for gaming, creative work, or machine learning.

Why 使用 GPU 直通功能?
  • **性能:**为高需求应用提供直接硬件访问。
  • **兼容性:**运行需要专用GPU的图形密集型工作负载。
  • **灵活性:**将您的 Unraid 服务器转换为多用途工作站。

先决条件

硬件:

  • 支持Intel VT-d或AMD-Vi的处理器(在BIOS中启用IOMMU)。
  • 与透传兼容的GPU(参见社区测试硬件)。
  • 主板支持正确隔离PCIe设备。

注入ROM:

  • Unraid 6.9以上版本,启用了虚拟化。
  • OVMFUEFI) BIOS用于VM(推荐使用OVMF而不是SeaBIOS)。

To set up GPU passthrough:

  1. 确保您的硬件支持IOMMU并在您的BIOS中启用。
  2. 在BIOS中启用虚拟化特性(Intel VT-x/VT-d或AMD-v/AMD-vi)。
  3. 将 Unraid 更新到最新稳定版本。
  4. 在图形卡部分中,将GPU分配给VMVM创建或编辑屏幕。
  5. 如果使用GPU透传,请为VM分配USB键盘和鼠标。
  6. VM使用OVMF BIOS,以便更好地兼容GPU透传
  7. 启动VM并确认GPU正确透传。
备注

某些GPU可能需要额外配置或ROM注入才能正常透传。

停留在UEFI shell

某些GPU,特别是特定的NVIDIA型号,需要手动为VM提供ROM文件才能正确初始化。这通常在GPU的板载固件未默认正确传递时是必要的,导致诸如黑屏或无法启动等问题。在尝试BIOS和VM配置调整后,手动ROM注入是最后的手段。

注入ROM:

  1. 下载GPU ROM:

    • 访问TechPowerUp VGA BIOS数据库
    • 搜索您的GPU型号并下载正确的ROM文件。
    • 在您的 Unraid isosdomains 共享中存储 rom。
  2. 编辑VM XML:

    • 停止VM并打开其XML配置(在VM上下文菜单中选择编辑XML)。

    • 定位GPU的<hostdev>块并添加<rom>标签:


      <hostdev mode='subsystem' type='pci' managed='yes'>
      <driver name='vfio'/>
      <source>
      <address domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
      </source>
      <rom file='/mnt/user/isos/gpu_roms/your_gpu.rom'/> <!-- Update path -->
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
      </hostdev>
  3. 保存并测试:点击更新并启动VM


常见问题

This section covers advanced topics and solutions for common issues when managing VMs on Unraid. Expand the sections below for step-by-step instructions and troubleshooting tips.

扩展vDisk

点击展开/折叠

If your VM is running low on disk space, you can increase the size of its vDisk directly from the WebGUI.

要扩展vDisk

  1. 进入 WebGUI 中的 VMs 标签。
  2. 确保VM已停止。
  3. 点击VM的名称以展开其详细信息。
  4. 找到您要扩展的vDisk。点击容量字段中的值以使其可编辑。
  5. 输入新的所需大小(例如, 100G表示100GB)并按Enter
  6. 新的容量现已设置。
备注

You cannot shrink a vDisk from the Unraid GUI; only expansion is supported.

在您的客户操作系统中扩展分区

调整vDisk大小后,启动您的VM。您必须在客户操作系统中扩展分区以使用新空间:

  • **Windows:**使用内置磁盘管理工具扩展分区。

  • **Linux (LVM):**使用fdiskpvresizelvextendresize2fs等工具扩展分区和逻辑卷。

    示例:

    sudo fdisk /dev/vda
    sudo pvresize /dev/vda3
    sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
    sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

    根据您的设置调整设备名称。

提示

在进行磁盘更改之前,请始终备份您的VM

停留在UEFI shell

点击展开/折叠

如果您的VM启动到UEFI shell而非您的操作系统,您可以手动启动引导过程:

UEFI shell提示符下输入:

fs0:
cd efi/boot
bootx64.efi

VM现在应该继续引导您的操作系统。

提示

如果此情况频繁发生,请检查您的VM启动顺序并确保在VM设置中正确设定了主启动设备为vDisk或ISO。

启动后黑屏

点击展开/折叠

如果您的VM启动但显示器保持空白:

  1. 检查BIOS设置:

    • 将主图形设置为集成GPU(iGPU),而不是透传GPU。
    • 将主板和GPU BIOS更新至最新版本。
  2. 调整VM设置:

    • SeaBIOS换为OVMFUEFI)在VM设置中。
    • 机器类型 从i440fx更改为Q35。
  3. 手动ROM注入(最后一招):手动注入GPU ROM

错误:“设置容器的IOMMU失败:操作不允许”

点击展开/折叠

此错误通常指示IOMMU组冲突或缺少中断重映射:

  1. 启用PCIe ACS重置:

    • 进入 设置 → 虚拟机管理器
    • PCIe ACS重置设置为下游
    • 重启 Unraid。
  2. 允许不安全的中断(高级):

    • 在您的 Unraid 闪存驱动器上编辑 syslinux.cfg

      append vfio_iommu_type1.allow_unsafe_interrupts=1 initrd=/bzroot
    • 仅在您完全信任您的VM客户时使用此功能。

备注

对于详细的IOMMU组解释,建议查看Alex Williamson的博客