Regenerate a unique machine ID on Linux

6 November 2026

To regenerate a unique machine ID on Linux after cloning a virtual machine or disk image, you can clear the existing ID and initialize a new one using systemd-machine-id-setup. Run the following commands:

# 1. Clear or remove the existing machine ID file
sudo truncate -s 0 /etc/machine-id

# 2. If it exists, clear the D-Bus variant as well
if [ -f /var/lib/dbus/machine-id ]; then sudo truncate -s 0 /var/lib/dbus/machine-id; fi

# 3. Regenerate a new unique ID
sudo systemd-machine-id-setup

Note: Truncating the file to 0 bytes (instead of completely deleting it) prevents boot issues if your root file system happens to be mounted read-only during the next early boot phase.

After running these commands, a system reboot is required. Many running background processes (like systemd-networkd and journald) read the machine ID only once at startup.