在新VM上调用createhd并出现错误VERR_ALREADY_EXISTS时,流浪汉失败

Ste*_*ove 4 virtualbox vagrant

我将以下Vagrantfile用作许多新VM的基础(我将其复制到新目录中),但是今天创建具有错误VERR_ALREADY_EXISTS的磁盘时,新VM无法正确配置。磁盘文件(本地无业游民的“ tmp”目录中的source_code_disk.vdi)在开始时肯定不存在,实际上是在无业游民的启动过程中创建的,但是尽管FileExists检查这意味着它不存在,但“ createhd”似乎仍已存在当'createhd'调用时存在。有趣的是,如果我“无条件地销毁”新的VM,则磁盘文件也不会被删除。在其他基于相同Vagrantfile的安装中,它们可以正常工作,磁盘文件既可以在“无用启动”期间创建,也可以用“无用销毁”删除。运行“无所事事-调试”

# -*- 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
Run Code Online (Sandbox Code Playgroud)

Ste*_*ove 6

固定:通过更改相对路径名来删除前导“ ./”

file_to_disk = 'tmp/source_code_disk.vdi'
Run Code Online (Sandbox Code Playgroud)

我删除了磁盘文件路径中的“ ./”,现在可靠地完成了安装,没有任何问题-我怀疑当使用以无害分隔符为前缀的相对路径作为前缀时,存在路径检查失败以及一些计时问题。 '

# -*- 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
Run Code Online (Sandbox Code Playgroud)

注意:原始文件在大多数情况下都可以使用,但是有时我不时地将文件复制到新目录并尝试“无用”,则无法获取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.
Run Code Online (Sandbox Code Playgroud)