6

We're using a ubuntu-18.04 template on a virtualization environment. Therefore, before creating the template, we always empty the /etc/machine-id file so it's recreated upon the first boot.

The problem is that if several ubuntu-18-based VMs are started at once, systemd-machine-id-setup will generate the same ID for all of them, resulting in IP duplication. I checked these servers and they all have the same content in the /etc/machine-id file.

IP duplication

If machines are powered-on spaced in time, different IPs are assigned, thus I assume systemd-machine-id-setup is generated based on current time (possibly). This isn't acceptable for us because of the problem in the image above.

Is there a way to make the OS generate the /etc/machine-id on boot based on an alternative binary?

--- UPDATE 1 ---

On @GeraldSchneider's tip, I switched back from netplan to ifdownup and the IPs stopped duplicating, so definitely this is a netplan issue.

no duplicated IPs

Even if this could solve the problem, I'm curious if there's a way to set an alternative way to generate the /etc/machine-id file so no duplications happen using netplan.

nKn
  • 111
  • 7
  • 1
    Have you looked at `/etc/machine-id` to see if it is actually the same on each system? The machine ID file is not normally used to obtain an IP address. How are you assigning IP addresses? – Michael Hampton Jul 16 '19 at 14:37
  • @MichaelHampton yes, the `machine-id` file has exactly the same value on the machines that are powered-on within the same time lapse. If machines are powered-on on different time lapses, the file content varies. IP addresses are assigned via DHCP. Actually, this file seems to be used to acquire IP addresses: https://jaylacroix.com/fixing-ubuntu-18-04-virtual-machines-that-fight-over-the-same-ip-address/ – nKn Jul 17 '19 at 07:45
  • Which versions of ESXi are you running? It might possibly be important. – Michael Hampton Jul 17 '19 at 14:55
  • It's not VMware, it's oVirt. However, it happens on both infrastructures, so I assume this is an Ubuntu 18 issue, not infrastructure. – nKn Jul 18 '19 at 07:30
  • Have you tried if [switching back from netplan to ifupdown](https://askubuntu.com/questions/1031709/ubuntu-18-04-switch-back-to-etc-network-interfaces) makes a difference? – Gerald Schneider Jul 18 '19 at 11:32
  • @GeraldSchneider Actually it did a **big** difference. I updated my question with the tests I made. – nKn Jul 18 '19 at 12:44
  • 1
    You can also switch the netplan DUID back to `MAC` instead of `machine-id` using `dhcp-identifier: mac`, it seems this is a common issue with netplan and the changed DUID. – Lenniey Jul 18 '19 at 14:13
  • @Lenniey this way there are no duplicate IPs either. However, the `/etc/machine-id` is still the same for all machines which is something I'd like to avoid. – nKn Jul 19 '19 at 08:28
  • You can programmatically `rm /etc/machine-id; systemd-machine-id-setup;` via https://www.thegeekdiary.com/centos-rhel-7-how-to-change-the-machine-id/ – bgStack15 Jul 21 '19 at 03:20
  • @bgStack15 the system itself will call this command if it finds the `/etc/machine-id` empty, which is what I'm doing now. But that exactly what I want to avoid, I want to generate the `machine-id` with a different command upon startup so I make sure it won't generate the same ID for two different machines. – nKn Jul 22 '19 at 07:03

1 Answers1

2

...I'm curious if there's a way to set an alternative way to generate the /etc/machine-id file...

Per the machine-id manual page,

...Otherwise, the value in /etc/machine-id will be used. If this file is empty or missing, systemd will attempt to use the D-Bus machine ID from /var/lib/dbus/machine-id, the value of the kernel command line option container_uuid, the KVM DMI product_uuid (on KVM systems), and finally a randomly generated UUID.

And also, towards the bottom of the page,

The simple configuration file format of /etc/machine-id originates in the /var/lib/dbus/machine-id file introduced by D-Bus. In fact, this latter file might be a symlink to /etc/machine-id.

Therefore, it is also possible to set the machine-id using dbus-uuidgen, as can be seen in the following answer:

Per the dbus-uuidgen manual page,

If you run dbus-uuidgen with no options it just prints a new uuid made up out of thin air.

oxr463
  • 352
  • 1
  • 2
  • 14