The systemd-tmpfiles-setup.service is a critical systemd component responsible for creating, deleting, and cleaning up volatile and temporary files and directories (such as those in /tmp, /var/tmp, and /run) during the boot process, based on configuration rules defined in /usr/lib/tmpfiles.d/. While this service is absolutely essential for standard, read-write Ubuntu Server environments, it can introduce fatal initialization errors in highly specialized deployments. For instance, in strict read-only root filesystems, immutable Docker containers, or deeply embedded appliances where the temporary directories are handled externally via RAM disks or orchestrator mounts, attempting to run systemd-tmpfiles-setup causes boot delays, permission denied errors, and unnecessary CPU overhead.
This guide explains how to completely disable the systemd-tmpfiles-setup service in Ubuntu Server, optimizing the boot sequence for stateless and strictly immutable instances.
Warning: Do not perform this action on a standard, read-write Ubuntu Server. Disabling this service on a normal OS will break PID file creation, socket initialization, and cause severe system instability. Only proceed if you are building an immutable image or a specialized container.
Stop and Mask the systemd-tmpfiles-setup Service
To guarantee that the server boots faster and ignores the temporary file generation phase, we must disable the service and explicitly mask it to prevent systemd from invoking it during the boot sequence.
- Log into your Ubuntu Server via SSH using an account with
sudoprivileges. - First, check the current status of the service:
sudo systemctl status systemd-tmpfiles-setup.service - Next, disable the service to remove its symlinks from the systemd boot schedule:
sudo systemctl disable systemd-tmpfiles-setup.service - For absolute certainty, explicitly mask the service. This symlinks the unit file to
/dev/null, creating a hard block against it starting under any circumstances:sudo systemctl mask systemd-tmpfiles-setup.service
Verify the Service Lockdown
By masking systemd-tmpfiles-setup.service, you guarantee that the Ubuntu OS will silently skip the temporary directory generation phase, assuming that these mounts are being handled externally.
To verify the lockdown is successful, attempt to start the service manually:
sudo systemctl start systemd-tmpfiles-setup.service
Systemd will return a fatal error stating that the unit is masked (e.g., Failed to start systemd-tmpfiles-setup.service: Unit systemd-tmpfiles-setup.service is masked). You have successfully neutralized the service, streamlining your server’s immutable initialization pipeline.