github.com/tonnydourado/packer@v0.6.1-0.20140701134019-5d0cd9676a37/website/source/docs/builders/virtualbox-ovf.html.markdown (about)

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