github.com/supr/packer@v0.3.10-0.20131015195147-7b09e24ac3c1/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.3-server-amd64.iso",
    28    "iso_checksum": "2cbe868812a871242cdcdd8f2fd6feb9",
    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", "sha256", or "sha512" 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  * `format` (string) - Either "ovf" or "ova", this specifies the output
    86    format of the exported virtual machine. This defaults to "ovf".
    87  
    88  * `guest_additions_attach` (bool) - If this is true (defaults to "false"),
    89    the guest additions ISO will be attached to the virtual machine as a CD
    90    rather than uploaded as a raw ISO.
    91  
    92  * `guest_additions_path` (string) - The path on the guest virtual machine
    93    where the VirtualBox guest additions ISO will be uploaded. By default this
    94    is "VBoxGuestAdditions.iso" which should upload into the login directory
    95    of the user. This is a [configuration template](/docs/templates/configuration-templates.html)
    96    where the `Version` variable is replaced with the VirtualBox version.
    97  
    98  * `guest_additions_sha256` (string) - The SHA256 checksum of the guest
    99    additions ISO that will be uploaded to the guest VM. By default the
   100    checksums will be downloaded from the VirtualBox website, so this only
   101    needs to be set if you want to be explicit about the checksum.
   102  
   103  * `guest_additions_url` (string) - The URL to the guest additions ISO
   104    to upload. This can also be a file URL if the ISO is at a local path.
   105    By default the VirtualBox builder will go and download the proper
   106    guest additions ISO from the internet.
   107  
   108  * `guest_os_type` (string) - The guest OS type being installed. By default
   109    this is "other", but you can get _dramatic_ performance improvements by
   110    setting this to the proper value. To view all available values for this
   111    run `VBoxManage list ostypes`. Setting the correct value hints to VirtualBox
   112    how to optimize the virtual hardware to work best with that operating
   113    system.
   114  
   115  * `hard_drive_interface` (string) - The type of controller that the primary
   116    hard drive is attached to, defaults to "ide".  When set to "sata", the
   117    drive is attached to an AHCI SATA controller.
   118  
   119  * `headless` (bool) - Packer defaults to building VirtualBox
   120    virtual machines by launching a GUI that shows the console of the
   121    machine being built. When this value is set to true, the machine will
   122    start without a console.
   123  
   124  * `http_directory` (string) - Path to a directory to serve using an HTTP
   125    server. The files in this directory will be available over HTTP that will
   126    be requestable from the virtual machine. This is useful for hosting
   127    kickstart files and so on. By default this is "", which means no HTTP
   128    server will be started. The address and port of the HTTP server will be
   129    available as variables in `boot_command`. This is covered in more detail
   130    below.
   131  
   132  * `http_port_min` and `http_port_max` (int) - These are the minimum and
   133    maximum port to use for the HTTP server started to serve the `http_directory`.
   134    Because Packer often runs in parallel, Packer will choose a randomly available
   135    port in this range to run the HTTP server. If you want to force the HTTP
   136    server to be on one port, make this minimum and maximum port the same.
   137    By default the values are 8000 and 9000, respectively.
   138  
   139  * `iso_urls` (array of strings) - Multiple URLs for the ISO to download.
   140    Packer will try these in order. If anything goes wrong attempting to download
   141    or while downloading a single URL, it will move on to the next. All URLs
   142    must point to the same file (same checksum). By default this is empty
   143    and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified.
   144  
   145  * `output_directory` (string) - This is the path to the directory where the
   146    resulting virtual machine will be created. This may be relative or absolute.
   147    If relative, the path is relative to the working directory when `packer`
   148    is executed. This directory must not exist or be empty prior to running the builder.
   149    By default this is "output-BUILDNAME" where "BUILDNAME" is the name
   150    of the build.
   151  
   152  * `shutdown_command` (string) - The command to use to gracefully shut down
   153    the machine once all the provisioning is done. By default this is an empty
   154    string, which tells Packer to just forcefully shut down the machine.
   155  
   156  * `shutdown_timeout` (string) - The amount of time to wait after executing
   157    the `shutdown_command` for the virtual machine to actually shut down.
   158    If it doesn't shut down in this time, it is an error. By default, the timeout
   159    is "5m", or five minutes.
   160  
   161  * `ssh_host_port_min` and `ssh_host_port_max` (uint) - The minimum and
   162    maximum port to use for the SSH port on the host machine which is forwarded
   163    to the SSH port on the guest machine. Because Packer often runs in parallel,
   164    Packer will choose a randomly available port in this range to use as the
   165    host port.
   166  
   167  * `ssh_key_path` (string) - Path to a private key to use for authenticating
   168    with SSH. By default this is not set (key-based auth won't be used).
   169    The associated public key is expected to already be configured on the
   170    VM being prepared by some other process (kickstart, etc.).
   171  
   172  * `ssh_password` (string) - The password for `ssh_username` to use to
   173    authenticate with SSH. By default this is the empty string.
   174  
   175  * `ssh_port` (int) - The port that SSH will be listening on in the guest
   176    virtual machine. By default this is 22.
   177  
   178  * `ssh_wait_timeout` (string) - The duration to wait for SSH to become
   179    available. By default this is "20m", or 20 minutes. Note that this should
   180    be quite long since the timer begins as soon as the virtual machine is booted.
   181  
   182  * `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
   183    execute in order to further customize the virtual machine being created.
   184    The value of this is an array of commands to execute. The commands are executed
   185    in the order defined in the template. For each command, the command is
   186    defined itself as an array of strings, where each string represents a single
   187    argument on the command-line to `VBoxManage` (but excluding `VBoxManage`
   188    itself). Each arg is treated as a [configuration template](/docs/templates/configuration-templates.html),
   189    where the `Name` variable is replaced with the VM name. More details on how
   190    to use `VBoxManage` are below.
   191  
   192  * `virtualbox_version_file` (string) - The path within the virtual machine
   193    to upload a file that contains the VirtualBox version that was used to
   194    create the machine. This information can be useful for provisioning.
   195    By default this is ".vbox_version", which will generally upload it into
   196    the home directory.
   197  
   198  * `vm_name` (string) - This is the name of the OVF file for the new virtual
   199    machine, without the file extension. By default this is "packer-BUILDNAME",
   200    where "BUILDNAME" is the name of the build.
   201  
   202  ## Boot Command
   203  
   204  The `boot_command` configuration is very important: it specifies the keys
   205  to type when the virtual machine is first booted in order to start the
   206  OS installer. This command is typed after `boot_wait`, which gives the
   207  virtual machine some time to actually load the ISO.
   208  
   209  As documented above, the `boot_command` is an array of strings. The
   210  strings are all typed in sequence. It is an array only to improve readability
   211  within the template.
   212  
   213  The boot command is "typed" character for character over a VNC connection
   214  to the machine, simulating a human actually typing the keyboard. There are
   215  a set of special keys available. If these are in your boot command, they
   216  will be replaced by the proper key:
   217  
   218  * `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress.
   219  
   220  * `<esc>` - Simulates pressing the escape key.
   221  
   222  * `<tab>` - Simulates pressing the tab key.
   223  
   224  * `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before sending any additional keys. This
   225    is useful if you have to generally wait for the UI to update before typing more.
   226  
   227  In addition to the special keys, each command to type is treated as a
   228  [configuration template](/docs/templates/configuration-templates.html).
   229  The available variables are:
   230  
   231  * `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server
   232    that is started serving the directory specified by the `http_directory`
   233    configuration parameter. If `http_directory` isn't specified, these will
   234    be blank!
   235  
   236  Example boot command. This is actually a working boot command used to start
   237  an Ubuntu 12.04 installer:
   238  
   239  <pre class="prettyprint">
   240  [
   241    "&lt;esc&gt;&lt;esc&gt;&lt;enter&gt;&lt;wait&gt;",
   242    "/install/vmlinuz noapic ",
   243    "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
   244    "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
   245    "hostname={{ .Name }} ",
   246    "fb=false debconf/frontend=noninteractive ",
   247    "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
   248    "keyboard-configuration/variant=USA console-setup/ask_detect=false ",
   249    "initrd=/install/initrd.gz -- &lt;enter&gt;"
   250  ]
   251  </pre>
   252  
   253  ## Guest Additions
   254  
   255  Packer will automatically download the proper guest additions for the
   256  version of VirtualBox that is running and upload those guest additions into
   257  the virtual machine so that provisioners can easily install them.
   258  
   259  Packer downloads the guest additions from the official VirtualBox website,
   260  and verifies the file with the official checksums released by VirtualBox.
   261  
   262  After the virtual machine is up and the operating system is installed,
   263  Packer uploads the guest additions into the virtual machine. The path where
   264  they are uploaded is controllable by `guest_additions_path`, and defaults
   265  to "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the
   266  home directory of the SSH user.
   267  
   268  ## VBoxManage Commands
   269  
   270  In order to perform extra customization of the virtual machine, a template
   271  can define extra calls to `VBoxMangage` to perform. [VBoxManage](http://www.virtualbox.org/manual/ch08.html)
   272  is the command-line interface to VirtualBox where you can completely control
   273  VirtualBox. It can be used to do things such as set RAM, CPUs, etc.
   274  
   275  Extra VBoxManage commands are defined in the template in the `vboxmanage` section.
   276  An example is shown below that sets the memory and number of CPUs within the
   277  virtual machine:
   278  
   279  <pre class="prettyprint">
   280  {
   281    "vboxmanage": [
   282      ["modifyvm", "{{.Name}}", "--memory", "1024"],
   283      ["modifyvm", "{{.Name}}", "--cpus", "2"]
   284    ]
   285  }
   286  </pre>
   287  
   288  The value of `vboxmanage` is an array of commands to execute. These commands
   289  are executed in the order defined. So in the above example, the memory will be
   290  set followed by the CPUs.
   291  
   292  Each command itself is an array of strings, where each string is an argument
   293  to `VBoxManage`. Each argument is treated as a
   294  [configuration template](/docs/templates/configuration-templates.html).
   295  The only available variable is `Name` which is replaced with the unique
   296  name of the VM, which is required for many VBoxManage calls.