向Vagrant添加Box

3

我为Hyper-V提供程序创建了一个新的虚拟机。当我尝试添加这个虚拟机时,会出现以下错误:

PS C:\> vagrant box add sbx-misc-app01 .\img-misc-w2k16.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'sbx-misc-app01' (v0) for provider:
    box: Unpacking necessary files from: file://C:/img-misc-w2k16.box
    box:
C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:156:in `block (3 levels) in add': undefined method `to_sym' for nil:NilClass (NoMethodError)
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:461:in `with_temp_dir'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:134:in `block (2 levels) in add'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:461:in `with_temp_dir'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:115:in `block inadd' from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:448:in `block in with_collection_lock'
        from C:/HashiCorp/Vagrant/embedded/mingw64/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:447:in `with_collection_lock'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/box_collection.rb:104:in `add'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builtin/box_add.rb:357:in `box_add'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builtin/box_add.rb:146:in `add_direct'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builtin/box_add.rb:120:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/warden.rb:34:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/builder.rb:116:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/runner.rb:66:in `block in run'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/util/busy.rb:19:in `busy'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/action/runner.rb:66:in `run'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/plugins/commands/box/command/add.rb:78:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/plugins/commands/box/command/root.rb:66:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/cli.rb:46:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/lib/vagrant/environment.rb:269:in `cli'
        from C:/HashiCorp/Vagrant/embedded/gems/2.0.3/gems/vagrant-2.0.3/bin/vagrant:151:in `<main>'

问题:

  1. 是否有元数据文件参考?我已经搜索了,但就是找不到。
  2. 为什么会收到“box:未检测到Box文件作为元数据”的消息?我的归档文件中有metadata.json文件。
  3. "undefined method `to_sym'"错误的意思是什么?

环境...

  • 虚拟化操作系统:Microsoft Windows 10 Enterprise (10.0.15063)
  • 客户机操作系统:Windows Server 2016 Standard (64位)
  • 提供程序:Hyper-V Vagrant 2.0.3
  • 使用Bash on Ubuntu on Windows中的tar创建的Box归档文件
  • 从Powershell窗口添加的Box

Box的内容...

C:\img-misc-w2k16\Virtual Hard Disks
C:\img-misc-w2k16\Virtual Machines
C:\img-misc-w2k16\metadata.json
C:\img-misc-w2k16\Virtual Hard Disks\img-misc-w2k16.vhdx
C:\img-misc-w2k16\Virtual Machines\AB56D8F5-4F71-4CCD-97E6-237713B79FD8.... C:\img-misc-w2k16\Virtual Machines\AB56D8F5-4F71-4CCD-97E6-237713B79FD8....

metadata.json的内容...

{
    "name": "foo/windowsServer2016x64",
    "description": "This box contains Windows Server 2016 64-bit standard edition.",
    "versions": [
      {
        "version": "1.0.0",
        "providers": [
          {
            "name": "hyperv"
          }
        ]
      }
    ]
  }
1个回答

4

似乎有些人对这个盒子的不同方面存在一些困惑。

因此,参考自https://www.vagrantup.com/docs/boxes/format.html

Box文件 - 这是一个针对单个提供程序具体的压缩文件(tar、tar.gz、zip),可以包含任何内容。Vagrant核心从不使用此文件的内容。相反,它们会传递给提供程序。因此,VirtualBox盒子文件与VMware盒子文件等具有不同的内容。

Box目录元数据 - 这是一个JSON文档(通常在与HashiCorp的Vagrant Cloud交互期间交换),其中指定了盒子的名称、描述、可用版本、可用提供程序以及每个提供程序和版本的实际盒子文件(下一个组件)的URL。如果没有目录元数据,仍然可以直接添加盒子文件,但不支持版本控制和更新。

文件C:\img-misc-w2k16\metadata.json是盒子文件的一部分——它与盒子目录元数据不同(如果您想要分发您的盒子,则使用该元数据),但您共享的内容是盒子目录元数据。
进一步阅读:
在存档中,Vagrant确实期望一个单独的文件:metadata.json。这是一个完全与上述盒子目录元数据组件无关的JSON文件;每个盒子文件(在盒子文件内)只有一个metadata.json,而一个目录元数据JSON文档可以描述同一盒子的多个版本,可能跨越多个提供商。metadata.json必须至少包含“provider”键和盒子所用的提供者。Vagrant使用此项来验证盒子的提供者。例如,如果您的盒子是为VirtualBox准备的,则metadata.json将如下所示:{ "provider": "virtualbox" }。如果没有metadata.json文件,或者该文件不包含有效的JSON和至少一个“provider”键,则添加盒子时Vagrant会出现错误,因为它无法验证提供者。

因此,当您打包您的盒子时,metadata.json 的内容应该如下:

{
  "provider": "hyperv"
}

一旦您替换了文件的内容,就可以重新打包该文件,并且应该能够从该文件运行虚拟机。

完成。 "box: 成功为 'hyperv' 添加了盒子 'img-misc-w2k16' (v0)!" 谢谢先生!是否有模式或其他参考可指导盒子软件包中的 metadata.json 文件可以包含什么? - Adam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接