Skip to content

Instantly share code, notes, and snippets.

@tdewin
Created November 3, 2021 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tdewin/01a1f98239a463437a4dc8e405bd1ce1 to your computer and use it in GitHub Desktop.
Save tdewin/01a1f98239a463437a4dc8e405bd1ce1 to your computer and use it in GitHub Desktop.
Install ubuntu via GOVC in a almost automated way

Automated install

You want to have a fresh copy instead of a template clone? Here you go

Set some variables

set GOVC_INSECURE=true
set GOVC_URL=login@vcenter.fqdn
set GOVC_PASSWORD=youguess
set GOVC_DATASTORE=mydatastore
set GOVC_RESOURCE_POOL=myresourcepool
set GOVC_FOLDER=myvmfolder
set CNNAME=myvm

Create the VM. This assumes the iso "ubuntu-20.04.2-live-server-amd64.iso" in folder "Ubuntu" in datastore "ISO". It will connect to mynet, make sure you have dhcp

govc datastore.mkdir %CNNAME%
govc datastore.disk.create -d=thin -size 50G %CNNAME%/os.vmdk
govc vm.create -c=4 -m=8192 -disk=%CNNAME%/os.vmdk -dump=true -g="ubuntu64Guest" -iso-datastore=ISO -iso=Ubuntu/ubuntu-20.04.2-live-server-amd64.iso -on=false -link=true -net="mynet" -net.adapter=vmxnet3 %CNNAME%

Keystroke magic. Notice windows timeout sucks so ping acts as a sleeper here. http://myurl/mydir/user-data is your config file http://myurl/mydir/meta-data can be just blank file but has to exists

govc vm.power -off %CNNAME%
govc vm.power -on %CNNAME%
ping 127.0.0.1 -n 3 > nul
govc vm.keystrokes -vm %CNNAME% -c KEY_ESC
ping 127.0.0.1 -n 2 > nul
govc vm.keystrokes -vm %CNNAME% -c KEY_ESC
ping 127.0.0.1 -n 2 > nul
govc vm.keystrokes -vm %CNNAME% -c KEY_F6
ping 127.0.0.1 -n 2 > nul
govc vm.keystrokes -vm %CNNAME% -c KEY_ESC
ping 127.0.0.1 -n 2 > nul
govc vm.keystrokes -vm %CNNAME% -s " autoinstall ds=nocloud-net;s=http://myurl/mydir"
govc vm.keystrokes -vm %CNNAME% -c KEY_ENTER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment