github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/website/source/docs/builders/virtualbox.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  ---
     4  
     5  # VirtualBox Builder
     6  
     7  Type: `virtualbox`
     8  
     9  The VirtualBox builder is able to create [VirtualBox](https://www.virtualbox.org/)
    10  virtual machines and export them in the OVF format.
    11  
    12  The builder builds a virtual machine by creating a new virtual machine
    13  from scratch, booting it, installing an OS, provisioning software within
    14  the OS, then shutting it down. The result of the VirtualBox builder is a directory
    15  containing all the files necessary to run the virtual machine portably.
    16  
    17  ## Basic Example
    18  
    19  Here is a basic example. This example is not functional. It will start the
    20  OS installer but then fail because we don't provide the preseed file for
    21  Ubuntu to self-install. Still, the example serves to show the basic configuration:
    22  
    23  <pre class="prettyprint">
    24  {
    25    "type": "virtualbox",
    26    "guest_os_type": "Ubuntu_64",
    27    "iso_url": "http://releases.ubuntu.com/12.04/ubuntu-12.04.2-server-amd64.iso",
    28    "iso_checksum": "af5f788aee1b32c4b2634734309cc9e9",
    29    "iso_checksum_type": "md5",
    30    "ssh_username": "packer",
    31    "ssh_wait_timeout": "30s",
    32    "shutdown_command": "shutdown -P now"
    33  }
    34  </pre>
    35  
    36  ## Configuration Reference
    37  
    38  There are many configuration options available for the VirtualBox builder.
    39  They are organized below into two categories: required and optional. Within
    40  each category, the available options are alphabetized and described.
    41  
    42  Required:
    43  
    44  * `iso_checksum` (string) - The checksum for the OS ISO file. Because ISO
    45    files are so large, this is required and Packer will verify it prior
    46    to booting a virtual machine with the ISO attached. The type of the
    47    checksum is specified with `iso_checksum_type`, documented below.
    48  
    49  * `iso_checksum_type` (string) - The type of the checksum specified in
    50    `iso_checksum`. Valid values are "md5", "sha1", or "sha256" currently.
    51  
    52  * `iso_url` (string) - A URL to the ISO containing the installation image.
    53    This URL can be either an HTTP URL or a file URL (or path to a file).
    54    If this is an HTTP URL, Packer will download it and cache it between
    55    runs.
    56  
    57  * `ssh_username` (string) - The username to use to SSH into the machine
    58    once the OS is installed.
    59  
    60  Optional:
    61  
    62  * `boot_command` (array of strings) - This is an array of commands to type
    63    when the virtual machine is first booted. The goal of these commands should
    64    be to type just enough to initialize the operating system installer. Special
    65    keys can be typed as well, and are covered in the section below on the boot
    66    command. If this is not specified, it is assumed the installer will start
    67    itself.
    68  
    69  * `boot_wait` (string) - The time to wait after booting the initial virtual
    70    machine before typing the `boot_command`. The value of this should be
    71    a duration. Examples are "5s" and "1m30s" which will cause Packer to wait
    72    five seconds and one minute 30 seconds, respectively. If this isn't specified,
    73    the default is 10 seconds.
    74  
    75  * `disk_size` (int) - The size, in megabytes, of the hard disk to create
    76    for the VM. By default, this is 40000 (40 GB).
    77  
    78  * `floppy_files` (array of strings) - A list of files to put onto a floppy
    79    disk that is attached when the VM is booted for the first time. This is
    80    most useful for unattended Windows installs, which look for an
    81    `Autounattend.xml` file on removable media. By default no floppy will
    82    be attached. The files listed in this configuration will all be put
    83    into the root directory of the floppy disk; sub-directories are not supported.
    84  
    85  * `guest_additions_path` (string) - The path on the guest virtual machine
    86    where the VirtualBox guest additions ISO will be uploaded. By default this
    87    is "VBoxGuestAdditions.iso" which should upload into the login directory
    88    of the user. This is a [configuration template](/docs/templates/configuration-templates.html)
    89    where the `Version` variable is replaced with the VirtualBox version.
    90  
    91  * `guest_additions_sha256` (string) - The SHA256 checksum of the guest
    92    additions ISO that will be uploaded to the guest VM. By default the
    93    checksums will be downloaded from the VirtualBox website, so this only
    94    needs to be set if you want to be explicit about the checksum.
    95  
    96  * `guest_additions_url` (string) - The URL to the guest additions ISO
    97    to upload. This can also be a file URL if the ISO is at a local path.
    98    By default the VirtualBox builder will go and download the proper
    99    guest additions ISO from the internet.
   100  
   101  * `guest_os_type` (string) - The guest OS type being installed. By default
   102    this is "other", but you can get _dramatic_ performance improvements by
   103    setting this to the proper value. To view all available values for this
   104    run `VBoxManage list ostypes`. Setting the correct value hints to VirtualBox
   105    how to optimize the virtual hardware to work best with that operating
   106    system.
   107  
   108  * `headless` (bool) - Packer defaults to building VirtualBox
   109    virtual machines by launching a GUI that shows the console of the
   110    machine being built. When this value is set to true, the machine will
   111    start without a console.
   112  
   113  * `http_directory` (string) - Path to a directory to serve using an HTTP
   114    server. The files in this directory will be available over HTTP that will
   115    be requestable from the virtual machine. This is useful for hosting
   116    kickstart files and so on. By default this is "", which means no HTTP
   117    server will be started. The address and port of the HTTP server will be
   118    available as variables in `boot_command`. This is covered in more detail
   119    below.
   120  
   121  * `http_port_min` and `http_port_max` (int) - These are the minimum and
   122    maximum port to use for the HTTP server started to serve the `http_directory`.
   123    Because Packer often runs in parallel, Packer will choose a randomly available
   124    port in this range to run the HTTP server. If you want to force the HTTP
   125    server to be on one port, make this minimum and maximum port the same.
   126    By default the values are 8000 and 9000, respectively.
   127  
   128  * `iso_urls` (array of strings) - Multiple URLs for the ISO to download.
   129    Packer will try these in order. If anything goes wrong attempting to download
   130    or while downloading a single URL, it will move on to the next. All URLs
   131    must point to the same file (same checksum). By default this is empty
   132    and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified.
   133  
   134  * `output_directory` (string) - This is the path to the directory where the
   135    resulting virtual machine will be created. This may be relative or absolute.
   136    If relative, the path is relative to the working directory when `packer`
   137    is executed. This directory must not exist or be empty prior to running the builder.
   138    By default this is "output-BUILDNAME" where "BUILDNAME" is the name
   139    of the build.
   140  
   141  * `shutdown_command` (string) - The command to use to gracefully shut down
   142    the machine once all the provisioning is done. By default this is an empty
   143    string, which tells Packer to just forcefully shut down the machine.
   144  
   145  * `shutdown_timeout` (string) - The amount of time to wait after executing
   146    the `shutdown_command` for the virtual machine to actually shut down.
   147    If it doesn't shut down in this time, it is an error. By default, the timeout
   148    is "5m", or five minutes.
   149  
   150  * `ssh_host_port_min` and `ssh_host_port_max` (uint) - The minimum and
   151    maximum port to use for the SSH port on the host machine which is forwarded
   152    to the SSH port on the guest machine. Because Packer often runs in parallel,
   153    Packer will choose a randomly available port in this range to use as the
   154    host port.
   155  
   156  * `ssh_password` (string) - The password for `ssh_username` to use to
   157    authenticate with SSH. By default this is the empty string.
   158  
   159  * `ssh_port` (int) - The port that SSH will be listening on in the guest
   160    virtual machine. By default this is 22.
   161  
   162  * `ssh_wait_timeout` (string) - The duration to wait for SSH to become
   163    available. By default this is "20m", or 20 minutes. Note that this should
   164    be quite long since the timer begins as soon as the virtual machine is booted.
   165  
   166  * `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
   167    execute in order to further customize the virtual machine being created.
   168    The value of this is an array of commands to execute. The commands are executed
   169    in the order defined in the template. For each command, the command is
   170    defined itself as an array of strings, where each string represents a single
   171    argument on the command-line to `VBoxManage` (but excluding `VBoxManage`
   172    itself). Each arg is treated as a [configuration template](/docs/templates/configuration-templates.html),
   173    where the `Name` variable is replaced with the VM name. More details on how
   174    to use `VBoxManage` are below.
   175  
   176  * `virtualbox_version_file` (string) - The path within the virtual machine
   177    to upload a file that contains the VirtualBox version that was used to
   178    create the machine. This information can be useful for provisioning.
   179    By default this is ".vbox_version", which will generally upload it into
   180    the home directory.
   181  
   182  * `vm_name` (string) - This is the name of the VMX file for the new virtual
   183    machine, without the file extension. By default this is "packer-BUILDNAME",
   184    where "BUILDNAME" is the name of the build.
   185  
   186  ## Boot Command
   187  
   188  The `boot_command` configuration is very important: it specifies the keys
   189  to type when the virtual machine is first booted in order to start the
   190  OS installer. This command is typed after `boot_wait`, which gives the
   191  virtual machine some time to actually load the ISO.
   192  
   193  As documented above, the `boot_command` is an array of strings. The
   194  strings are all typed in sequence. It is an array only to improve readability
   195  within the template.
   196  
   197  The boot command is "typed" character for character over a VNC connection
   198  to the machine, simulating a human actually typing the keyboard. There are
   199  a set of special keys available. If these are in your boot command, they
   200  will be replaced by the proper key:
   201  
   202  * `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress.
   203  
   204  * `<esc>` - Simulates pressing the escape key.
   205  
   206  * `<tab>` - Simulates pressing the tab key.
   207  
   208  * `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before sending any additional keys. This
   209    is useful if you have to generally wait for the UI to update before typing more.
   210  
   211  In addition to the special keys, each command to type is treated as a
   212  [configuration template](/docs/templates/configuration-templates.html).
   213  The available variables are:
   214  
   215  * `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server
   216    that is started serving the directory specified by the `http_directory`
   217    configuration parameter. If `http_directory` isn't specified, these will
   218    be blank!
   219  
   220  Example boot command. This is actually a working boot command used to start
   221  an Ubuntu 12.04 installer:
   222  
   223  <pre class="prettyprint">
   224  [
   225    "&lt;esc&gt;&lt;esc&gt;&lt;enter&gt;&lt;wait&gt;",
   226    "/install/vmlinuz noapic ",
   227    "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
   228    "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
   229    "hostname={{ .Name }} ",
   230    "fb=false debconf/frontend=noninteractive ",
   231    "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
   232    "keyboard-configuration/variant=USA console-setup/ask_detect=false ",
   233    "initrd=/install/initrd.gz -- &lt;enter&gt;"
   234  ]
   235  </pre>
   236  
   237  ## Guest Additions
   238  
   239  Packer will automatically download the proper guest additions for the
   240  version of VirtualBox that is running and upload those guest additions into
   241  the virtual machine so that provisioners can easily install them.
   242  
   243  Packer downloads the guest additions from the official VirtualBox website,
   244  and verifies the file with the official checksums released by VirtualBox.
   245  
   246  After the virtual machine is up and the operating system is installed,
   247  Packer uploads the guest additions into the virtual machine. The path where
   248  they are uploaded is controllable by `guest_additions_path`, and defaults
   249  to "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the
   250  home directory of the SSH user.
   251  
   252  ## VBoxManage Commands
   253  
   254  In order to perform extra customization of the virtual machine, a template
   255  can define extra calls to `VBoxMangage` to perform. [VBoxManage](http://www.virtualbox.org/manual/ch08.html)
   256  is the command-line interface to VirtualBox where you can completely control
   257  VirtualBox. It can be used to do things such as set RAM, CPUs, etc.
   258  
   259  Extra VBoxManage commands are defined in the template in the `vboxmanage` section.
   260  An example is shown below that sets the memory and number of CPUs within the
   261  virtual machine:
   262  
   263  <pre class="prettyprint">
   264  {
   265    "vboxmanage": [
   266      ["modifyvm", "{{.Name}}", "--memory", "1024"],
   267      ["modifyvm", "{{.Name}}", "--cpus", "2"]
   268    ]
   269  }
   270  </pre>
   271  
   272  The value of `vboxmanage` is an array of commands to execute. These commands
   273  are executed in the order defined. So in the above example, the memory will be
   274  set followed by the CPUs.
   275  
   276  Each command itself is an array of strings, where each string is an argument
   277  to `VBoxManage`. Each argument is treated as a
   278  [configuration template](/docs/templates/configuration-templates.html).
   279  The only available variable is `Name` which is replaced with the unique
   280  name of the VM, which is required for many VBoxManage calls.