github.com/kimor79/packer@v0.8.7-0.20151221212622-d507b18eb4cf/website/source/docs/builders/virtualbox-iso.html.markdown (about)

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