What is machine-id in Linux
The /etc/machine-id file contains the unique machine ID of the local system that is set during installation. The machine ID is a single newline-terminated, hexadecimal, 32-character, lowercase machine ID string. When decoded from hexadecimal, this corresponds with a 16-byte/128-bit string. The machine ID is usually generated from a random source during system installation and stays constant for all subsequent boots. Optionally, for stateless systems, it is generated during runtime at boot if it is found to be empty.
The machine ID does not change based on user configuration or when hardware is replaced. This machine ID adheres to the same format and logic as the D-Bus machine ID. Programs may use this ID to identify the host with a globally unique ID in the network, which does not change even if the local network configuration changes. Due to this and its greater length, it is a more useful replacement for the gethostid(3) call that POSIX specifies.
The systemd-machine-id-setup(1) tool may be used by installer tools to initialize the machine ID at install time. Use systemd-firstboot(1) to initialize it on mounted (but not booted) system images.
Display Machine ID
To display the machine-id:
# hostnamectl | grep "Machine ID"
Machine ID: f50935fd04114b6ba00d0820cddae7f1
Generating a New machine-ID
When a system is cloned, the cloned system’s machine-id value is not automatically changed, therefore duplicate systems exist within the network. Every system must have a unique machine-id value.
Perform the following actions as the root user on any cloned systems.
1. Clear the original machine-id.
The machine-id value is stored in file /etc/machine-id. The original machine-id value must be removed before it’s value can be changed. Multiple methods exist to change the machine-id value - in this case, the cp(1) is used. For example :
e2bd0adf084a4c289cf335da4cd2junk * Original "machine-id".
# cp -f /dev/null /etc/machine-id
cp: overwrite '/etc/machine-id'? * Clear original value.
# cat /etc/machine-id
# * Value has been cleared.
2. Generate the new, unique machine-id value - generate a new machine-id value using the systemd-machine-id-setup command and add it to file /etc/machine-id. For example:
# cat /etc/machine-id
# * "/etc/machine-id" is empty.
# systemd-machine-id-setup
Initializing machine ID from random generator. * Success to generate and setup the new value.
# cat /etc/machine-id
junk9965986b4ea1ba34dc7a79bb2830 * New value of "machine-id".