github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/website/source/docs/builders/virtualbox-iso.html.md (about)

     1  ---
     2  description: |
     3      The VirtualBox Packer builder is able to create VirtualBox virtual machines
     4      and export them in the OVF format, starting from an ISO image.
     5  layout: docs
     6  page_title: 'VirtualBox ISO - Builders'
     7  sidebar_current: 'docs-builders-virtualbox-iso'
     8  ---
     9  
    10  # VirtualBox Builder (from an ISO)
    11  
    12  Type: `virtualbox-iso`
    13  
    14  The VirtualBox Packer builder is able to create
    15  [VirtualBox](https://www.virtualbox.org/) virtual machines and export them in
    16  the OVF format, starting from an ISO image.
    17  
    18  The builder builds a virtual machine by creating a new virtual machine from
    19  scratch, booting it, installing an OS, provisioning software within the OS, then
    20  shutting it down. The result of the VirtualBox builder is a directory containing
    21  all the files necessary to run the virtual machine portably.
    22  
    23  ## Basic Example
    24  
    25  Here is a basic example. This example is not functional. It will start the OS
    26  installer but then fail because we don't provide the preseed file for Ubuntu to
    27  self-install. Still, the example serves to show the basic configuration:
    28  
    29  ``` json
    30  {
    31    "type": "virtualbox-iso",
    32    "guest_os_type": "Ubuntu_64",
    33    "iso_url": "http://releases.ubuntu.com/12.04/ubuntu-12.04.5-server-amd64.iso",
    34    "iso_checksum": "769474248a3897f4865817446f9a4a53",
    35    "iso_checksum_type": "md5",
    36    "ssh_username": "packer",
    37    "ssh_password": "packer",
    38    "shutdown_command": "echo 'packer' | sudo -S shutdown -P now"
    39  }
    40  ```
    41  
    42  It is important to add a `shutdown_command`. By default Packer halts the virtual
    43  machine and the file system may not be sync'd. Thus, changes made in a
    44  provisioner might not be saved.
    45  
    46  ## Configuration Reference
    47  
    48  There are many configuration options available for the VirtualBox builder. They
    49  are organized below into two categories: required and optional. Within each
    50  category, the available options are alphabetized and described.
    51  
    52  In addition to the options listed here, a
    53  [communicator](/docs/templates/communicator.html) can be configured for this
    54  builder.
    55  
    56  ### Required:
    57  
    58  -   `iso_checksum` (string) - The checksum for the OS ISO file. Because ISO
    59      files are so large, this is required and Packer will verify it prior to
    60      booting a virtual machine with the ISO attached. The type of the checksum is
    61      specified with `iso_checksum_type`, documented below. At least one of
    62      `iso_checksum` and `iso_checksum_url` must be defined. This has precedence
    63      over `iso_checksum_url` type.
    64  
    65  -   `iso_checksum_type` (string) - The type of the checksum specified in
    66      `iso_checksum`. Valid values are "none", "md5", "sha1", "sha256", or
    67      "sha512" currently. While "none" will skip checksumming, this is not
    68      recommended since ISO files are generally large and corruption does happen
    69      from time to time.
    70  
    71  -   `iso_checksum_url` (string) - A URL to a GNU or BSD style checksum file
    72      containing a checksum for the OS ISO file. At least one of `iso_checksum`
    73      and `iso_checksum_url` must be defined. This will be ignored if
    74      `iso_checksum` is non empty.
    75  
    76  -   `iso_url` (string) - A URL to the ISO containing the installation image.
    77      This URL can be either an HTTP URL or a file URL (or path to a file). If
    78      this is an HTTP URL, Packer will download it and cache it between runs.
    79  
    80  ### Optional:
    81  
    82  -   `boot_command` (array of strings) - This is an array of commands to type
    83      when the virtual machine is first booted. The goal of these commands should
    84      be to type just enough to initialize the operating system installer. Special
    85      keys can be typed as well, and are covered in the section below on the
    86      boot command. If this is not specified, it is assumed the installer will
    87      start itself.
    88  
    89  -   `boot_wait` (string) - The time to wait after booting the initial virtual
    90      machine before typing the `boot_command`. The value of this should be
    91      a duration. Examples are "5s" and "1m30s" which will cause Packer to wait
    92      five seconds and one minute 30 seconds, respectively. If this isn't
    93      specified, the default is 10 seconds.
    94  
    95  -   `disk_size` (integer) - The size, in megabytes, of the hard disk to create
    96      for the VM. By default, this is 40000 (about 40 GB).
    97  
    98  -   `export_opts` (array of strings) - Additional options to pass to the
    99      [VBoxManage
   100      export](https://www.virtualbox.org/manual/ch08.html#vboxmanage-export). This
   101      can be useful for passing product information to include in the resulting
   102      appliance file. Packer JSON configuration file example:
   103  
   104      ``` json
   105      {
   106        "type": "virtualbox-iso",
   107        "export_opts":
   108        [
   109          "--manifest",
   110          "--vsys", "0",
   111          "--description", "{{user `vm_description`}}",
   112          "--version", "{{user `vm_version`}}"
   113        ],
   114        "format": "ova",
   115      }
   116      ```
   117  
   118      A VirtualBox [VM
   119      description](https://www.virtualbox.org/manual/ch08.html#idm3756) may
   120      contain arbitrary strings; the GUI interprets HTML formatting. However, the
   121      JSON format does not allow arbitrary newlines within a value. Add a
   122      multi-line description by preparing the string in the shell before the
   123      packer call like this (shell `>` continuation character snipped for easier
   124      copy & paste):
   125  
   126      ``` {.shell}
   127  
   128      vm_description='some
   129      multiline
   130      description'
   131  
   132      vm_version='0.2.0'
   133  
   134      packer build \
   135          -var "vm_description=${vm_description}" \
   136          -var "vm_version=${vm_version}"         \
   137          "packer_conf.json"
   138      ```
   139  
   140  -   `floppy_files` (array of strings) - A list of files to place onto a floppy
   141      disk that is attached when the VM is booted. This is most useful for
   142      unattended Windows installs, which look for an `Autounattend.xml` file on
   143      removable media. By default, no floppy will be attached. All files listed in
   144      this setting get placed into the root directory of the floppy and the floppy
   145      is attached as the first floppy device. Currently, no support exists for
   146      creating sub-directories on the floppy. Wildcard characters (\*, ?,
   147      and \[\]) are allowed. Directory names are also allowed, which will add all
   148      the files found in the directory to the floppy.
   149  
   150  -   `floppy_dirs` (array of strings) - A list of directories to place onto
   151      the floppy disk recursively. This is similar to the `floppy_files` option
   152      except that the directory structure is preserved. This is useful for when
   153      your floppy disk includes drivers or if you just want to organize it's
   154      contents as a hierarchy. Wildcard characters (\*, ?, and \[\]) are allowed.
   155  
   156  -   `format` (string) - Either "ovf" or "ova", this specifies the output format
   157      of the exported virtual machine. This defaults to "ovf".
   158  
   159  -   `guest_additions_mode` (string) - The method by which guest additions are
   160      made available to the guest for installation. Valid options are "upload",
   161      "attach", or "disable". If the mode is "attach" the guest additions ISO will
   162      be attached as a CD device to the virtual machine. If the mode is "upload"
   163      the guest additions ISO will be uploaded to the path specified by
   164      `guest_additions_path`. The default value is "upload". If "disable" is used,
   165      guest additions won't be downloaded, either.
   166  
   167  -   `guest_additions_path` (string) - The path on the guest virtual machine
   168      where the VirtualBox guest additions ISO will be uploaded. By default this
   169      is "VBoxGuestAdditions.iso" which should upload into the login directory of
   170      the user. This is a [configuration
   171      template](/docs/templates/engine.html) where the `Version`
   172      variable is replaced with the VirtualBox version.
   173  
   174  -   `guest_additions_sha256` (string) - The SHA256 checksum of the guest
   175      additions ISO that will be uploaded to the guest VM. By default the
   176      checksums will be downloaded from the VirtualBox website, so this only needs
   177      to be set if you want to be explicit about the checksum.
   178  
   179  -   `guest_additions_url` (string) - The URL to the guest additions ISO
   180      to upload. This can also be a file URL if the ISO is at a local path. By
   181      default, the VirtualBox builder will attempt to find the guest additions ISO
   182      on the local file system. If it is not available locally, the builder will
   183      download the proper guest additions ISO from the internet.
   184  
   185  -   `guest_os_type` (string) - The guest OS type being installed. By default
   186      this is "other", but you can get *dramatic* performance improvements by
   187      setting this to the proper value. To view all available values for this run
   188      `VBoxManage list ostypes`. Setting the correct value hints to VirtualBox how
   189      to optimize the virtual hardware to work best with that operating system.
   190  
   191  -   `hard_drive_interface` (string) - The type of controller that the primary
   192      hard drive is attached to, defaults to "ide". When set to "sata", the drive
   193      is attached to an AHCI SATA controller. When set to "scsi", the drive is
   194      attached to an LsiLogic SCSI controller.
   195  
   196  -   `sata_port_count` (integer) - The number of ports available on any SATA
   197      controller created, defaults to 1. VirtualBox supports up to 30 ports on a
   198      maximum of 1 SATA controller. Increasing this value can be useful if you
   199      want to attach additional drives.
   200  
   201  -   `hard_drive_nonrotational` (boolean) - Forces some guests (i.e. Windows 7+)
   202      to treat disks as SSDs and stops them from performing disk fragmentation.
   203      Also set `hard_drive_Discard` to `true` to enable TRIM support.
   204  
   205  -   `hard_drive_discard` (boolean) - When this value is set to `true`, a VDI
   206      image will be shrunk in response to the trim command from the guest OS.
   207      The size of the cleared area must be at least 1MB. Also set
   208      `hard_drive_nonrotational` to `true` to enable TRIM support.
   209  
   210  -   `headless` (boolean) - Packer defaults to building VirtualBox virtual
   211      machines by launching a GUI that shows the console of the machine
   212      being built. When this value is set to `true`, the machine will start without
   213      a console.
   214  
   215  -   `http_directory` (string) - Path to a directory to serve using an
   216      HTTP server. The files in this directory will be available over HTTP that
   217      will be requestable from the virtual machine. This is useful for hosting
   218      kickstart files and so on. By default this is "", which means no HTTP server
   219      will be started. The address and port of the HTTP server will be available
   220      as variables in `boot_command`. This is covered in more detail below.
   221  
   222  -   `http_port_min` and `http_port_max` (integer) - These are the minimum and
   223      maximum port to use for the HTTP server started to serve the
   224      `http_directory`. Because Packer often runs in parallel, Packer will choose
   225      a randomly available port in this range to run the HTTP server. If you want
   226      to force the HTTP server to be on one port, make this minimum and maximum
   227      port the same. By default the values are 8000 and 9000, respectively.
   228  
   229  -   `iso_interface` (string) - The type of controller that the ISO is attached
   230      to, defaults to "ide". When set to "sata", the drive is attached to an AHCI
   231      SATA controller.
   232  
   233  -   `iso_target_extension` (string) - The extension of the iso file after
   234      download. This defaults to "iso".
   235  
   236  -   `iso_target_path` (string) - The path where the iso should be saved
   237      after download. By default will go in the packer cache, with a hash of the
   238      original filename as its name.
   239  
   240  -   `iso_urls` (array of strings) - Multiple URLs for the ISO to download.
   241      Packer will try these in order. If anything goes wrong attempting to
   242      download or while downloading a single URL, it will move on to the next. All
   243      URLs must point to the same file (same checksum). By default this is empty
   244      and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified.
   245  
   246  -   `keep_registered` (boolean) - Set this to `true` if you would like to keep
   247      the VM registered with virtualbox. Defaults to `false`.
   248  
   249  -   `output_directory` (string) - This is the path to the directory where the
   250      resulting virtual machine will be created. This may be relative or absolute.
   251      If relative, the path is relative to the working directory when `packer`
   252      is executed. This directory must not exist or be empty prior to running
   253      the builder. By default this is "output-BUILDNAME" where "BUILDNAME" is the
   254      name of the build.
   255  
   256  -   `post_shutdown_delay` (string) - The amount of time to wait after shutting
   257      down the virtual machine. If you get the error
   258      `Error removing floppy controller`, you might need to set this to `5m`
   259      or so. By default, the delay is `0s`, or disabled.
   260  
   261  -   `shutdown_command` (string) - The command to use to gracefully shut down the
   262      machine once all the provisioning is done. By default this is an empty
   263      string, which tells Packer to just forcefully shut down the machine unless a
   264      shutdown command takes place inside script so this may safely be omitted. If
   265      one or more scripts require a reboot it is suggested to leave this blank
   266      since reboots may fail and specify the final shutdown command in your
   267      last script.
   268  
   269  -   `shutdown_timeout` (string) - The amount of time to wait after executing the
   270      `shutdown_command` for the virtual machine to actually shut down. If it
   271      doesn't shut down in this time, it is an error. By default, the timeout is
   272      `5m`, or five minutes.
   273  
   274  -   `skip_export` (boolean) - Defaults to `false`. When enabled, Packer will
   275      not export the VM. Useful if the build output is not the resultant image,
   276      but created inside the VM.
   277  
   278  -   `ssh_host_port_min` and `ssh_host_port_max` (integer) - The minimum and
   279      maximum port to use for the SSH port on the host machine which is forwarded
   280      to the SSH port on the guest machine. Because Packer often runs in parallel,
   281      Packer will choose a randomly available port in this range to use as the
   282      host port. By default this is 2222 to 4444.
   283  
   284  -   `ssh_skip_nat_mapping` (boolean) - Defaults to `false`. When enabled, Packer
   285      does not setup forwarded port mapping for SSH requests and uses `ssh_port`
   286      on the host to communicate to the virtual machine
   287  
   288  -   `vboxmanage` (array of array of strings) - Custom `VBoxManage` commands to
   289      execute in order to further customize the virtual machine being created. The
   290      value of this is an array of commands to execute. The commands are executed
   291      in the order defined in the template. For each command, the command is
   292      defined itself as an array of strings, where each string represents a single
   293      argument on the command-line to `VBoxManage` (but excluding
   294      `VBoxManage` itself). Each arg is treated as a [configuration
   295      template](/docs/templates/engine.html), where the `Name`
   296      variable is replaced with the VM name. More details on how to use
   297      `VBoxManage` are below.
   298  
   299  -   `vboxmanage_post` (array of array of strings) - Identical to `vboxmanage`,
   300      except that it is run after the virtual machine is shutdown, and before the
   301      virtual machine is exported.
   302  
   303  -   `virtualbox_version_file` (string) - The path within the virtual machine to
   304      upload a file that contains the VirtualBox version that was used to create
   305      the machine. This information can be useful for provisioning. By default
   306      this is ".vbox\_version", which will generally be upload it into the
   307      home directory. Set to an empty string to skip uploading this file, which
   308      can be useful when using the `none` communicator.
   309  
   310  -   `vm_name` (string) - This is the name of the OVF file for the new virtual
   311      machine, without the file extension. By default this is "packer-BUILDNAME",
   312      where "BUILDNAME" is the name of the build.
   313  
   314  -   `vrdp_bind_address` (string / IP address) - The IP address that should be
   315      binded to for VRDP. By default packer will use 127.0.0.1 for this. If you
   316      wish to bind to all interfaces use 0.0.0.0
   317  
   318  -   `vrdp_port_min` and `vrdp_port_max` (integer) - The minimum and maximum port
   319      to use for VRDP access to the virtual machine. Packer uses a randomly chosen
   320      port in this range that appears available. By default this is 5900 to 6000.
   321      The minimum and maximum ports are inclusive.
   322  
   323  ## Boot Command
   324  
   325  The `boot_command` configuration is very important: it specifies the keys to
   326  type when the virtual machine is first booted in order to start the OS
   327  installer. This command is typed after `boot_wait`, which gives the virtual
   328  machine some time to actually load the ISO.
   329  
   330  As documented above, the `boot_command` is an array of strings. The strings are
   331  all typed in sequence. It is an array only to improve readability within the
   332  template.
   333  
   334  The boot command is "typed" character for character over a VNC connection to the
   335  machine, simulating a human actually typing the keyboard. There are a set of
   336  special keys available. If these are in your boot command, they will be replaced
   337  by the proper key:
   338  
   339  -   `<bs>` - Backspace
   340  
   341  -   `<del>` - Delete
   342  
   343  -   `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress.
   344  
   345  -   `<esc>` - Simulates pressing the escape key.
   346  
   347  -   `<tab>` - Simulates pressing the tab key.
   348  
   349  -   `<f1>` - `<f12>` - Simulates pressing a function key.
   350  
   351  -   `<up>` `<down>` `<left>` `<right>` - Simulates pressing an arrow key.
   352  
   353  -   `<spacebar>` - Simulates pressing the spacebar.
   354  
   355  -   `<insert>` - Simulates pressing the insert key.
   356  
   357  -   `<home>` `<end>` - Simulates pressing the home and end keys.
   358  
   359  -   `<pageUp>` `<pageDown>` - Simulates pressing the page up and page down keys.
   360  
   361  -   `<leftAlt>` `<rightAlt>` - Simulates pressing the alt key.
   362  
   363  -   `<leftCtrl>` `<rightCtrl>` - Simulates pressing the ctrl key.
   364  
   365  -   `<leftShift>` `<rightShift>` - Simulates pressing the shift key.
   366  
   367  -   `<leftAltOn>` `<rightAltOn>` - Simulates pressing and holding the alt key.
   368  
   369  -   `<leftCtrlOn>` `<rightCtrlOn>` - Simulates pressing and holding the
   370      ctrl key.
   371  
   372  -   `<leftShiftOn>` `<rightShiftOn>` - Simulates pressing and holding the
   373      shift key.
   374  
   375  -   `<leftAltOff>` `<rightAltOff>` - Simulates releasing a held alt key.
   376  
   377  -   `<leftCtrlOff>` `<rightCtrlOff>` - Simulates releasing a held ctrl key.
   378  
   379  -   `<leftShiftOff>` `<rightShiftOff>` - Simulates releasing a held shift key.
   380  
   381  -   `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before
   382      sending any additional keys. This is useful if you have to generally wait
   383      for the UI to update before typing more.
   384  
   385  When using modifier keys `ctrl`, `alt`, `shift` ensure that you release them,
   386  otherwise they will be held down until the machine reboots. Use lowercase
   387  characters as well inside modifiers.
   388  
   389  For example: to simulate ctrl+c use `<leftCtrlOn>c<leftCtrlOff>`.
   390  
   391  In addition to the special keys, each command to type is treated as a
   392  [template engine](/docs/templates/engine.html). The
   393  available variables are:
   394  
   395  -   `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server
   396      that is started serving the directory specified by the `http_directory`
   397      configuration parameter. If `http_directory` isn't specified, these will be
   398      blank!
   399  
   400  Example boot command. This is actually a working boot command used to start an
   401  Ubuntu 12.04 installer:
   402  
   403  ``` text
   404  [
   405    "<esc><esc><enter><wait>",
   406    "/install/vmlinuz noapic ",
   407    "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
   408    "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
   409    "hostname={{ .Name }} ",
   410    "fb=false debconf/frontend=noninteractive ",
   411    "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
   412    "keyboard-configuration/variant=USA console-setup/ask_detect=false ",
   413    "initrd=/install/initrd.gz -- <enter>"
   414  ]
   415  ```
   416  
   417  ## Guest Additions
   418  
   419  Packer will automatically download the proper guest additions for the version of
   420  VirtualBox that is running and upload those guest additions into the virtual
   421  machine so that provisioners can easily install them.
   422  
   423  Packer downloads the guest additions from the official VirtualBox website, and
   424  verifies the file with the official checksums released by VirtualBox.
   425  
   426  After the virtual machine is up and the operating system is installed, Packer
   427  uploads the guest additions into the virtual machine. The path where they are
   428  uploaded is controllable by `guest_additions_path`, and defaults to
   429  "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the home
   430  directory of the SSH user.
   431  
   432  ## VBoxManage Commands
   433  
   434  In order to perform extra customization of the virtual machine, a template can
   435  define extra calls to `VBoxManage` to perform.
   436  [VBoxManage](https://www.virtualbox.org/manual/ch08.html) is the command-line
   437  interface to VirtualBox where you can completely control VirtualBox. It can be
   438  used to do things such as set RAM, CPUs, etc.
   439  
   440  Extra VBoxManage commands are defined in the template in the `vboxmanage`
   441  section. An example is shown below that sets the memory and number of CPUs
   442  within the virtual machine:
   443  
   444  ``` json
   445  {
   446    "vboxmanage": [
   447      ["modifyvm", "{{.Name}}", "--memory", "1024"],
   448      ["modifyvm", "{{.Name}}", "--cpus", "2"]
   449    ]
   450  }
   451  ```
   452  
   453  The value of `vboxmanage` is an array of commands to execute. These commands are
   454  executed in the order defined. So in the above example, the memory will be set
   455  followed by the CPUs.
   456  
   457  Each command itself is an array of strings, where each string is an argument to
   458  `VBoxManage`. Each argument is treated as a [configuration
   459  template](/docs/templates/engine.html). The only available
   460  variable is `Name` which is replaced with the unique name of the VM, which is
   461  required for many VBoxManage calls.