github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/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. It can also be a URL.
    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  -   `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_files` (array of strings) - A list of files to place onto a floppy
   137      disk that is attached when the VM is booted. This is most useful for
   138      unattended Windows installs, which look for an `Autounattend.xml` file on
   139      removable media. By default, no floppy will be attached. All files listed in
   140      this setting get placed into the root directory of the floppy and the floppy
   141      is attached as the first floppy device. Currently, no support exists for
   142      creating sub-directories on the floppy. Wildcard characters (\*, ?,
   143      and \[\]) are allowed. Directory names are also allowed, which will add all
   144      the files found in the directory to the floppy.
   145  
   146  -   `floppy_dirs` (array of strings) - A list of directories to place onto the
   147      floppy disk recursively. This is similar to the `floppy_files` option except
   148      that the directory structure is preserved. This is useful for when your
   149      floppy disk includes drivers or if you just want to organize it's contents
   150      as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed.
   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/configuration-templates.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 without
   183      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 "", which means no HTTP server
   189      will be started. The address and port of the HTTP server will be available
   190      as variables in `boot_command`. This is covered in more detail below.
   191  
   192  -   `http_port_min` and `http_port_max` (integer) - These are the minimum and
   193      maximum port to use for the HTTP server started to serve the
   194      `http_directory`. Because Packer often runs in parallel, Packer will choose
   195      a randomly available port in this range to run the HTTP server. If you want
   196      to force the HTTP server to be on one port, make this minimum and maximum
   197      port the same. By default the values are 8000 and 9000, respectively.
   198  
   199  -   `import_flags` (array of strings) - Additional flags to pass to
   200      `VBoxManage import`. This can be used to add additional command-line flags
   201      such as `--eula-accept` to accept a EULA in the OVF.
   202  
   203  -   `import_opts` (string) - Additional options to pass to the
   204      `VBoxManage import`. This can be useful for passing "keepallmacs" or
   205      "keepnatmacs" options for existing ovf images.
   206  
   207  -   `output_directory` (string) - This is the path to the directory where the
   208      resulting virtual machine will be created. This may be relative or absolute.
   209      If relative, the path is relative to the working directory when `packer`
   210      is executed. This directory must not exist or be empty prior to running
   211      the builder. By default this is "output-BUILDNAME" where "BUILDNAME" is the
   212      name of the build.
   213  
   214  -   `post_shutdown_delay` (string) - The amount of time to wait after shutting
   215      down the virtual machine. If you get the error
   216      `Error removing floppy controller`, you might need to set this to `5m`
   217      or so. By default, the delay is `0s`, or disabled.
   218  
   219  -   `shutdown_command` (string) - The command to use to gracefully shut down the
   220      machine once all the provisioning is done. By default this is an empty
   221      string, which tells Packer to just forcefully shut down the machine unless a
   222      shutdown command takes place inside script so this may safely be omitted. If
   223      one or more scripts require a reboot it is suggested to leave this blank
   224      since reboots may fail and specify the final shutdown command in your
   225      last script.
   226  
   227  -   `shutdown_timeout` (string) - The amount of time to wait after executing the
   228      `shutdown_command` for the virtual machine to actually shut down. If it
   229      doesn't shut down in this time, it is an error. By default, the timeout is
   230      "5m", or five minutes.
   231  
   232  -   `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and
   233      maximum port to use for the SSH port on the host machine which is forwarded
   234      to the SSH port on the guest machine. Because Packer often runs in parallel,
   235      Packer will choose a randomly available port in this range to use as the
   236      host port.
   237  
   238  -   `ssh_skip_nat_mapping` (boolean) - Defaults to false. When enabled, Packer
   239      does not setup forwarded port mapping for SSH requests and uses `ssh_port`
   240      on the host to communicate to the virtual machine
   241  
   242  -   `target_path` (string) - The path where the OVA should be saved
   243      after download. By default, it will go in the packer cache, with a hash of
   244      the original filename as its name.
   245  
   246  -   `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
   247      execute in order to further customize the virtual machine being created. The
   248      value of this is an array of commands to execute. The commands are executed
   249      in the order defined in the template. For each command, the command is
   250      defined itself as an array of strings, where each string represents a single
   251      argument on the command-line to `VBoxManage` (but excluding
   252      `VBoxManage` itself). Each arg is treated as a [configuration
   253      template](/docs/templates/configuration-templates.html), where the `Name`
   254      variable is replaced with the VM name. More details on how to use
   255      `VBoxManage` are below.
   256  
   257  -   `vboxmanage_post` (array of array of strings) - Identical to `vboxmanage`,
   258      except that it is run after the virtual machine is shutdown, and before the
   259      virtual machine is exported.
   260  
   261  -   `virtualbox_version_file` (string) - The path within the virtual machine to
   262      upload a file that contains the VirtualBox version that was used to create
   263      the machine. This information can be useful for provisioning. By default
   264      this is ".vbox\_version", which will generally be upload it into the
   265      home directory.
   266  
   267  -   `vm_name` (string) - This is the name of the virtual machine when it is
   268      imported as well as the name of the OVF file when the virtual machine
   269      is exported. By default this is "packer-BUILDNAME", where "BUILDNAME" is the
   270      name of the build.
   271  
   272  -   `vrdp_bind_address` (string / IP address) - The IP address that should be
   273      binded to for VRDP. By default packer will use 127.0.0.1 for this.
   274  
   275  -   `vrdp_port_min` and `vrdp_port_max` (integer) - The minimum and maximum port
   276      to use for VRDP access to the virtual machine. Packer uses a randomly chosen
   277      port in this range that appears available. By default this is 5900 to 6000.
   278      The minimum and maximum ports are inclusive.
   279  
   280  ## Boot Command
   281  
   282  The `boot_command` configuration is very important: it specifies the keys to
   283  type when the virtual machine is first booted in order to start the OS
   284  installer. This command is typed after `boot_wait`.
   285  
   286  As documented above, the `boot_command` is an array of strings. The strings are
   287  all typed in sequence. It is an array only to improve readability within the
   288  template.
   289  
   290  The boot command is "typed" character for character over a VNC connection to the
   291  machine, simulating a human actually typing the keyboard. There are a set of
   292  special keys available. If these are in your boot command, they will be replaced
   293  by the proper key:
   294  
   295  -   `<bs>` - Backspace
   296  
   297  -   `<del>` - Delete
   298  
   299  -   `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress.
   300  
   301  -   `<esc>` - Simulates pressing the escape key.
   302  
   303  -   `<tab>` - Simulates pressing the tab key.
   304  
   305  -   `<f1>` - `<f12>` - Simulates pressing a function key.
   306  
   307  -   `<up>` `<down>` `<left>` `<right>` - Simulates pressing an arrow key.
   308  
   309  -   `<spacebar>` - Simulates pressing the spacebar.
   310  
   311  -   `<insert>` - Simulates pressing the insert key.
   312  
   313  -   `<home>` `<end>` - Simulates pressing the home and end keys.
   314  
   315  -   `<pageUp>` `<pageDown>` - Simulates pressing the page up and page down keys.
   316  
   317  -   `<leftAlt>` `<rightAlt>` - Simulates pressing the alt key.
   318  
   319  -   `<leftCtrl>` `<rightCtrl>` - Simulates pressing the ctrl key.
   320  
   321  -   `<leftShift>` `<rightShift>` - Simulates pressing the shift key.
   322  
   323  -   `<leftAltOn>` `<rightAltOn>` - Simulates pressing and holding the alt key.
   324  
   325  -   `<leftCtrlOn>` `<rightCtrlOn>` - Simulates pressing and holding the
   326      ctrl key.
   327  
   328  -   `<leftShiftOn>` `<rightShiftOn>` - Simulates pressing and holding the
   329      shift key.
   330  
   331  -   `<leftAltOff>` `<rightAltOff>` - Simulates releasing a held alt key.
   332  
   333  -   `<leftCtrlOff>` `<rightCtrlOff>` - Simulates releasing a held ctrl key.
   334  
   335  -   `<leftShiftOff>` `<rightShiftOff>` - Simulates releasing a held shift key.
   336  
   337  -   `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before
   338      sending any additional keys. This is useful if you have to generally wait
   339      for the UI to update before typing more.
   340  
   341  In addition to the special keys, each command to type is treated as a
   342  [configuration template](/docs/templates/configuration-templates.html). The
   343  available variables are:
   344  
   345  -   `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server
   346      that is started serving the directory specified by the `http_directory`
   347      configuration parameter. If `http_directory` isn't specified, these will be
   348      blank!
   349  
   350  Example boot command. This is actually a working boot command used to start an
   351  Ubuntu 12.04 installer:
   352  
   353  ``` {.text}
   354  [
   355    "<esc><esc><enter><wait>",
   356    "/install/vmlinuz noapic ",
   357    "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
   358    "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
   359    "hostname={{ .Name }} ",
   360    "fb=false debconf/frontend=noninteractive ",
   361    "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
   362    "keyboard-configuration/variant=USA console-setup/ask_detect=false ",
   363    "initrd=/install/initrd.gz -- <enter>"
   364  ]
   365  ```
   366  
   367  ## Guest Additions
   368  
   369  Packer will automatically download the proper guest additions for the version of
   370  VirtualBox that is running and upload those guest additions into the virtual
   371  machine so that provisioners can easily install them.
   372  
   373  Packer downloads the guest additions from the official VirtualBox website, and
   374  verifies the file with the official checksums released by VirtualBox.
   375  
   376  After the virtual machine is up and the operating system is installed, Packer
   377  uploads the guest additions into the virtual machine. The path where they are
   378  uploaded is controllable by `guest_additions_path`, and defaults to
   379  "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the home
   380  directory of the SSH user.
   381  
   382  ## VBoxManage Commands
   383  
   384  In order to perform extra customization of the virtual machine, a template can
   385  define extra calls to `VBoxManage` to perform.
   386  [VBoxManage](https://www.virtualbox.org/manual/ch08.html) is the command-line
   387  interface to VirtualBox where you can completely control VirtualBox. It can be
   388  used to do things such as set RAM, CPUs, etc.
   389  
   390  Extra VBoxManage commands are defined in the template in the `vboxmanage`
   391  section. An example is shown below that sets the memory and number of CPUs
   392  within the virtual machine:
   393  
   394  ``` {.javascript}
   395  {
   396    "vboxmanage": [
   397      ["modifyvm", "{{.Name}}", "--memory", "1024"],
   398      ["modifyvm", "{{.Name}}", "--cpus", "2"]
   399    ]
   400  }
   401  ```
   402  
   403  The value of `vboxmanage` is an array of commands to execute. These commands are
   404  executed in the order defined. So in the above example, the memory will be set
   405  followed by the CPUs.
   406  
   407  Each command itself is an array of strings, where each string is an argument to
   408  `VBoxManage`. Each argument is treated as a [configuration
   409  template](/docs/templates/configuration-templates.html). The only available
   410  variable is `Name` which is replaced with the unique name of the VM, which is
   411  required for many VBoxManage calls.