github.com/daniellockard/packer@v0.7.6-0.20141210173435-5a9390934716/website/source/docs/builders/virtualbox-ovf.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  page_title: "VirtualBox Builder (from an OVF/OVA)"
     4  description: |-
     5    This VirtualBox Packer builder is able to create VirtualBox virtual machines and export them in the OVF format, starting from an existing OVF/OVA (exported virtual machine image).
     6  ---
     7  
     8  # VirtualBox Builder (from an OVF/OVA)
     9  
    10  Type: `virtualbox-ovf`
    11  
    12  This VirtualBox Packer builder is able to create [VirtualBox](https://www.virtualbox.org/)
    13  virtual machines and export them in the OVF format, starting from an
    14  existing OVF/OVA (exported virtual machine image).
    15  
    16  The builder builds a virtual machine by importing an existing OVF or OVA
    17  file. It then boots this image, runs provisioners on this new VM, and
    18  exports that VM to create the image. The imported machine is deleted prior
    19  to finishing the build.
    20  
    21  ## Basic Example
    22  
    23  Here is a basic example. This example is functional if you have an OVF matching
    24  the settings here.
    25  
    26  ```javascript
    27  {
    28    "type": "virtualbox-ovf",
    29    "source_path": "source.ovf",
    30    "ssh_username": "packer",
    31    "ssh_password": "packer",
    32    "ssh_wait_timeout": "30s",
    33    "shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
    34  }
    35  ```
    36  
    37  It is important to add a `shutdown_command`. By default Packer halts the
    38  virtual machine and the file system may not be sync'd. Thus, changes made in a
    39  provisioner might not be saved.
    40  
    41  ## Configuration Reference
    42  
    43  There are many configuration options available for the VirtualBox builder.
    44  They are organized below into two categories: required and optional. Within
    45  each category, the available options are alphabetized and described.
    46  
    47  ### Required:
    48  
    49  * `source_path` (string) - The path to an OVF or OVA file that acts as
    50    the source of this build.
    51  
    52  * `ssh_username` (string) - The username to use to SSH into the machine
    53    once the OS is installed.
    54  
    55  ### Optional:
    56  
    57  * `boot_command` (array of strings) - This is an array of commands to type
    58    when the virtual machine is first booted. The goal of these commands should
    59    be to type just enough to initialize the operating system installer. Special
    60    keys can be typed as well, and are covered in the section below on the boot
    61    command. If this is not specified, it is assumed the installer will start
    62    itself.
    63  
    64  * `boot_wait` (string) - The time to wait after booting the initial virtual
    65    machine before typing the `boot_command`. The value of this should be
    66    a duration. Examples are "5s" and "1m30s" which will cause Packer to wait
    67    five seconds and one minute 30 seconds, respectively. If this isn't specified,
    68    the default is 10 seconds.
    69  
    70  * `export_opts` (array of strings) - Additional options to pass to the `VBoxManage export`.
    71    This can be useful for passing product information to include in the resulting
    72    appliance file.
    73  
    74  * `floppy_files` (array of strings) - A list of files to place onto a floppy
    75    disk that is attached when the VM is booted. This is most useful
    76    for unattended Windows installs, which look for an `Autounattend.xml` file
    77    on removable media. By default, no floppy will be attached. All files
    78    listed in this setting get placed into the root directory of the floppy
    79    and the floppy is attached as the first floppy device. Currently, no
    80    support exists for creating sub-directories on the floppy. Wildcard
    81    characters (*, ?, and []) are allowed. Directory names are also allowed,
    82    which will add all the files found in the directory to the floppy.
    83  
    84  * `format` (string) - Either "ovf" or "ova", this specifies the output
    85    format of the exported virtual machine. This defaults to "ovf".
    86  
    87  * `guest_additions_mode` (string) - The method by which guest additions
    88    are made available to the guest for installation. Valid options are
    89    "upload", "attach", or "disable". The functions of each of these should be
    90    self-explanatory. The default value is "upload". If "disable" is used,
    91    guest additions won't be downloaded, either.
    92  
    93  * `guest_additions_path` (string) - The path on the guest virtual machine
    94    where the VirtualBox guest additions ISO will be uploaded. By default this
    95    is "VBoxGuestAdditions.iso" which should upload into the login directory
    96    of the user. This is a [configuration template](/docs/templates/configuration-templates.html)
    97    where the `Version` variable is replaced with the VirtualBox version.
    98  
    99  * `guest_additions_sha256` (string) - The SHA256 checksum of the guest
   100    additions ISO that will be uploaded to the guest VM. By default the
   101    checksums will be downloaded from the VirtualBox website, so this only
   102    needs to be set if you want to be explicit about the checksum.
   103  
   104  * `guest_additions_url` (string) - The URL to the guest additions ISO
   105    to upload. This can also be a file URL if the ISO is at a local path.
   106    By default the VirtualBox builder will go and download the proper
   107    guest additions ISO from the internet.
   108  
   109  * `headless` (boolean) - Packer defaults to building VirtualBox
   110    virtual machines by launching a GUI that shows the console of the
   111    machine being built. When this value is set to true, the machine will
   112    start without a console.
   113  
   114  * `http_directory` (string) - Path to a directory to serve using an HTTP
   115    server. The files in this directory will be available over HTTP that will
   116    be requestable from the virtual machine. This is useful for hosting
   117    kickstart files and so on. By default this is "", which means no HTTP
   118    server will be started. The address and port of the HTTP server will be
   119    available as variables in `boot_command`. This is covered in more detail
   120    below.
   121  
   122  * `http_port_min` and `http_port_max` (integer) - These are the minimum and
   123    maximum port to use for the HTTP server started to serve the `http_directory`.
   124    Because Packer often runs in parallel, Packer will choose a randomly available
   125    port in this range to run the HTTP server. If you want to force the HTTP
   126    server to be on one port, make this minimum and maximum port the same.
   127    By default the values are 8000 and 9000, respectively.
   128  
   129  * `import_flags` (array of strings) - Additional flags to pass to
   130      `VBoxManage import`. This can be used to add additional command-line flags
   131      such as `--eula-accept` to accept a EULA in the OVF.
   132  
   133  * `import_opts` (string) - Additional options to pass to the `VBoxManage import`.
   134    This can be useful for passing "keepallmacs" or "keepnatmacs" options for existing
   135    ovf images.
   136  
   137  * `output_directory` (string) - This is the path to the directory where the
   138    resulting virtual machine will be created. This may be relative or absolute.
   139    If relative, the path is relative to the working directory when `packer`
   140    is executed. This directory must not exist or be empty prior to running the builder.
   141    By default this is "output-BUILDNAME" where "BUILDNAME" is the name
   142    of the build.
   143  
   144  * `shutdown_command` (string) - The command to use to gracefully shut down
   145    the machine once all the provisioning is done. By default this is an empty
   146    string, which tells Packer to just forcefully shut down the machine.
   147  
   148  * `shutdown_timeout` (string) - The amount of time to wait after executing
   149    the `shutdown_command` for the virtual machine to actually shut down.
   150    If it doesn't shut down in this time, it is an error. By default, the timeout
   151    is "5m", or five minutes.
   152  
   153  * `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and
   154    maximum port to use for the SSH port on the host machine which is forwarded
   155    to the SSH port on the guest machine. Because Packer often runs in parallel,
   156    Packer will choose a randomly available port in this range to use as the
   157    host port.
   158  
   159  * `ssh_key_path` (string) - Path to a private key to use for authenticating
   160    with SSH. By default this is not set (key-based auth won't be used).
   161    The associated public key is expected to already be configured on the
   162    VM being prepared by some other process (kickstart, etc.).
   163  
   164  * `ssh_password` (string) - The password for `ssh_username` to use to
   165    authenticate with SSH. By default this is the empty string.
   166  
   167  * `ssh_port` (integer) - The port that SSH will be listening on in the guest
   168    virtual machine. By default this is 22.
   169  
   170  * `ssh_wait_timeout` (string) - The duration to wait for SSH to become
   171    available. By default this is "20m", or 20 minutes. Note that this should
   172    be quite long since the timer begins as soon as the virtual machine is booted.
   173  
   174  * `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
   175    execute in order to further customize the virtual machine being created.
   176    The value of this is an array of commands to execute. The commands are executed
   177    in the order defined in the template. For each command, the command is
   178    defined itself as an array of strings, where each string represents a single
   179    argument on the command-line to `VBoxManage` (but excluding `VBoxManage`
   180    itself). Each arg is treated as a [configuration template](/docs/templates/configuration-templates.html),
   181    where the `Name` variable is replaced with the VM name. More details on how
   182    to use `VBoxManage` are below.
   183  
   184  * `vboxmanage_post` (array of array of strings) - Identical to `vboxmanage`,
   185    except that it is run after the virtual machine is shutdown, and before the
   186    virtual machine is exported.
   187  
   188  * `virtualbox_version_file` (string) - The path within the virtual machine
   189    to upload a file that contains the VirtualBox version that was used to
   190    create the machine. This information can be useful for provisioning.
   191    By default this is ".vbox_version", which will generally be upload it into
   192    the home directory.
   193  
   194  * `vm_name` (string) - This is the name of the virtual machine when it is
   195    imported as well as the name of the OVF file when the virtual machine is
   196    exported. By default this is "packer-BUILDNAME", where "BUILDNAME" is
   197    the name of the build.
   198  
   199  ## Guest Additions
   200  
   201  Packer will automatically download the proper guest additions for the
   202  version of VirtualBox that is running and upload those guest additions into
   203  the virtual machine so that provisioners can easily install them.
   204  
   205  Packer downloads the guest additions from the official VirtualBox website,
   206  and verifies the file with the official checksums released by VirtualBox.
   207  
   208  After the virtual machine is up and the operating system is installed,
   209  Packer uploads the guest additions into the virtual machine. The path where
   210  they are uploaded is controllable by `guest_additions_path`, and defaults
   211  to "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the
   212  home directory of the SSH user.
   213  
   214  ## VBoxManage Commands
   215  
   216  In order to perform extra customization of the virtual machine, a template
   217  can define extra calls to `VBoxManage` to perform. [VBoxManage](http://www.virtualbox.org/manual/ch08.html)
   218  is the command-line interface to VirtualBox where you can completely control
   219  VirtualBox. It can be used to do things such as set RAM, CPUs, etc.
   220  
   221  Extra VBoxManage commands are defined in the template in the `vboxmanage` section.
   222  An example is shown below that sets the memory and number of CPUs within the
   223  virtual machine:
   224  
   225  ```javascript
   226  {
   227    "vboxmanage": [
   228      ["modifyvm", "{{.Name}}", "--memory", "1024"],
   229      ["modifyvm", "{{.Name}}", "--cpus", "2"]
   230    ]
   231  }
   232  ```
   233  
   234  The value of `vboxmanage` is an array of commands to execute. These commands
   235  are executed in the order defined. So in the above example, the memory will be
   236  set followed by the CPUs.
   237  
   238  Each command itself is an array of strings, where each string is an argument
   239  to `VBoxManage`. Each argument is treated as a
   240  [configuration template](/docs/templates/configuration-templates.html).
   241  The only available variable is `Name` which is replaced with the unique
   242  name of the VM, which is required for many VBoxManage calls.