Set Useful Machine Metadata with systemd machine-info

A server called db-07 tells you nothing at 3am, but /etc/machine-info lets hostnamectl show a name, location and role instead. You will create or update the file with a readable machine name and operational metadata, then confirm the values through hostnamectl. This is useful when the DNS name is terse but people still need to identify a laptop, server or virtual machine quickly.

Allow about 10 minutes. You need a Linux system using systemd 197 or newer for the basic chassis setting, and root access to edit the file or use hostnamectl. The examples below match the systemd 255 manpage installed on this machine, packaged as Ubuntu 24.04's systemd 255.4-1ubuntu8.17. The file is optional, so an existing machine may have no /etc/machine-info at all.

What this file controls

machine-info is a newline-separated list of shell-compatible variable assignments. Comments and blank lines are allowed. It is safe to source the assignments in a shell, but it is not a general shell script: command substitution, conditionals and other shell features are not supported.

The values are administrator-controlled metadata and have the highest precedence when applications look for this information. They do not rename the machine on the network. Keep /etc/hostname, DNS and the pretty human-readable name as separate concerns.

The supported fields in the local manpage are:

1. Inspect the current state

Start without changing anything. This gives you the detected chassis and hardware values, and shows whether a pretty name is already configured.

hostnamectl status
sudo test -e /etc/machine-info && sudo sed -n '1,120p' /etc/machine-info || echo '/etc/machine-info is absent'

Expected output includes lines such as Icon name, Chassis, and, where available, Hardware Vendor. If the file is absent, that is normal: systemd can obtain fallback values automatically.

Checkpoint: Record any existing values before editing. In particular, do not replace an administrator's location or deployment label just because it is unfamiliar.

2. Choose metadata that will stay true

Use a deployment value that describes the system's role, not the person currently logged in. For example, a test host can be staging even when it runs on production-grade hardware. Set CHASSIS only when automatic detection is wrong or unavailable. A virtual machine and a container are valid special values even though neither has a physical chassis.

Keep the pretty name recognisable and the location useful without exposing secrets. A rack position is often useful; an access code, customer identifier or private address is not.

3. Write the file

For a small, deliberate change, use hostnamectl. These commands require elevated privileges and write the corresponding entries in /etc/machine-info:

sudo hostnamectl hostname --pretty "Build Server 02"
sudo hostnamectl icon-name computer-server
sudo hostnamectl chassis server
sudo hostnamectl deployment staging
sudo hostnamectl location "Left Rack, 2nd Shelf"

The current hostnamectl help lists these subcommands. The first command changes only the pretty hostname because of the --pretty option; it does not change the static network hostname. The other commands change one machine-info property each.

For a reviewable batch change, edit the file as root instead. Preserve any settings you intend to keep and use quotes where a value contains spaces:

sudoedit /etc/machine-info

PRETTY_HOSTNAME="Build Server 02"
ICON_NAME=computer-server
CHASSIS=server
DEPLOYMENT=staging
LOCATION="Left Rack, 2nd Shelf"

Warning: Do not paste commands into this file. Do not add a shell shebang, command substitution or an unrecognised key and assume applications will use it. The format is intentionally limited to assignments.

4. Verify what consumers see

Read the values back through the supported command:

hostnamectl status
printf 'pretty hostname: '; hostnamectl --pretty hostname
printf 'icon: '; hostnamectl icon-name
printf 'chassis: '; hostnamectl chassis
printf 'deployment: '; hostnamectl deployment
printf 'location: '; hostnamectl location

The displayed values should match your chosen metadata. Hardware vendor and model may still come from DMI or hwdb when you have not set manual overrides. That is expected precedence behaviour, not evidence that the file was ignored.

If a command reports that the system bus or hostnamed is unavailable, inspect the file directly with sudo sed. The file may be correct even when the service interface is not available in a minimal container. Do not repair that unrelated service problem by changing machine-info syntax.

Undo a mistake

Before changing a value, save a root-readable copy if the file already exists:

sudo cp --preserve=mode,ownership /etc/machine-info /etc/machine-info.backup

If you need to restore it, use the saved copy and verify again:

sudo cp --preserve=mode,ownership /etc/machine-info.backup /etc/machine-info
hostnamectl status

Recovery: To remove one property, use hostnamectl with an empty value when supported by the installed command, or edit the file and remove that assignment. Check the local help first: hostnamectl --help. Removing the entire file is broader than removing one line and returns all fields to automatic fallbacks, so do not do that unless that is the intended result.

Done means