ubuntu 18.x is by default shipped with cloud-init/netplan that breaks when customizing the VM using vCenter custom spec. In this blog, I’ll show you how to get the customization to work with vCenter.
On a fresh install of ubuntu 18.04, create a bash script with the below contents (mine was setup using DHCP)
sudo cloud-init clean --logs sudo touch /etc/cloud/cloud-init.disabled sudo rm -rf /etc/netplan/50-cloud-init.yaml sudo apt purge cloud-init -y sudo apt autoremove -y # Don't clear /tmp sudo sed -i 's/D \/tmp 1777 root root -/#D \/tmp 1777 root root -/g' /usr/lib/tmpfiles.d/tmp.conf # Remove cloud-init and rely on dbus for open-vm-tools sudo sed -i 's/Before=cloud-init-local.service/After=dbus.service/g' /lib/systemd/system/open-vm-tools.service # cleanup current ssh keys so templated VMs get fresh key # sudo rm -f /etc/ssh/ssh_host_* # add check for ssh keys on reboot...regenerate if neccessary sudo tee /etc/rc.local >/dev/null <<EOL #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server # exit 0 EOL # make the script executable sudo chmod +x /etc/rc.local # cleanup apt sudo apt clean # reset the machine-id (DHCP leases in 18.04 are generated based on this... not MAC...) echo "" | sudo tee /etc/machine-id >/dev/null # disable swap for K8s sudo swapoff --all sudo sed -ri '/\sswap\s/s/^#?/#/' /etc/fstab # cleanup shell history and shutdown for templating history -c history -w sudo shutdown -h now
Note, sometimes copy-paste can change the special characters, should that be the case, please use this link to download the file:
once the script is run, the VM should power off automatically. convert the VM to the template and then test by deploying this with a guest customization spec
Note: Do not run the command directly from putty/shell. in some cases i’ve noticed the networking on the VM goes blank causing the VM to go off-network when the netplan is being removed..
always invoke the above via the bash script local to the guest os.
2 Replies to “ubuntu 18.04 getting VMware guest customization to work”
Thanks for that script. For Ubuntu 20.0.* I just changed one line sudo rm -rf /etc/netplan/50-cloud-init.yaml with sudo rm -rf /etc/netplan/*.yaml.
After doing that it works on vSphere 7.0 and ubuntu 20.
Good day very nice website!! Man .. Beautiful .. Superb .. I will bookmark your site and take the feeds additionally厈I am glad to search out a lot of useful info right here in the post, we want develop extra techniques on this regard, thanks for sharing. . . . . .