首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >理解Vagrant虚拟机导入

理解Vagrant虚拟机导入
EN

DevOps用户
提问于 2019-04-28 00:42:40
回答 1查看 112关注 0票数 2

我正在用packer构建我的WindowsServer2012VM,当我执行vagrant up时,它失败了,因为文件夹名已经存在了,…

这是我的json封隔器文件

代码语言:javascript
复制
{
  "builders": [
    {
      "boot_wait": "2m",
      "communicator": "winrm",
      "disk_size": "{{user `disk_size`}}",
      "floppy_files": [
        "{{user `autounattend`}}",
        "./scripts/disable-winrm.ps1",
        "./scripts/enable-winrm.ps1"
      ],
      "guest_additions_mode": "disable",
      "guest_os_type": "Windows2012_64",
      "headless": "{{user `headless`}}",
      "iso_checksum": "{{user `iso_checksum`}}",
      "iso_checksum_type": "{{user `iso_checksum_type`}}",
      "iso_url": "{{user `iso_url`}}",
      "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
      "type": "virtualbox-iso",
      "vboxmanage": [
        [
          "modifyvm",
          "{{.Name}}",
          "--memory",
          "2048"
        ],
        [
          "modifyvm",
          "{{.Name}}",
          "--nic1",
          "NAT"
        ],
        [
          "modifyvm",
          "{{.Name}}",
          "--cpus",
          "2"
        ]
      ],
      "vm_name": "windows_2012_r2",
      "winrm_password": "vagrant",
      "winrm_timeout": "{{user `winrm_timeout`}}",
      "winrm_username": "vagrant"
    }
  ],
  "post-processors": [
    {
      "keep_input_artifact": false,
      "output": "vagrantenv/windows_2012_r2_{{.Provider}}.box",
      "type": "vagrant",
      "vagrantfile_template": "vagrantfile-windows_2012_r2.template"
    }
  ],
  "provisioners": [
    {
      "scripts": [
        "./scripts/vm-guest-tools.bat",
        "./scripts/enable-rdp.bat"
      ],
      "type": "windows-shell"
    }
  ],
  "variables": {
    "autounattend": "./answer_files/2012_r2/Autounattend.xml",
    "disk_size": "61440",
    "disk_type_id": "1",
    "headless": "true",
    "iso_checksum": "5b5e08c490ad16b59b1d9fab0def883a",
    "iso_checksum_type": "md5",
    "iso_url": "./iso/windows_2012_r2.iso",
    "winrm_timeout": "30m"
  }
}

和我的post-processors模板

代码语言:javascript
复制
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.6.2"

Vagrant.configure("2") do |config|
    config.vm.box = "windows_2012_r2"
    config.vm.communicator = "winrm"

    # Admin user name and password
    config.winrm.username = "vagrant"
    config.winrm.password = "vagrant"

    config.vm.guest = :windows
    config.windows.halt_timeout = 15

    config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true

    config.vm.provider :virtualbox do |v, override|
        #v.gui = true
        v.name = "windows_2012_r2"
        v.customize ["modifyvm", :id, "--memory", 2048]
        v.customize ["modifyvm", :id, "--cpus", 2]
        v.customize ["modifyvm", :id, "--vram", 128]
        v.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
        v.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
        end
end

这个步骤非常有效,我最终得到了一个文件windows_2012_r2_virtualbox.box

然后我运行vagrant init -f windows_2012_r2 windows_2012_r2_virtualbox.box

最后是vagrant up

接下来,我得到了一个错误:

代码语言:javascript
复制
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'windows_2012_r2' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Box file was not detected as metadata. Adding it directly...
==> default: Adding box 'windows_2012_r2' (v0) for provider: virtualbox
    default: Unpacking necessary files from: file:///D:/Dev/packer-windows/vagrantenv/windows_2012_r2_virtualbox.box
    default:
==> default: Successfully added box 'windows_2012_r2' (v0) for 'virtualbox'!
==> default: Importing base box 'windows_2012_r2'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: windows_2012_r2
The name of your virtual machine couldn't be set because VirtualBox
is reporting another VM with that name already exists. Most of the
time, this is because of an error with VirtualBox not cleaning up
properly. To fix this, verify that no VMs with that name do exist
(by opening the VirtualBox GUI). If they don't, then look at the
folder in the error message from VirtualBox below and remove it
if there isn't any information you need in there.

VirtualBox error:

VBoxManage.exe: error: Could not rename the directory 'D:\VM\VirtualBox\windows_2012_r2_1556359923004_28925' to 'D:\VM\VirtualBox\windows_2012_r2' to save the settings file (VERR_ALREADY_EXISTS)
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component SessionMachine, interface IMachine, callee IUnknown
VBoxManage.exe: error: Context: "SaveSettings()" at line 3194 of file VBoxManageModifyVM.cpp

我注意到在舞台上

  • Successfully added box 'windows_2012_r2' (v0) for 'virtualbox'!迷航器在virtualbox文件夹中创建文件夹windows_2012_r2,然后在此阶段创建
  • default: Importing base box 'windows_2012_r2'...迷航器创建一个文件夹windows_2012_r2_1556359923004_28925并尝试将其重命名为windows_2012_r2,但由于它已经存在,所以无法对其进行重命名。
  • windows_2012_r2文件夹有windows_2012_r2-disk001 001_2.2.vmdk文件
  • windows_2012_r2_1556359923004_28925有windows_2012_r2_1556359923004_28925.vbox文件

我搞不懂,当导入一个打包器创建的盒子时,流浪者是如何管理Virtualbox的?为什么流浪者要重命名文件夹名,而不使用已经存在的目标文件夹呢?

EN

回答 1

DevOps用户

回答已采纳

发布于 2019-12-25 08:52:19

看上去有一种名称冲突:

代码语言:javascript
复制
The name of your virtual machine couldn't be set because VirtualBox
is reporting another VM with that name already exists. Most of the
time, this is because of an error with VirtualBox not cleaning up
properly. To fix this, verify that no VMs with that name do exist
(by opening the VirtualBox GUI). If they don't, then look at the
folder in the error message from VirtualBox below and remove it
if there isn't any information you need in there.

根据@xofer on Github,on必须设置name。但是,在您与日志一起提供的示例中,这个问题似乎是由创建并仍然存在于Virtualbox中的VM引起的。换句话说,必须确保VM已经被删除,或者必须定义另一个名称来防止这种冲突。

票数 2
EN
页面原文内容由DevOps提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://devops.stackexchange.com/questions/7971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档