github.com/ratanraj/packer@v1.3.2/website/source/docs/builders/virtualbox-ovf.html.md.erb (about)

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