在调用createhd时,vagrant up失败,错误为VERR_已存在于新VM上

在调用createhd时,vagrant up失败,错误为VERR_已存在于新VM上,vagrant,virtualbox,Vagrant,Virtualbox,我使用下面的Vagrant文件作为许多新虚拟机的基础(我将其复制到一个新目录),但今天,在创建磁盘时,新虚拟机无法正确配置,错误为VERR_已经存在。磁盘文件(本地vagrant“tmp”目录中的source_code_disk.vdi)在启动时肯定不存在,实际上是在vagrant启动时创建的,但“createhd”似乎认为它已经存在,尽管有FileExists检查,这意味着调用“createhd”时它不存在。有趣的是,如果我“随意销毁”新VM,那么磁盘文件也不会被删除。在其他基于相同vagra

我使用下面的Vagrant文件作为许多新虚拟机的基础(我将其复制到一个新目录),但今天,在创建磁盘时,新虚拟机无法正确配置,错误为VERR_已经存在。磁盘文件(本地vagrant“tmp”目录中的source_code_disk.vdi)在启动时肯定不存在,实际上是在vagrant启动时创建的,但“createhd”似乎认为它已经存在,尽管有FileExists检查,这意味着调用“createhd”时它不存在。有趣的是,如果我“随意销毁”新VM,那么磁盘文件也不会被删除。在其他基于相同vagrant文件的安装中,磁盘文件在“vagrant up”过程中创建,并在“vagrant destroy”过程中删除。运行“vagrant up--debug”并没有产生任何额外的信息,为了简洁起见,我没有在这里包含输出

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

file_to_disk = './tmp/source_code_disk.vdi'

Vagrant.configure("2") do |config|

    config.vm.box = "ubuntu/trusty32"
    config.vm.network "private_network", ip: "192.168.33.11"
    config.vm.hostname = "testdisk"
    config.ssh.forward_agent = true
    config.ssh.shell = "/bin/bash -l"

    config.vm.provision :shell do |shell|
        shell.inline = "sudo chsh -s /bin/bash vagrant"
    end

    # create a disk for the source code
    config.vm.provider "virtualbox" do | v |
        unless File.exist?(file_to_disk)
            v.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]
            v.customize ['storageattach', :id, '--storagectl', 'SATAController', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
        end
    end    

end

修复:通过更改相对路径名来删除前导“/”

file_to_disk = 'tmp/source_code_disk.vdi'
我删除了磁盘文件路径中的“/”,一个可靠失败的安装现在完成,没有问题-我怀疑在使用前缀为无害分隔符(如“/”)的相对路径时,存在路径检查失败和一些时间问题

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

file_to_disk = 'tmp/source_code_disk.vdi'

Vagrant.configure("2") do |config|

    config.vm.box = "ubuntu/trusty32"
    config.vm.network "private_network", ip: "192.168.33.11"
    config.vm.hostname = "testdisk"
    config.ssh.forward_agent = true
    config.ssh.shell = "/bin/bash -l"

    config.vm.provision :shell do |shell|
        shell.inline = "sudo chsh -s /bin/bash vagrant"
    end

    # create a disk for the source code
    config.vm.provider "virtualbox" do | v |
        unless File.exist?(file_to_disk)
            v.customize ['createhd', '--filename', file_to_disk, '--size', 50 * 1024]
            v.customize ['storageattach', :id, '--storagectl', 'SATAController', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
        end
    end    

end
注意:原始文件在大多数情况下都可以工作,但有时当我将文件复制到新目录并尝试“vagrant up”时,我无法使VM正常运行。我知道这听起来不太可能,但这是真的,这里的调试显示了一个失败,如果我“随意销毁”,然后仅从文件路径中删除“./”,则该失败有效-没有其他更改

==> default: Running 'pre-boot' VM customizations...
INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "createhd", "--filename", "./tmp/source_code_disk.vdi", "--size", "51200"]
INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stderr: 0%...
DEBUG subprocess: stderr: 10%...20%...30%...40%...50%...60%...70%...80%...90%...
DEBUG subprocess: stderr: 
Progress state: NS_ERROR_INVALID_ARG
DEBUG subprocess: stderr: VBoxManage: error: Failed to create medium
DEBUG subprocess: stderr: VBoxManage: error: Cannot register the hard disk '/home/stg38/vagrant/vstb/./tmp/source_code_disk.vdi' {0c2aa882-a1ef-427e-b7c4-85ef86c0f819} because a hard disk '/home/stg38/vagrant/vstb/./tmp/source_code_disk.vdi' with UUID {17da2b81-dd91-44a3-b60e-6c4921d8e75a} already exists
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBoxWrap, interface IVirtualBox
VBoxManage: error: Context: "RTEXITCODE handleCreateMedium(HandlerArg*)" at line 449 of file VBoxManageDisk.cpp
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 1
INFO retryable: Retryable exception raised: #<Vagrant::Errors::VBoxManageError: There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["createhd", "--filename", "./tmp/source_code_disk.vdi", "--size", "51200"]

Stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...
Progress state: NS_ERROR_INVALID_ARG
VBoxManage: error: Failed to create medium
VBoxManage: error: Cannot register the hard disk '/home/stg38/vagrant/vstb/./tmp/source_code_disk.vdi' {0c2aa882-a1ef-427e-b7c4-85ef86c0f819} because a hard disk '/home/stg38/vagrant/vstb/./tmp/source_code_disk.vdi' with UUID {17da2b81-dd91-44a3-b60e-6c4921d8e75a} already exists
VBoxManage: error: Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBoxWrap, interface IVirtualBox
VBoxManage: error: Context: "RTEXITCODE handleCreateMedium(HandlerArg*)" at line 449 of file VBoxManageDisk.cpp
>
INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "createhd", "--filename", "./tmp/source_code_disk.vdi", "--size", "51200"]
INFO subprocess: Command not in installer, restoring original environment...


Please fix this customization and try again.
A customization command failed:

["createhd", "--filename", "./tmp/source_code_disk.vdi", "--size", 51200]

The following error was experienced:

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

Command: ["createhd", "--filename", "./tmp/source_code_disk.vdi", "--size", "51200"]

Stderr: 0%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage: error: Failed to create medium
VBoxManage: error: Could not create the medium storage unit '/home/stg38/vagrant/vstb/./tmp/source_code_disk.vdi'.
VBoxManage: error: VDI: cannot create image '/home/stg38/vagrant/vstb/./tmp/source_code_disk.vdi' (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium
VBoxManage: error: Context: "RTEXITCODE handleCreateMedium(HandlerArg*)" at line 449 of file VBoxManageDisk.cpp
>

Please fix this customization and try again.
==>默认值:运行“预引导”VM自定义。。。
信息子进程:启动进程:[“/usr/bin/VBoxManage”、“createhd”、“--filename”、“/tmp/source\u code\u disk.vdi”、“--size”、“51200”]
信息子进程:命令不在安装程序中,正在还原原始环境。。。
调试子进程:在IO上选择
调试子进程:标准:0%。。。
调试子流程:标准:10%…20%…30%…40%…50%…60%…70%…80%…90%。。。
调试子进程:stderr:
进度状态:NS\u错误\u无效\u参数
调试子进程:stderr:VBoxManage:错误:无法创建介质
调试子进程:stderr:VBoxManage:error:无法注册硬盘“/home/stg38/vagrant/vstb//tmp/source_code_disk.vdi”{0c2aa882-a1ef-427e-b7c4-85ef86c0f819},因为UUID{17da2b81-dd91-44a3-b60e-6c4921de75a}的硬盘“/home/stg38/vagrant/vstb//tmp/source code_disk.vdi”已经存在
VBoxManage:错误:详细信息:代码NS\u错误\u无效\u参数(0x80070057)、组件VirtualBoxWrap、接口IVirtualBox
VBoxManage:错误:文件VBoxManageDisk.cpp第449行的上下文:“RTEXITCODE handleCreateMedium(HandlerArg*)”
调试子进程:等待进程退出。剩余超时时间:32000
调试子进程:退出状态:1
信息可检索:引发可检索异常:#
信息子进程:启动进程:[“/usr/bin/VBoxManage”、“createhd”、“--filename”、“/tmp/source\u code\u disk.vdi”、“--size”、“51200”]
信息子进程:命令不在安装程序中,正在还原原始环境。。。
请修复此自定义项,然后重试。
自定义命令失败:
[“createhd”、“--filename”、“/tmp/source\u code\u disk.vdi”、“--size”,51200]
出现以下错误:
#
请修复此自定义项,然后重试。

这对我也有用
Vagrant up
如果我在重新启动主机后尝试启动该框,则会产生此错误。