You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL2下Molecule启动VirtualBox VM无头模式故障及GUI配置问询

解决WSL2中Molecule+Vagrant+VirtualBox无头模式启动失败问题

环境信息

  • WSL2(Debian 12)运行Molecule及Vagrant 2.4.1
  • Windows 10安装Vagrant 2.4.1和VirtualBox 7.0.1

当前molecule.yml配置

---
dependency:
  name: galaxy
  enabled: false
prerun: false
driver:
  name: vagrant
  provider:
    name: virtualbox
lint: |
  yamllint .
  ansible-lint .
platforms:
  - name: peertube-host
    box: debian/buster64
    memory: 2048
    cpu: 2
    interfaces:
      - auto_config: true
        network_name: private_network
        type: static
        ip: "192.168.56.4"
provisioner:
  name: ansible
  log: True
  env:
    ALLOW_WORLD_READABLE_TMPFILES: True
    ANSIBLE_FORCE_COLOR: true
    ANSIBLE_ROLES_PATH: ../../roles:../../roles-dependencies/
    ANSIBLE_COLLECTIONS_PATH: $PWD/collections-dependencies/
    ANSIBLE_VERBOSITY: 3
  playbooks:
    converge: ../../site.yml
  inventory:
    links:
      group_vars: ../../inventories/molecule/group_vars/
verifier:
  name: testinfra
  options:
    junit-xml: default-report.xml
    o: "junit_family=legacy"

问题现象

执行molecule create时,虚拟机可正常创建,但无头模式启动失败,报错如下:

"There was an error while executing `VBoxManage`, a CLI used by Vagrant",
        "for controlling VirtualBox. The command and stderr is shown below.",
        "",
        "Command: [\"startvm\", \"2fa5ff42-1aec-47ba-a7cb-2b161bff3cf6\", \"--type\", \"headless\"]",
        "",
        "Stderr: VBoxManage.exe: error: The virtual machine 'default_peertube-host_1710842684897_81290' has terminated unexpectedly during startup with exit code -1073741819 (0xc0000005)",
        "VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component MachineWrap, interface IMachine"

Windows应用日志记录的错误详情:

Faulting application name VBoxHeadless.exe, version: 7.0.14.11095, timestamp: 0x65a53a70
Failing module name: VBoxHeadless.exe, version: 7.0.14.11095, timestamp: 0x65a53a70
Exception code: 0xc0000005
Error offset: 0x000000000001b21b
Failing process ID: 0x245c
Start time of the failing application: 0x01da79e4e25c2618
Path of the faulting application: C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe
Path of the faulting module: C:\Program Files\Oracle\VirtualBox\VBoxHeadless.exe
Report ID: 6771c359-7ee3-494a-806a-6be9772f8535
Full name of the failing package:
Application ID relating to the failing package:

直接在WSL中使用Vagrant,给Vagrantfile添加以下配置后,虚拟机可正常以GUI模式启动:

config.vm.provider "virtualbox" do |v|
   v.gui = true
  end

解决方案

1. 在molecule.yml中配置GUI模式

在platforms下的虚拟机节点添加provider_options字段,指定VirtualBox启用GUI:

platforms:
  - name: peertube-host
    box: debian/buster64
    memory: 2048
    cpu: 2
    interfaces:
      - auto_config: true
        network_name: private_network
        type: static
        ip: "192.168.56.4"
    provider_options:
      gui: true

Molecule生成Vagrantfile时会自动注入该配置,虚拟机启动时将弹出VirtualBox GUI窗口。

2. 修复无头模式启动失败的可能方法

  • 升级VirtualBox版本:当前7.0.1版本可能存在WSL2下无头模式的兼容性bug,尝试升级到同系列最新稳定版。
  • 检查权限设置:确保Windows侧的VirtualBox服务以管理员权限运行,WSL2用户拥有调用Windows VirtualBox CLI的足够权限。
  • 禁用3D加速:在provider_options中添加accelerate_3d: false,部分场景下3D加速会导致无头模式崩溃:
    platforms:
      - name: peertube-host
        # 保留原有配置
        provider_options:
          accelerate_3d: false
    
  • 调整显示参数:指定显存或显示控制器类型,避免无头模式下的渲染冲突:
    platforms:
      - name: peertube-host
        # 保留原有配置
        provider_options:
          vram: 16
          display: vmsvga
    

内容的提问来源于stack exchange,提问作者Vorbisset

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 11:45:00