Not gonna lie, getting this to work was hard, plus I'm still not
super happy with the results but it's good enough. You can set
a static ip in the Proxmox cloud-init
disk and that's what you'll
end up with on first boot.
Note: this probably also applies to Ubuntu 18.04
There is probably a way better way to get here but this is what I ended up doing.
- download and install latest cloud image in a vm
- after booting tweak the image as you see fit
- prepare the image for templating by unsetting hostname, deleting
.bash_history
, etc - run
cloud-init clean
poweroff
the vm- in Proxmox convert vm to a template (this is
v1
) - clone
v1
template and boot it - paste the script that's below in shell
poweroff
- convert vm to a template (this is
v2
, you'll probably want to make this a full clone) - clone
v2
template, this vm should “just work”
script
You can just paste the following in your shell.
Why couldn't we do this in the first image? Not sure, but something
happens on first boot of v2
that files are created, files are deleted,
etc. Just do the steps twice and get on with your life.
Or if you know what's going on leave a comment below.
# nic must have "old" name, eg. eth0 and not ens18
cat << EOF > /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", NAME="eth0"
EOF
# this prevents network configuration from happening, says so right in the name
rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg
# ConfigDrive needs to come first (I think)
cat << EOF > /etc/cloud/cloud.cfg.d/99-pve.cfg
datasource_list: [ConfigDrive, NoCloud]
EOF
# this is super important, netplan files are not regenerated if they exist
rm -f /etc/netplan/00-installer-config.yaml
rm -f /etc/netplan/50-cloud-init.yaml
cloud-init clean
# reboot
Even though I just finished getting this working I've written this from memory so I may have missed something. Also you may have to repeat making a template v3
from v2
. You'll know if you have a dhcp
address and the files the script deleted still exist.
/etc/netplan/50-cloud-init.yaml
should have your static ip after booting.