LinuxCommandLibrary

systemctl-preset-all

Apply all systemd unit presets

TLDR

Reset the enablement state of all installed units

$ sudo systemctl preset-all
copy

Enable only if marked as enabled in the preset policy
$ sudo systemctl preset-all --preset-mode enable-only
copy

Disable only if marked as disabled in the preset policy
$ sudo systemctl preset-all --preset-mode disable-only
copy

Suppress output and return only the exit code
$ sudo systemctl preset-all [[-q|--quiet]]
copy

SYNOPSIS

systemctl preset-all [UNIT...] [OPTIONS]

PARAMETERS

UNIT...
    Optional. Specifies one or more unit names (e.g., apache2.service, sshd.socket). If provided, presets are applied only to these specific units instead of all installed units.

--root=PATH
    Operates on a systemd instance rooted in the specified directory PATH instead of the default /. This is useful for chroot or container environments.

--runtime
    Makes changes only in the runtime configuration, meaning they will be lost on the next system reboot. This is useful for temporary state changes.

--dry-run
    Shows what actions would be performed without actually executing them. This is helpful for previewing the impact of the command.

--no-reload
    Prevents systemd from reloading its configuration after making changes. This might be useful in scripts where a manual reload will follow.

DESCRIPTION

The systemctl preset-all command is a crucial utility within the systemd ecosystem, designed to apply the predefined enablement policies (presets) to all installed systemd units. These presets determine whether a particular service, socket, timer, or other systemd unit should be enabled or disabled by default at boot time. This command is particularly useful after a new system installation, a major package upgrade, or when wishing to revert unit enablement states to the defaults specified by package maintainers or system administrators. When executed, preset-all iterates through all available unit files and consults the preset files (typically found in /etc/systemd/system/*.preset and /usr/lib/systemd/system/*.preset). Based on the rules defined in these preset files, it then enables or disables the corresponding units. This ensures a consistent and predictable initial state for system services, aligning with the distribution's recommended configuration. It can also be run with specific unit names as arguments to apply presets only to those units.

CAVEATS

  • Requires root privileges to execute, as it modifies system-wide unit enablement states.
  • Applying presets can change the behavior of your system on subsequent reboots by enabling or disabling services that were previously in a different state.
  • Custom configurations in /etc/systemd/system/*.conf or explicit manual systemctl enable/disable commands might be overridden if the preset rules conflict. Ensure you understand your preset files.

HOW PRESETS WORK

Preset files are simple text files with a .preset extension, typically located in /usr/lib/systemd/system/*.preset (provided by packages) and /etc/systemd/system/*.preset (for local overrides). They contain rules like enable unit.service or disable unit.service. If multiple preset files define rules for the same unit, the one in /etc takes precedence, and within a directory, files are processed in lexicographical order.

IMPACT ON EXISTING SERVICES

When systemctl preset-all is run, it affects the enablement state of units, meaning whether they start at boot. It does not directly stop or start currently running services. For immediate changes, systemctl start or systemctl stop would be required after preset-all.

HISTORY

The preset-all subcommand, along with the systemd preset mechanism, has been an integral part of systemd since its early development. It was introduced to standardize and simplify the initial configuration of services across different Linux distributions using systemd, offering a declarative way for package maintainers to specify default enablement policies for their services. This significantly improved consistency compared to previous init systems.

SEE ALSO

systemctl(1), systemd.preset(5), systemctl enable(1), systemctl disable(1)

Copied to clipboard