github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/website/source/docs/builders/virtualbox-ovf.html.md (about)

     1  ---
     2  description: |
     3      This VirtualBox Packer builder is able to create VirtualBox virtual machines and
     4      export them in the OVF format, starting from an existing OVF/OVA (exported
     5      virtual machine image).
     6  layout: docs
     7  page_title: 'VirtualBox Builder (from an OVF/OVA)'
     8  ...
     9  
    10  # VirtualBox Builder (from an OVF/OVA)
    11  
    12  Type: `virtualbox-ovf`
    13  
    14  This VirtualBox Packer builder is able to create
    15  [VirtualBox](https://www.virtualbox.org/) virtual machines and export them in
    16  the OVF format, starting from an existing OVF/OVA (exported virtual machine
    17  image).
    18  
    19  When exporting from VirtualBox make sure to choose OVF Version 2, since Version
    20  1 is not compatible and will generate errors like this:
    21  
    22      ==> virtualbox-ovf: Progress state: VBOX_E_FILE_ERROR
    23      ==> virtualbox-ovf: VBoxManage: error: Appliance read failed
    24      ==> virtualbox-ovf: VBoxManage: error: Error reading "source.ova": element "Section" has no "type" attribute, line 21
    25      ==> virtualbox-ovf: VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Appliance, interface IAppliance
    26      ==> virtualbox-ovf: VBoxManage: error: Context: "int handleImportAppliance(HandlerArg*)" at line 304 of file VBoxManageAppliance.cpp
    27  
    28  The builder builds a virtual machine by importing an existing OVF or OVA file.
    29  It then boots this image, runs provisioners on this new VM, and exports that VM
    30  to create the image. The imported machine is deleted prior to finishing the
    31  build.
    32  
    33  ## Basic Example
    34  
    35  Here is a basic example. This example is functional if you have an OVF matching
    36  the settings here.
    37  
    38  ``` {.javascript}
    39  {
    40    "type": "virtualbox-ovf",
    41    "source_path": "source.ovf",
    42    "ssh_username": "packer",
    43    "ssh_password": "packer",
    44    "shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
    45  }
    46  ```
    47  
    48  It is important to add a `shutdown_command`. By default Packer halts the virtual
    49  machine and the file system may not be sync'd. Thus, changes made in a
    50  provisioner might not be saved.
    51  
    52  ## Configuration Reference
    53  
    54  There are many configuration options available for the VirtualBox builder. They
    55  are organized below into two categories: required and optional. Within each
    56  category, the available options are alphabetized and described.
    57  
    58  In addition to the options listed here, a
    59  [communicator](/docs/templates/communicator.html) can be configured for this
    60  builder.
    61  
    62  ### Required:
    63  
    64  -   `source_path` (string) - The path to an OVF or OVA file that acts as the
    65      source of this build.
    66  
    67  -   `ssh_username` (string) - The username to use to SSH into the machine once
    68      the OS is installed.
    69  
    70  ### Optional:
    71  
    72  -   `boot_command` (array of strings) - This is an array of commands to type
    73      when the virtual machine is first booted. The goal of these commands should
    74      be to type just enough to initialize the operating system installer. Special
    75      keys can be typed as well, and are covered in the section below on the
    76      boot command. If this is not specified, it is assumed the installer will
    77      start itself.
    78  
    79  -   `boot_wait` (string) - The time to wait after booting the initial virtual
    80      machine before typing the `boot_command`. The value of this should be
    81      a duration. Examples are "5s" and "1m30s" which will cause Packer to wait
    82      five seconds and one minute 30 seconds, respectively. If this isn't
    83      specified, the default is 10 seconds.
    84  
    85  -   `export_opts` (array of strings) - Additional options to pass to the
    86      [VBoxManage export](https://www.virtualbox.org/manual/ch08.html#vboxmanage-export).
    87      This can be useful for passing product information to include in the
    88      resulting appliance file. Packer JSON configuration file example:
    89  
    90      ``` {.json}
    91      {
    92        "type": "virtualbox-ovf",
    93        "export_opts":
    94        [
    95          "--manifest",
    96          "--vsys", "0",
    97          "--description", "{{user `vm_description`}}",
    98          "--version", "{{user `vm_version`}}"
    99        ],
   100        "format": "ova",
   101      }
   102      ```
   103  
   104      A VirtualBox [VM description](https://www.virtualbox.org/manual/ch08.html#idm3756)
   105      may contain arbitrary strings; the GUI interprets HTML formatting.
   106      However, the JSON format does not allow arbitrary newlines within a
   107      value. Add a multi-line description by preparing the string in the
   108      shell before the packer call like this (shell `>` continuation
   109      character snipped for easier copy & paste):
   110  
   111      ``` {.shell}
   112  
   113      vm_description='some
   114      multiline
   115      description'
   116  
   117      vm_version='0.2.0'
   118  
   119      packer build \
   120          -var "vm_description=${vm_description}" \
   121          -var "vm_version=${vm_version}"         \
   122          "packer_conf.json"
   123      ```
   124  
   125  -   `floppy_files` (array of strings) - A list of files to place onto a floppy
   126      disk that is attached when the VM is booted. This is most useful for
   127      unattended Windows installs, which look for an `Autounattend.xml` file on
   128      removable media. By default, no floppy will be attached. All files listed in
   129      this setting get placed into the root directory of the floppy and the floppy
   130      is attached as the first floppy device. Currently, no support exists for
   131      creating sub-directories on the floppy. Wildcard characters (\*, ?,
   132      and \[\]) are allowed. Directory names are also allowed, which will add all
   133      the files found in the directory to the floppy.
   134  
   135  -   `floppy_dirs` (array of strings) - A list of directories to place onto
   136      the floppy disk recursively. This is similar to the `floppy_files` option
   137      except that the directory structure is preserved. This is useful for when
   138      your floppy disk includes drivers or if you just want to organize it's 
   139      contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed.
   140  
   141  -   `format` (string) - Either "ovf" or "ova", this specifies the output format
   142      of the exported virtual machine. This defaults to "ovf".
   143  
   144  -   `guest_additions_mode` (string) - The method by which guest additions are
   145      made available to the guest for installation. Valid options are "upload",
   146      "attach", or "disable". If the mode is "attach" the guest additions ISO will
   147      be attached as a CD device to the virtual machine. If the mode is "upload"
   148      the guest additions ISO will be uploaded to the path specified by
   149      `guest_additions_path`. The default value is "upload". If "disable" is used,
   150      guest additions won't be downloaded, either.
   151  
   152  -   `guest_additions_path` (string) - The path on the guest virtual machine
   153      where the VirtualBox guest additions ISO will be uploaded. By default this
   154      is "VBoxGuestAdditions.iso" which should upload into the login directory of
   155      the user. This is a [configuration
   156      template](/docs/templates/configuration-templates.html) where the `Version`
   157      variable is replaced with the VirtualBox version.
   158  
   159  -   `guest_additions_sha256` (string) - The SHA256 checksum of the guest
   160      additions ISO that will be uploaded to the guest VM. By default the
   161      checksums will be downloaded from the VirtualBox website, so this only needs
   162      to be set if you want to be explicit about the checksum.
   163  
   164  -   `guest_additions_url` (string) - The URL to the guest additions ISO
   165      to upload. This can also be a file URL if the ISO is at a local path. By
   166      default the VirtualBox builder will go and download the proper guest
   167      additions ISO from the internet.
   168  
   169  -   `headless` (boolean) - Packer defaults to building VirtualBox virtual
   170      machines by launching a GUI that shows the console of the machine
   171      being built. When this value is set to true, the machine will start without
   172      a console.
   173  
   174  -   `http_directory` (string) - Path to a directory to serve using an
   175      HTTP server. The files in this directory will be available over HTTP that
   176      will be requestable from the virtual machine. This is useful for hosting
   177      kickstart files and so on. By default this is "", which means no HTTP server
   178      will be started. The address and port of the HTTP server will be available
   179      as variables in `boot_command`. This is covered in more detail below.
   180  
   181  -   `http_port_min` and `http_port_max` (integer) - These are the minimum and
   182      maximum port to use for the HTTP server started to serve the
   183      `http_directory`. Because Packer often runs in parallel, Packer will choose
   184      a randomly available port in this range to run the HTTP server. If you want
   185      to force the HTTP server to be on one port, make this minimum and maximum
   186      port the same. By default the values are 8000 and 9000, respectively.
   187  
   188  -   `import_flags` (array of strings) - Additional flags to pass to
   189      `VBoxManage import`. This can be used to add additional command-line flags
   190      such as `--eula-accept` to accept a EULA in the OVF.
   191  
   192  -   `import_opts` (string) - Additional options to pass to the
   193      `VBoxManage import`. This can be useful for passing "keepallmacs" or
   194      "keepnatmacs" options for existing ovf images.
   195  
   196  -   `output_directory` (string) - This is the path to the directory where the
   197      resulting virtual machine will be created. This may be relative or absolute.
   198      If relative, the path is relative to the working directory when `packer`
   199      is executed. This directory must not exist or be empty prior to running
   200      the builder. By default this is "output-BUILDNAME" where "BUILDNAME" is the
   201      name of the build.
   202  
   203  -   `post_shutdown_delay` (string) - The amount of time to wait after shutting
   204      down the virtual machine. If you get the error `Error removing floppy
   205      controller`, you might need to set this to `5m` or so. By default, the
   206      delay is `0s`, or disabled.
   207  
   208  -   `shutdown_command` (string) - The command to use to gracefully shut down the
   209      machine once all the provisioning is done. By default this is an empty
   210      string, which tells Packer to just forcefully shut down the machine unless a
   211      shutdown command takes place inside script so this may safely be omitted. If
   212      one or more scripts require a reboot it is suggested to leave this blank
   213      since reboots may fail and specify the final shutdown command in your
   214      last script.
   215  
   216  -   `shutdown_timeout` (string) - The amount of time to wait after executing the
   217      `shutdown_command` for the virtual machine to actually shut down. If it
   218      doesn't shut down in this time, it is an error. By default, the timeout is
   219      "5m", or five minutes.
   220  
   221  -   `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and
   222      maximum port to use for the SSH port on the host machine which is forwarded
   223      to the SSH port on the guest machine. Because Packer often runs in parallel,
   224      Packer will choose a randomly available port in this range to use as the
   225      host port.
   226  
   227  -   `ssh_skip_nat_mapping` (boolean) - Defaults to false. When enabled, Packer
   228      does not setup forwarded port mapping for SSH requests and uses `ssh_port`
   229      on the host to communicate to the virtual machine
   230  
   231  -   `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
   232      execute in order to further customize the virtual machine being created. The
   233      value of this is an array of commands to execute. The commands are executed
   234      in the order defined in the template. For each command, the command is
   235      defined itself as an array of strings, where each string represents a single
   236      argument on the command-line to `VBoxManage` (but excluding
   237      `VBoxManage` itself). Each arg is treated as a [configuration
   238      template](/docs/templates/configuration-templates.html), where the `Name`
   239      variable is replaced with the VM name. More details on how to use
   240      `VBoxManage` are below.
   241  
   242  -   `vboxmanage_post` (array of array of strings) - Identical to `vboxmanage`,
   243      except that it is run after the virtual machine is shutdown, and before the
   244      virtual machine is exported.
   245  
   246  -   `virtualbox_version_file` (string) - The path within the virtual machine to
   247      upload a file that contains the VirtualBox version that was used to create
   248      the machine. This information can be useful for provisioning. By default
   249      this is ".vbox\_version", which will generally be upload it into the
   250      home directory.
   251  
   252  -   `vm_name` (string) - This is the name of the virtual machine when it is
   253      imported as well as the name of the OVF file when the virtual machine
   254      is exported. By default this is "packer-BUILDNAME", where "BUILDNAME" is the
   255      name of the build.
   256  
   257  -   `vrdp_bind_address` (string / IP address) - The IP address that should be binded
   258       to for VRDP. By default packer will use 127.0.0.1 for this.
   259  
   260  -   `vrdp_port_min` and `vrdp_port_max` (integer) - The minimum and maximum port
   261      to use for VRDP access to the virtual machine. Packer uses a randomly chosen
   262      port in this range that appears available. By default this is 5900 to 6000.
   263      The minimum and maximum ports are inclusive.
   264  
   265  ## Boot Command
   266  
   267  The `boot_command` configuration is very important: it specifies the keys to
   268  type when the virtual machine is first booted in order to start the OS
   269  installer. This command is typed after `boot_wait`.
   270  
   271  As documented above, the `boot_command` is an array of strings. The strings are
   272  all typed in sequence. It is an array only to improve readability within the
   273  template.
   274  
   275  The boot command is "typed" character for character over a VNC connection to the
   276  machine, simulating a human actually typing the keyboard. There are a set of
   277  special keys available. If these are in your boot command, they will be replaced
   278  by the proper key:
   279  
   280  -   `<bs>` - Backspace
   281  
   282  -   `<del>` - Delete
   283  
   284  -   `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress.
   285  
   286  -   `<esc>` - Simulates pressing the escape key.
   287  
   288  -   `<tab>` - Simulates pressing the tab key.
   289  
   290  -   `<f1>` - `<f12>` - Simulates pressing a function key.
   291  
   292  -   `<up>` `<down>` `<left>` `<right>` - Simulates pressing an arrow key.
   293  
   294  -   `<spacebar>` - Simulates pressing the spacebar.
   295  
   296  -   `<insert>` - Simulates pressing the insert key.
   297  
   298  -   `<home>` `<end>` - Simulates pressing the home and end keys.
   299  
   300  -   `<pageUp>` `<pageDown>` - Simulates pressing the page up and page down keys.
   301  
   302  -   `<leftAlt>` `<rightAlt>`  - Simulates pressing the alt key.
   303  
   304  -   `<leftCtrl>` `<rightCtrl>` - Simulates pressing the ctrl key.
   305  
   306  -   `<leftShift>` `<rightShift>` - Simulates pressing the shift key.
   307  
   308  -   `<leftAltOn>` `<rightAltOn>`  - Simulates pressing and holding the alt key.
   309  
   310  -   `<leftCtrlOn>` `<rightCtrlOn>` - Simulates pressing and holding the ctrl key. 
   311  
   312  -   `<leftShiftOn>` `<rightShiftOn>` - Simulates pressing and holding the shift key.
   313  
   314  -   `<leftAltOff>` `<rightAltOff>`  - Simulates releasing a held alt key.
   315  
   316  -   `<leftCtrlOff>` `<rightCtrlOff>` - Simulates releasing a held ctrl key.
   317  
   318  -   `<leftShiftOff>` `<rightShiftOff>` - Simulates releasing a held shift key.
   319  
   320  -   `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before
   321      sending any additional keys. This is useful if you have to generally wait
   322      for the UI to update before typing more.
   323  
   324  In addition to the special keys, each command to type is treated as a
   325  [configuration template](/docs/templates/configuration-templates.html). The
   326  available variables are:
   327  
   328  -   `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server
   329      that is started serving the directory specified by the `http_directory`
   330      configuration parameter. If `http_directory` isn't specified, these will be
   331      blank!
   332  
   333  Example boot command. This is actually a working boot command used to start an
   334  Ubuntu 12.04 installer:
   335  
   336  ``` {.text}
   337  [
   338    "<esc><esc><enter><wait>",
   339    "/install/vmlinuz noapic ",
   340    "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
   341    "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
   342    "hostname={{ .Name }} ",
   343    "fb=false debconf/frontend=noninteractive ",
   344    "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
   345    "keyboard-configuration/variant=USA console-setup/ask_detect=false ",
   346    "initrd=/install/initrd.gz -- <enter>"
   347  ]
   348  ```
   349  
   350  ## Guest Additions
   351  
   352  Packer will automatically download the proper guest additions for the version of
   353  VirtualBox that is running and upload those guest additions into the virtual
   354  machine so that provisioners can easily install them.
   355  
   356  Packer downloads the guest additions from the official VirtualBox website, and
   357  verifies the file with the official checksums released by VirtualBox.
   358  
   359  After the virtual machine is up and the operating system is installed, Packer
   360  uploads the guest additions into the virtual machine. The path where they are
   361  uploaded is controllable by `guest_additions_path`, and defaults to
   362  "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the home
   363  directory of the SSH user.
   364  
   365  ## VBoxManage Commands
   366  
   367  In order to perform extra customization of the virtual machine, a template can
   368  define extra calls to `VBoxManage` to perform.
   369  [VBoxManage](https://www.virtualbox.org/manual/ch08.html) is the command-line
   370  interface to VirtualBox where you can completely control VirtualBox. It can be
   371  used to do things such as set RAM, CPUs, etc.
   372  
   373  Extra VBoxManage commands are defined in the template in the `vboxmanage`
   374  section. An example is shown below that sets the memory and number of CPUs
   375  within the virtual machine:
   376  
   377  ``` {.javascript}
   378  {
   379    "vboxmanage": [
   380      ["modifyvm", "{{.Name}}", "--memory", "1024"],
   381      ["modifyvm", "{{.Name}}", "--cpus", "2"]
   382    ]
   383  }
   384  ```
   385  
   386  The value of `vboxmanage` is an array of commands to execute. These commands are
   387  executed in the order defined. So in the above example, the memory will be set
   388  followed by the CPUs.
   389  
   390  Each command itself is an array of strings, where each string is an argument to
   391  `VBoxManage`. Each argument is treated as a [configuration
   392  template](/docs/templates/configuration-templates.html). The only available
   393  variable is `Name` which is replaced with the unique name of the VM, which is
   394  required for many VBoxManage calls.