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

     1  ---
     2  layout: "docs"
     3  page_title: "VMware Builder from ISO"
     4  ---
     5  
     6  # VMware Builder (from ISO)
     7  
     8  Type: `vmware-iso`
     9  
    10  This VMware builder is able to create VMware virtual machines from an
    11  ISO file as a source. It currently
    12  supports building virtual machines on hosts running
    13  [VMware Fusion](http://www.vmware.com/products/fusion/overview.html) for OS X,
    14  [VMware Workstation](http://www.vmware.com/products/workstation/overview.html)
    15  for Linux and Windows, and
    16  [VMware Player](http://www.vmware.com/products/player/) on Linux. It can
    17  also build machines directly on
    18  [VMware vSphere Hypervisor](http://www.vmware.com/products/vsphere-hypervisor/)
    19  using SSH as opposed to the vSphere API.
    20  
    21  The builder builds a virtual machine by creating a new virtual machine
    22  from scratch, booting it, installing an OS, provisioning software within
    23  the OS, then shutting it down. The result of the VMware builder is a directory
    24  containing all the files necessary to run the virtual machine.
    25  
    26  ## Basic Example
    27  
    28  Here is a basic example. This example is not functional. It will start the
    29  OS installer but then fail because we don't provide the preseed file for
    30  Ubuntu to self-install. Still, the example serves to show the basic configuration:
    31  
    32  <pre class="prettyprint">
    33  {
    34    "type": "vmware-iso",
    35    "iso_url": "http://old-releases.ubuntu.com/releases/precise/ubuntu-12.04.2-server-amd64.iso",
    36    "iso_checksum": "af5f788aee1b32c4b2634734309cc9e9",
    37    "iso_checksum_type": "md5",
    38    "ssh_username": "packer",
    39    "ssh_wait_timeout": "30s",
    40    "shutdown_command": "shutdown -P now"
    41  }
    42  </pre>
    43  
    44  ## Configuration Reference
    45  
    46  There are many configuration options available for the VMware 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  Required:
    51  
    52  * `iso_checksum` (string) - The checksum for the OS ISO file. Because ISO
    53    files are so large, this is required and Packer will verify it prior
    54    to booting a virtual machine with the ISO attached. The type of the
    55    checksum is specified with `iso_checksum_type`, documented below.
    56  
    57  * `iso_checksum_type` (string) - The type of the checksum specified in
    58    `iso_checksum`. Valid values are "none", "md5", "sha1", "sha256", or
    59    "sha512" currently. While "none" will skip checksumming, this is not
    60    recommended since ISO files are generally large and corruption does happen
    61    from time to time.
    62  
    63  * `iso_url` (string) - A URL to the ISO containing the installation image.
    64    This URL can be either an HTTP URL or a file URL (or path to a file).
    65    If this is an HTTP URL, Packer will download it and cache it between
    66    runs.
    67  
    68  * `ssh_username` (string) - The username to use to SSH into the machine
    69    once the OS is installed.
    70  
    71  Optional:
    72  
    73  * `boot_command` (array of strings) - This is an array of commands to type
    74    when the virtual machine is firsted booted. The goal of these commands should
    75    be to type just enough to initialize the operating system installer. Special
    76    keys can be typed as well, and are covered in the section below on the boot
    77    command. If this is not specified, it is assumed the installer will start
    78    itself.
    79  
    80  * `boot_wait` (string) - The time to wait after booting the initial virtual
    81    machine before typing the `boot_command`. The value of this should be
    82    a duration. Examples are "5s" and "1m30s" which will cause Packer to wait
    83    five seconds and one minute 30 seconds, respectively. If this isn't specified,
    84    the default is 10 seconds.
    85  
    86  * `disk_size` (int) - The size of the hard disk for the VM in megabytes.
    87    The builder uses expandable, not fixed-size virtual hard disks, so the
    88    actual file representing the disk will not use the full size unless it is full.
    89    By default this is set to 40,000 (40 GB).
    90  
    91  * `disk_type_id` (string) - The type of VMware virtual disk to create.
    92    The default is "1", which corresponds to a growable virtual disk split in
    93    2GB files.  This option is for advanced usage, modify only if you
    94    know what you're doing.  For more information, please consult the
    95    [Virtual Disk Manager User's Guide](http://www.vmware.com/pdf/VirtualDiskManager.pdf)
    96    for desktop VMware clients. For ESXi, refer to the proper ESXi documentation.
    97  
    98  * `floppy_files` (array of strings) - A list of files to put onto a floppy
    99    disk that is attached when the VM is booted for the first time. This is
   100    most useful for unattended Windows installs, which look for an
   101    `Autounattend.xml` file on removable media. By default no floppy will
   102    be attached. The files listed in this configuration will all be put
   103    into the root directory of the floppy disk; sub-directories are not supported.
   104  
   105  * `fusion_app_path` (string) - Path to "VMware Fusion.app". By default this
   106    is "/Applications/VMware Fusion.app" but this setting allows you to
   107    customize this.
   108  
   109  * `guest_os_type` (string) - The guest OS type being installed. This will be
   110    set in the VMware VMX. By default this is "other". By specifying a more specific
   111    OS type, VMware may perform some optimizations or virtual hardware changes
   112    to better support the operating system running in the virtual machine.
   113  
   114  * `headless` (bool) - Packer defaults to building VMware
   115    virtual machines by launching a GUI that shows the console of the
   116    machine being built. When this value is set to true, the machine will
   117    start without a console. For VMware machines, Packer will output VNC
   118    connection information in case you need to connect to the console to
   119    debug the build process.
   120  
   121  * `http_directory` (string) - Path to a directory to serve using an HTTP
   122    server. The files in this directory will be available over HTTP that will
   123    be requestable from the virtual machine. This is useful for hosting
   124    kickstart files and so on. By default this is "", which means no HTTP
   125    server will be started. The address and port of the HTTP server will be
   126    available as variables in `boot_command`. This is covered in more detail
   127    below.
   128  
   129  * `http_port_min` and `http_port_max` (int) - These are the minimum and
   130    maximum port to use for the HTTP server started to serve the `http_directory`.
   131    Because Packer often runs in parallel, Packer will choose a randomly available
   132    port in this range to run the HTTP server. If you want to force the HTTP
   133    server to be on one port, make this minimum and maximum port the same.
   134    By default the values are 8000 and 9000, respectively.
   135  
   136  * `iso_urls` (array of strings) - Multiple URLs for the ISO to download.
   137    Packer will try these in order. If anything goes wrong attempting to download
   138    or while downloading a single URL, it will move on to the next. All URLs
   139    must point to the same file (same checksum). By default this is empty
   140    and `iso_url` is used. Only one of `iso_url` or `iso_urls` can be specified.
   141  
   142  * `output_directory` (string) - This is the path to the directory where the
   143    resulting virtual machine will be created. This may be relative or absolute.
   144    If relative, the path is relative to the working directory when `packer`
   145    is executed. This directory must not exist or be empty prior to running the builder.
   146    By default this is "output-BUILDNAME" where "BUILDNAME" is the name
   147    of the build.
   148  
   149  * `remote_type` (string) - The type of remote machine that will be used to
   150    build this VM rather than a local desktop product. The only value accepted
   151    for this currently is "esx5". If this is not set, a desktop product will be
   152    used. By default, this is not set.
   153  
   154  * `remote_datastore` (string) - The path to the datastore where the resulting
   155    VM will be stored when it is built on the remote machine. By default this
   156    is "datastore1". This only has an effect if `remote_type` is enabled.
   157  
   158  * `remote_host` (string) - The host of the remote machine used for access.
   159    This is only required if `remote_type` is enabled.
   160  
   161  * `remote_password` (string) - The SSH password for the user used to
   162    access the remote machine. By default this is empty. This only has an
   163    effect if `remote_type` is enabled.
   164  
   165  * `remote_username` (string) - The username for the SSH user that will access
   166    the remote machine. This is required if `remote_type` is enabled.
   167  
   168  * `skip_compaction` (bool) -  VMware-created disks are defragmented
   169    and compacted at the end of the build process using `vmware-vdiskmanager`.
   170    In certain rare cases, this might actually end up making the resulting disks
   171    slightly larger. If you find this to be the case, you can disable compaction
   172    using this configuration value.
   173  
   174  * `shutdown_command` (string) - The command to use to gracefully shut down
   175    the machine once all the provisioning is done. By default this is an empty
   176    string, which tells Packer to just forcefully shut down the machine.
   177  
   178  * `shutdown_timeout` (string) - The amount of time to wait after executing
   179    the `shutdown_command` for the virtual machine to actually shut down.
   180    If it doesn't shut down in this time, it is an error. By default, the timeout
   181    is "5m", or five minutes.
   182  
   183  * `ssh_key_path` (string) - Path to a private key to use for authenticating
   184    with SSH. By default this is not set (key-based auth won't be used).
   185    The associated public key is expected to already be configured on the
   186    VM being prepared by some other process (kickstart, etc.).
   187  
   188  * `ssh_password` (string) - The password for `ssh_username` to use to
   189    authenticate with SSH. By default this is the empty string.
   190  
   191  * `ssh_port` (int) - The port that SSH will listen on within the virtual
   192    machine. By default this is 22.
   193  
   194  * `ssh_skip_request_pty` (bool) - If true, a pty will not be requested as
   195    part of the SSH connection. By default, this is "false", so a pty
   196    _will_ be requested.
   197  
   198  * `ssh_wait_timeout` (string) - The duration to wait for SSH to become
   199    available. By default this is "20m", or 20 minutes. Note that this should
   200    be quite long since the timer begins as soon as the virtual machine is booted.
   201  
   202  * `tools_upload_flavor` (string) - The flavor of the VMware Tools ISO to
   203    upload into the VM. Valid values are "darwin", "linux", and "windows".
   204    By default, this is empty, which means VMware tools won't be uploaded.
   205  
   206  * `tools_upload_path` (string) - The path in the VM to upload the VMware
   207    tools. This only takes effect if `tools_upload_flavor` is non-empty.
   208    This is a [configuration template](/docs/templates/configuration-templates.html)
   209    that has a single valid variable: `Flavor`, which will be the value of
   210    `tools_upload_flavor`. By default the upload path is set to
   211    `{{.Flavor}}.iso`.
   212  
   213  * `vm_name` (string) - This is the name of the VMX file for the new virtual
   214    machine, without the file extension. By default this is "packer-BUILDNAME",
   215    where "BUILDNAME" is the name of the build.
   216  
   217  * `vmdk_name` (string) - The filename of the virtual disk that'll be created,
   218    without the extension. This defaults to "packer".
   219  
   220  * `vmx_data` (object, string keys and string values) - Arbitrary key/values
   221    to enter into the virtual machine VMX file. This is for advanced users
   222    who want to set properties such as memory, CPU, etc.
   223  
   224  * `vnc_port_min` and `vnc_port_max` (int) - The minimum and maximum port to
   225    use for VNC access to the virtual machine. The builder uses VNC to type
   226    the initial `boot_command`. Because Packer generally runs in parallel, Packer
   227    uses a randomly chosen port in this range that appears available. By default
   228    this is 5900 to 6000. The minimum and maximum ports are inclusive.
   229  
   230  * `vmx_template_path` (string) - Path to a
   231    [configuration template](/docs/templates/configuration-templates.html) that
   232    defines the contents of the virtual machine VMX file for VMware. This is
   233    for **advanced users only** as this can render the virtual machine
   234    non-functional. See below for more information. For basic VMX modifications,
   235    try `vmx_data` first.
   236  
   237  ## Boot Command
   238  
   239  The `boot_command` configuration is very important: it specifies the keys
   240  to type when the virtual machine is first booted in order to start the
   241  OS installer. This command is typed after `boot_wait`, which gives the
   242  virtual machine some time to actually load the ISO.
   243  
   244  As documented above, the `boot_command` is an array of strings. The
   245  strings are all typed in sequence. It is an array only to improve readability
   246  within the template.
   247  
   248  The boot command is "typed" character for character over a VNC connection
   249  to the machine, simulating a human actually typing the keyboard. There are
   250  a set of special keys available. If these are in your boot command, they
   251  will be replaced by the proper key:
   252  
   253  * `<enter>` and `<return>` - Simulates an actual "enter" or "return" keypress.
   254  
   255  * `<esc>` - Simulates pressing the escape key.
   256  
   257  * `<tab>` - Simulates pressing the tab key.
   258  
   259  * `<wait>` `<wait5>` `<wait10>` - Adds a 1, 5 or 10 second pause before sending any additional keys. This
   260    is useful if you have to generally wait for the UI to update before typing more.
   261  
   262  In addition to the special keys, each command to type is treated as a
   263  [configuration template](/docs/templates/configuration-templates.html).
   264  The available variables are:
   265  
   266  * `HTTPIP` and `HTTPPort` - The IP and port, respectively of an HTTP server
   267    that is started serving the directory specified by the `http_directory`
   268    configuration parameter. If `http_directory` isn't specified, these will
   269    be blank!
   270  
   271  Example boot command. This is actually a working boot command used to start
   272  an Ubuntu 12.04 installer:
   273  
   274  <pre class="prettyprint">
   275  [
   276    "&lt;esc&gt;&lt;esc&gt;&lt;enter&gt;&lt;wait&gt;",
   277    "/install/vmlinuz noapic ",
   278    "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",
   279    "debian-installer=en_US auto locale=en_US kbd-chooser/method=us ",
   280    "hostname={{ .Name }} ",
   281    "fb=false debconf/frontend=noninteractive ",
   282    "keyboard-configuration/modelcode=SKIP keyboard-configuration/layout=USA ",
   283    "keyboard-configuration/variant=USA console-setup/ask_detect=false ",
   284    "initrd=/install/initrd.gz -- &lt;enter&gt;"
   285  ]
   286  </pre>
   287  
   288  ## VMX Template
   289  
   290  The heart of a VMware machine is the "vmx" file. This contains all the
   291  virtual hardware metadata necessary for the VM to function. Packer by default
   292  uses a [safe, flexible VMX file](https://github.com/mitchellh/packer/blob/20541a7eda085aa5cf35bfed5069592ca49d106e/builder/vmware/step_create_vmx.go#L84).
   293  But for advanced users, this template can be customized. This allows
   294  Packer to build virtual machines of effectively any guest operating system
   295  type.
   296  
   297  <div class="alert alert-block alert-warn">
   298  <p>
   299  <strong>This is an advanced feature.</strong> Modifying the VMX template
   300  can easily cause your virtual machine to not boot properly. Please only
   301  modify the template if you know what you're doing.
   302  </p>
   303  </div>
   304  
   305  Within the template, a handful of variables are available so that your
   306  template can continue working with the rest of the Packer machinery. Using
   307  these variables isn't required, however.
   308  
   309  * `Name` - The name of the virtual machine.
   310  * `GuestOS` - The VMware-valid guest OS type.
   311  * `DiskName` - The filename (without the suffix) of the main virtual disk.
   312  * `ISOPath` - The path to the ISO to use for the OS installation.
   313  
   314  ## Building on a Remote vSphere Hypervisor
   315  
   316  In addition to using the desktop products of VMware locally to build
   317  virtual machines, Packer can use a remote VMware Hypervisor to build
   318  the virtual machine.
   319  
   320  When using a remote VMware Hypervisor, the builder still downloads the
   321  ISO and various files locally, and uploads these to the remote machine.
   322  Packer currently uses SSH to communicate to the ESXi machine rather than
   323  the vSphere API. At some point, the vSphere API may be used.
   324  
   325  To use a remote VMware vSphere Hypervisor to build your virtual machine,
   326  fill in the required `remote_*` configurations:
   327  
   328  * `remote_type` - This must be set to "esx5".
   329  
   330  * `remote_host` - The host of the remote machine.
   331  
   332  Additionally, there are some optional configurations that you'll likely
   333  have to modify as well:
   334  
   335  * `remote_datastore` - The path to the datastore where the VM will be
   336    stored on the ESXi machine.
   337  
   338  * `remote_username` - The SSH username used to access the remote machine.
   339  
   340  * `remote_password` - The SSH password for access to the remote machine.