github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/website/source/docs/builders/virtualbox-ovf.html.md (about)

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