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

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