setup-machine-id 1 user commands nosh
setup-machine-id set up the machine ID
`setup-machine-id`

## Description

`setup-machine-id` stores a machine ID in various areas of volatile and non-volatile storage, creating a new machine ID if one has not already been created, correcting faulty machine IDs generated by some erroneous softwares, and creating storage files if they are missing. See machine-id 7 for where the volatile and non-volatile storage areas are, and the corrections for faulty machine IDs.

`setup-machine-id` also creates a host ID (again, see machine-id 7) from the machine ID and stores it in various areas of storage, creating them if they are missing.

On operating systems where bind mounting is available, if `setup-machine-id` cannot write to the `/etc/machine-id` or the `/etc/hostid` files, it bind mounts the `/run/machine-id` or the `/run/hostid` files over them. This will be the case where the root filesystem is mounted read-only at the point in the operating system bootstrap where `setup-machine-id` is run.

### Fallbacks

`setup-machine-id` falls back to creating or restoring machine IDs as follows:

1. It will attempt to read the UUID from volatile storage and use that. Thus, if the file `/etc/machine-id` is deleted but the system is not restarted, `setup-machine-id` can restore the existing machine ID from volatile storage.

2. It will attempt to read the UUID from various older locations, such as the D-Bus machine ID files and (on the BSDs) the `/etc/hostid` and `/usr/local/etc/machine-id` files. Thus, if the file `/etc/machine-id` has not yet been created but the system has machine IDs from older mechanisms, `setup-machine-id` will attempt to retain the machine IDs from those mechanisms.

3. If it detects that it is running in a container/jail, it will use the value of the `container_uuid` environment variable, if it is correctly formatted. This environment variable is a convention and is set by various jailer and container management utilities.

4. As a final fallback, it will create a UUID using the uuid_create 3 or the uuid_generate 3 library function.

   On FreeBSD, UUID generation with these library functions still employs, and thus reveals, MAC address information.

Prior to version 1.40 of the toolset, `setup-machine-id` would attempt to read the SMBIOS product ID and use that as a fallback mechanism, for compatibility with what FreeBSD had done since 2007. This made machine IDs in practice constant and correlatable even when an administrator had explicitly wiped them. The privacy problems that this entailed far outweighed what little utility it had, and this has been removed.

## Compatibility

Not all other softwares support it, but `setup-machine-id` allows the `/etc/machine-id` file to contain further lines beyond the first one with the ID, which it will ignore when reading.

## Author

Jonathan de Boyne Pollard