vagrant icon indicating copy to clipboard operation
vagrant copied to clipboard

Vagrant fails when there are other inaccessible VirtualBox VMs

Open gl-bars opened this issue 1 month ago • 3 comments

Debug output

https://gist.github.com/gl-bars/047813ff447e68973b682006e8ce9a7b

Expected behavior

Vagrant ignores inaccessible VMs (unless it is the current VM), vagrant up finishes successfully.

I'm pretty sure older Vagrant versions (2.2.x) worked fine in this scenario.

Actual behavior

vagrant up fails since it tries to invoke VBoxManage showvminfo for inaccessible VMs:

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["showvminfo", "1684edd6-b4e0-456f-ba1e-39c3d6874677", "--machinereadable"]

Stderr: VBoxManage: error: The object functionality is limited
VBoxManage: error: Details: code E_ACCESSDENIED (0x80070005), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LockMachine(a->session, LockType_Shared)" at line 3327 of file VBoxManageInfo.cpp

Reproduction information

Vagrant version

2.4.9

Host operating system

Linux, VirtualBox 7.2

Guest operating system

Linux

Steps to reproduce

  1. Create a VirtualBox machine and make it "inaccessible", e.g. by renaming the folder with VM files. (Actual use case is having the VM files on a different filesystem, which is not mounted when Vagrant is run). To verify:
$ VBoxManage list vms
"<inaccessible>" {1684edd6-b4e0-456f-ba1e-39c3d6874677}
"dev1_daedalus_default_1762691679187_68108" {defb849c-c475-4ce2-8d13-ff26249af2ed}
  1. Vagrant init
  2. Vagrant up

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "generic/devuan5"
end

gl-bars avatar Nov 09 '25 14:11 gl-bars

It works if I apply this quick fix:

--- /opt/vagrant/embedded/gems/gems/vagrant-2.4.9/plugins/providers/virtualbox/driver/version_5_0.rb	2025-08-21 10:17:12.000000000 +0300
+++ /opt/vagrant/embedded/gems/gems/vagrant-2.4.9/plugins/providers/virtualbox/driver/version_5_0.rb	2025-11-09 15:00:44.094768133 +0200
@@ -286,6 +286,7 @@
           end
 
           execute("list", "vms", retryable: true).split("\n").each do |line|
+            next if line.start_with?('"<inaccessible>"')
             if line =~ /^".+?"\s+\{(.+?)\}$/
               begin
                 info = execute("showvminfo", $1.to_s, "--machinereadable", retryable: true)
@@ -722,6 +723,7 @@
         def read_used_ports
           used_ports = Hash.new{|hash, key| hash[key] = Set.new}
           execute("list", "vms", retryable: true).split("\n").each do |line|
+            next if line.start_with?('"<inaccessible>"')
             if line =~ /^".+?" \{(.+?)\}$/
               uuid = $1.to_s
 
@@ -748,6 +750,7 @@
         def read_vms
           results = {}
           execute("list", "vms", retryable: true).split("\n").each do |line|
+            next if line.start_with?('"<inaccessible>"')
             if line =~ /^"(.+?)" \{(.+?)\}$/
               results[$1.to_s] = $2.to_s
             end

gl-bars avatar Nov 09 '25 14:11 gl-bars

I think I got hit with the same bug,

kinow@ranma:~/Documents/msc/subjects/High Performance Infrastructures/Lab 6/Vagrant/x86_64$ vagrant up
Bringing machine 'vm0' up with 'virtualbox' provider...
Bringing machine 'vm1' up with 'virtualbox' provider...
==> vm0: Importing base box 'rreye/rocky9'...
==> vm0: Matching MAC address for NAT networking...
==> vm0: Setting the name of the VM: IAP-RDMA-VM0
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["showvminfo", "f9b525d8-8042-4e64-99b7-14fa95ecf072", "--machinereadable"]

Stderr: VBoxManage: error: The object functionality is limited
VBoxManage: error: Details: code E_ACCESSDENIED (0x80070005), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LockMachine(a->session, LockType_Shared)" at line 3328 of file VBoxManageInfo.cpp

I tried reinstalling, using Oracle version, and trying to re-install it a few times, but nothing worked.

I deleted all my other VMs, and tried again, and now everything worked.

Thanks!

kinow avatar Nov 25 '25 08:11 kinow

It works if I apply this quick fix:

@gl-bars: thanks a lot, you've just saved my day!

gusthoff avatar Nov 27 '25 14:11 gusthoff

It works if I apply this quick fix:

--- /opt/vagrant/embedded/gems/gems/vagrant-2.4.9/plugins/providers/virtualbox/driver/version_5_0.rb 2025-08-21 10:17:12.000000000 +0300 +++ /opt/vagrant/embedded/gems/gems/vagrant-2.4.9/plugins/providers/virtualbox/driver/version_5_0.rb 2025-11-09 15:00:44.094768133 +0200 @@ -286,6 +286,7 @@ end

       execute("list", "vms", retryable: true).split("\n").each do |line|
  •        next if line.start_with?('"<inaccessible>"')
           if line =~ /^".+?"\s+\{(.+?)\}$/
             begin
               info = execute("showvminfo", $1.to_s, "--machinereadable", retryable: true)
    

@@ -722,6 +723,7 @@ def read_used_ports used_ports = Hash.new{|hash, key| hash[key] = Set.new} execute("list", "vms", retryable: true).split("\n").each do |line|

  •        next if line.start_with?('"<inaccessible>"')
           if line =~ /^".+?" \{(.+?)\}$/
             uuid = $1.to_s
    

@@ -748,6 +750,7 @@ def read_vms results = {} execute("list", "vms", retryable: true).split("\n").each do |line|

  •        next if line.start_with?('"<inaccessible>"')
           if line =~ /^"(.+?)" \{(.+?)\}$/
             results[$1.to_s] = $2.to_s
           end
    

Wow, thank you very much!

tranphuquy19 avatar Dec 16 '25 15:12 tranphuquy19