github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/website/source/docs/builders/virtualbox-iso.html.markdown (about)

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