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