Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Build VM from ISO file #16

Closed
rszentmihalyi opened this issue Jun 7, 2017 · 36 comments
Closed

Build VM from ISO file #16

rszentmihalyi opened this issue Jun 7, 2017 · 36 comments
Labels

Comments

@rszentmihalyi
Copy link

It would be great if it was possible to use an ISO file as source instead of having to clone a VM (the vmware-iso builder does not support the vSphere API)

@LizaTretyakova-zz
Copy link
Contributor

Hi @rszentmihalyi, thanks for your note and sorry for the delay with the answer!
This is a great feature, and we definitely consider implementing it as soon as we finish all the basic functionality. At the moment, though, our first priority is creating fully operable builder which creates the machine from an existing one. The reason for this decision is that there is no workaround for such task at the moment, while, on the other hand, the workarounds for creating from ISO files exist (yet they are pain, so, again, the feature is definitely important).

@tsugliani
Copy link

I think this feature is very important, as relying on a "template" from which you do not really control the lifecycle, can lead to inconsistent outcomes on the long term if using many different environments.

Or it would require a 2 step build process for templates, which could be pretty bothersome.

That said I really like the full API approach of this builder. (if we could have both, it would be fantastic ;-) )

👍

@mkuzmin
Copy link
Contributor

mkuzmin commented Jun 28, 2017

I totally understand your points. Having a native remote ISO builder is definitely a desired feature. That's just a question of time and priorities.

But actually, 2-step build process is exactly the reason we started this development. Creating VMs from scratch is complicated, but possible. Incremental builds where we can split the work into a hierarchy of layers - this is an unique ability.

@ehaselwanter
Copy link

Is there any suggestion for the baseline? E.g. an example with 'upload this starting image, we keep it fresh'. Any requirements on the base image?

@mkuzmin
Copy link
Contributor

mkuzmin commented Aug 3, 2017

We are still using VMware Player and vmware-iso builder to create base machines, and vsphere post-processor to upload them into vSphere.

THere are two requirements

  1. VMware Guest Tools
  2. SSH server

@qubitrenegade
Copy link

@mkuzmin is there a specific requirement for VMware branded VMtools? We've switched almost entirely to open-vm-tools as that's what VMware recommends.

Thanks!

@mkuzmin
Copy link
Contributor

mkuzmin commented Oct 11, 2017

yes, open-vm-tools work fine. We're also using them.

@taliesins
Copy link

+1 for iso support. Once we have this feature I am willing to champion the Packer pull request. Even if I have to update the docs and get it past @mwhooker

@basictheprogram
Copy link

I believe this fork, https://github.com/martezr/packer-builder-vsphere, has build from .iso but does not have provisioning capabilities. Some work to integrate the .iso build?

@mkuzmin
Copy link
Contributor

mkuzmin commented Feb 2, 2018

Good news, everyone!

We have started developing ISO-builder. Thanks, @xosmig!
A current code in master allows creating new VMs from scratch, customize hardware, attach ISO-images, and generate floppy images. This makes possible a complete automation of Windows installation.

We still need to implement boot_command keystrokes, so Linux and macOS installers can be started.

@tallaxes
Copy link

tallaxes commented Feb 9, 2018

Thank you for implementing this! Any plans to support http server with this? Many other builders (including the stock vmware-iso support http_directory etc.; convenient for serving something like Kickstarter files ...

@mkuzmin
Copy link
Contributor

mkuzmin commented Feb 14, 2018

I've published v2.0-beta1 release.
Please see an example of Windows build in /examples/windows/.

@mkuzmin
Copy link
Contributor

mkuzmin commented Feb 18, 2018

And now we have boot_command, so Linux builds can be automated too.
Please find details in #53, get binaries at v2.0-beta2, and see a minimal Ubuntu template in examples/ubuntu.

@tallaxes I have no plans to implement http_directory - this is a feature suitable for desktop hypervisors, but I don't think it would work reliably with remote builds. Especially under Docker (port forwarding, IP address translation).
Ubuntu installer can access preseed flies on a floppy drive, check out an example by the link above.

@hulbs9nw
Copy link

Thanks for this mkuzmin, it looks really promising. I'm just trying it out however, it doesn't seem to find my host properly. I get the following error - vpshere-iso: error creating vm: resource pool '/DATACENTER/host/HOSTNAME/Resources not found. Can you point me in the right direction?

@mkuzmin
Copy link
Contributor

mkuzmin commented Feb 22, 2018

@hulbs9nw this may be related to clusters. please check workarounds in #38.

@hulbs9nw
Copy link

Thanks for the response. Yes all our hosts are in a cluster so looks like it is related. I tried to specify the cluster in place of the host and a datastore name but I get an error about resolving to multiple hosts. Any other suggestions or is this a bug?

@mkuzmin
Copy link
Contributor

mkuzmin commented Mar 4, 2018

I've published v2.0-beta3 with macOS support (#54).

It's going to be the last pre-release build.

@loxley
Copy link

loxley commented Mar 6, 2018

@mkuzmin FYI, packer-builder-vsphere-clone works fine with clusters. It's just the packer-builder-vsphere-iso that throws this error:

==> Some builds didn't complete successfully and had errors:
--> vsphere-iso: error creating vm: path '/Tools/host/Tools' resolves to multiple hosts

Config:
"datacenter": "Tools",
"host": "Tools"

@ScriptXaaS
Copy link

packer-builder-vsphere-iso validated succesfully, yet during the build throwed the following error:
==> Some builds didn't complete successfully and had errors:
--> vsphere-iso: error creating vm: resource pool '/Datacenter/host/Esxi1/Resources/' not found

JSON:
"datacenter": "Datacenter",
"host": "Esxi1"

MOB shows the path to reosource pool should be: 'Datacenter/hostFolder/childEntry/Resources/' or 'Datacenter/hostFolder/childEntry/Resources/resourcePool' . In contrast, the path to esxi hosts is 'Datacenter/hostFolder/childEntry/host/'

In a complex vSphere implementation, it is likely that multiple datacenters, clusters, and resource pools, etc. are in use. It appears the RCA is due to improper enumeration of the path.

@seanmalloy
Copy link
Contributor

@ScriptXaaS I think is would be useful if you could provide the Packer JSON template you are using that produces this error. Thanks!

@ScriptXaaS
Copy link

ScriptXaaS commented Mar 13, 2018

I have a few additional questions:

  1. In the example it states that floppy files is to be defined as:
    "floppy_files": [
    "{{template_dir}}/preseed.cfg"

Could someone elaborate where is it {template_dir} defined? In the vSphere-iso context, where is the directory to the template for the build? Is it the datastore where the iso file resided? On VM configuration, floppy files has to point to either a physical drive or, a floppy image(flp). The example is pointing directly to a cfg file.

  1. Is there a doc for the parameters' syntax of vsphere-iso supported? It will be nice if it can support numCoresPerSocket parameter

  2. vSphere Tree Structure looks like
    vCenter
    Datacenter
    Cluster
    Esxi1
    Esxi2
    ResourcePool1
    ResourcePool2
    ResourcePool3

Here is the JSON template:
"builders": [
{
"type": "vsphere-iso",

  "vcenter_server": "vCenter.xyz.com",
  "insecure_connection": "true",
  "host": "esxi1.xyz.com",
  "username": "user@xyz.com",
  "password": "xxx",
  "ssh_username": "ssh",
  "ssh_password": "ssh",


  "folder": "folder1",
  "vm_name":  "Ubuntu1604-01",
  "convert_to_template": "false",
  "guest_os_type": "ubuntu64Guest",

  "CPUs": 2,
  "ram": "4096",

  "disk_controller_type": "pvscsi",
  "disk_size": 40,
  "disk_thin_provisioned": true,

  "network": "VM Network",
  "network_card": "VMXNET 3",

  "datastore": "Storage-Cluster1",

  "iso_paths": [
    "[datastore01] ISO/ubuntu-16.04.4-server-amd64.iso"
  ],
        
  "boot_command": [
    "<enter><wait><f6><esc><wait>",
    "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
    "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
    "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
    "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
    "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
    "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
    "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
    "<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
    "<bs><bs><bs>",
    "/install/vmlinuz",
    " initrd=/install/initrd.gz",
    " priority=critical",
    " locale=en_US",
    " file=/media/preseed.cfg",
    "<enter>"
  ],
  "boot_order": "disk,cdrom"
}

]

@seanmalloy
Copy link
Contributor

seanmalloy commented Mar 13, 2018

@ScriptXaaS here is the info on template_dir. This is a feature of Packer and is not specific to this plugin.

https://www.packer.io/docs/templates/engine.html

I have a work in progress pull request #56 to document all the vsphere-iso config options. I'll hopefully be making some additional tweaks to my pull request tonight.

You can view the pretty version of my work in progress docs at the below URL.

https://github.com/KohlsTechnology/packer-builder-vsphere/blob/doc-updates/README.md

@ScriptXaaS
Copy link

@seanmalloy Thanks for updating the doc. Do you know the right syntax for vmx_data?

When adding the following configuration key of vmx_data in the JSON template:
"vmx_data": {
"ethernet0.virtualDev": "vmxnet3"
},

I got the error during validation: Error validating build 'vsphere-iso'. 1 error occured:

  • unknown configuration key: "vmx_data"

@seanmalloy
Copy link
Contributor

@ScriptXaaS I don't think vmx_data is a valid config option. I just searched through source code on the master branch and I do not see any references to it.

@mkuzmin
Copy link
Contributor

mkuzmin commented Mar 14, 2018

I've named this setting to follow UI language, not internals:

 "configuration_parameters": {
        "ich7m.present": "TRUE",
        "smc.present": "TRUE"
      },

But for network adapters there is a dedicated setting:

"network_card": "vmxnet3"

@loxley
Copy link

loxley commented Mar 19, 2018

@mkuzmin : since pull request #61 building images for our setup also works. Thanks!

@ScriptXaaS
Copy link

ScriptXaaS commented Mar 20, 2018

@mkuzmin:
Building from Windows 10 v1709 iso, with the following configuration in the JSON template:
"iso_paths": [
"[datastore1] ISO/en_windows_10_multi-edition_vl_version_1709_updated_dec_2017_x64_dvd_100406172.iso",
"[datastore1] ISO/VMware Tools/10.2.0/windows.iso"
],

Two cd-roms got mounted in the new VM, but cd-rom1 (with Win10 v1709 ISO) is NOT connected. In contrast, cd-rom2 is shown as connected. Deducing the only one cd-rom drive with the following configuration:

"iso_paths": [
"[datastore1] ISO/en_windows_10_multi-edition_vl_version_1709_updated_dec_2017_x64_dvd_100406172.iso"

  ],

The cd-rom still shows NOT connected. It appears cd-rom1 is NOT connected by default. Please fix or even better, give an option to have it connected or not.

@casey-robertson
Copy link

Interesting - I can't reproduce that issue. My config looks the same.

"iso_paths": [
"[lv9_iso] ISOs/en_windows_server_version_1709_x64_dvd_100090904.iso",
"[lv9_iso] ISOs/VMware-Tools-Jan-2018/windows.iso"
],

@sbarthelemy
Copy link

Hello,
I tried the iso builder and it worked for me (on a cluster without DRS, vCenter 5.5) until some point:
I'm in a corporate network where I don't have datastore write permission, hence the builder failed to upload the preseed "floppy" file from the ubuntu example.

Is there way bypass the "datastore write permission" requirement?
Thank you!

@mkuzmin
Copy link
Contributor

mkuzmin commented Mar 21, 2018

Having no datastore file write privilege, how are you uploading ISO files there?
In Linux the floppy is not mandatory. Debian installer allows getting preseed file from external HTTP server by url parameter.
In Windows I don't see other way. but you could create a static flp-image manually, and ask your admins to upload it.

Anyway, I'd try to obtain these privileges - there are many other reasons where direct file access is helpful.

@mkuzmin
Copy link
Contributor

mkuzmin commented Mar 21, 2018

I'm going to close this issue. The feature is now complete, critical bugs are fixed, and we are preparing a release.

Feel free to open separate issues for any your questions and problems.

@mkuzmin mkuzmin closed this as completed Mar 21, 2018
@zenvenki
Copy link

i am trying to create a VM from ISO using the below pluggin

https://github.com/jetbrains-infra/packer-builder-vsphere/releases

i have full administrator permissions on the entire Vcenter and the Datacenter is not nested inside a folder.

Sill when i am running packer build rhel.json

i am getting errors. Attached the error log along with this.

could you please help me on this

Regards
Venki
packer error logs.txt

@VladRassokhin
Copy link
Collaborator

@zenvenki in your log there's Build 'vsphere-iso' errored: error creating vm: folder '/TESTLAB/vm/templates' not found message. Please ensure such folder exists or your packer config is correct.
PS: It would be much simpler if your message contained error from packer log.

@zenvenki
Copy link

hi even if i manually create the folder the error message is the same
please find the json file.

{
"builders": [
{
"type": "vsphere-iso",

  "vcenter_server": "test.test.com",
  "username": "test",
  "password": "test",
  "insecure_connection": "true",
  "host": "10.10.10.1",
  "datacenter": "TESTLAB",
  "vm_name":  "rhel7-packer-test",
  "folder": "templates",
  "convert_to_template": "true",
  "CPUs": "1",
  "RAM": "2048",
  "network": "VLAN214",
  "network_card": "vmxnet3",
  "guest_os_type": "rhel7_64Guest",
  "disk_size": "5",
  "iso_paths": "test/rhel7/rhel-server-7.5-x86_64-dvd.iso",
  "datastore": "testvol00",


  "ssh_username": "packer",
  "ssh_password": "packer"
}

],

"provisioners": [
{
"type": "shell",
"inline": ["ls /"]
}
]
}

@VladRassokhin
Copy link
Collaborator

@zenvenki Please post comment to the issue you've created.
Sorry I missed it initially and answered here.
Let's not spam everyone in issue with updates

@pastaup
Copy link

pastaup commented Jul 9, 2020

@mkuzmin:
Building from Windows 10 v1709 iso, with the following configuration in the JSON template:
"iso_paths": [
"[datastore1] ISO/en_windows_10_multi-edition_vl_version_1709_updated_dec_2017_x64_dvd_100406172.iso",
"[datastore1] ISO/VMware Tools/10.2.0/windows.iso"
],

Two cd-roms got mounted in the new VM, but cd-rom1 (with Win10 v1709 ISO) is NOT connected. In contrast, cd-rom2 is shown as connected. Deducing the only one cd-rom drive with the following configuration:

"iso_paths": [
"[datastore1] ISO/en_windows_10_multi-edition_vl_version_1709_updated_dec_2017_x64_dvd_100406172.iso"

  ],

The cd-rom still shows NOT connected. It appears cd-rom1 is NOT connected by default. Please fix or even better, give an option to have it connected or not.

Late to the party, but I ran into this today.
My isos were located on a datastore, within in a folder called "Packer".
The folder name at some point was changed to "packer", but I failed to update my json files to reference a lowercase p.

Make sure your ISO path is the correct case exactly, when interacting with non-Windows this matters.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests