LinuxCommandLibrary

systemd-firstboot

Initialize system settings on first boot

TLDR

Operate on the specified directory instead of the root directory of the host system

$ sudo systemd-firstboot --root [path/to/root_directory]
copy

Set the system keyboard layout
$ sudo systemd-firstboot --keymap [keymap]
copy

Set the system hostname
$ sudo systemd-firstboot --hostname [hostname]
copy

Set the root user's password
$ sudo systemd-firstboot --root-password [password]
copy

Prompt the user interactively for a specific basic setting
$ sudo systemd-firstboot --prompt [setting]
copy

Force writing configuration even if the relevant files already exist
$ sudo systemd-firstboot --force
copy

Remove all existing files that are configured by systemd-firstboot
$ sudo systemd-firstboot --reset
copy

Remove the password of the system's root user
$ sudo systemd-firstboot --delete-root-password
copy

SYNOPSIS

systemd-firstboot [OPTIONS]

PARAMETERS

-h, --help
    Display a short help text and exit.

--version
    Show the version string and exit.

--root=PATH
    Operates on the specified root directory PATH instead of the system root (/). This is useful for configuring disk images or chrooted environments.

--force
    Forces systemd-firstboot to run even if the first boot setup has already been completed, indicated by the absence of the first-boot marker file.

--reboot
    Reboots the system after successful execution of all first boot tasks.

DESCRIPTION

systemd-firstboot is a utility designed to perform initial system setup tasks during the first boot of a newly installed or reset operating system.

Its primary purpose is to automate common post-installation configurations, ensuring that the system is ready for use without manual intervention. It checks for a specific "first boot" state, typically indicated by the presence of a file like /etc/.firstboot or an empty /etc directory. If this state is detected, systemd-firstboot proceeds to apply various configurations, which might include setting up initial system users and groups via systemd-sysusers(8), creating temporary files and directories via systemd-tmpfiles(8), or applying service preset configurations via systemd-preset(8).

After successful execution, systemd-firstboot typically clears the "first boot" indicator to prevent subsequent runs, ensuring that these one-time setup tasks are not repeated. This command plays a crucial role in creating a consistent and automated initial system environment for various Linux distributions.

CAVEATS

systemd-firstboot relies on specific markers (e.g., /etc/.firstboot or an empty /etc directory) to determine if it should run. If these markers are manually removed or not present, the first boot setup will not occur.

Forcing its execution with --force on an already configured system might lead to unintended changes or conflicts with existing configurations. It's designed for a specific initial state and might not handle subsequent re-runs gracefully without --force.

EXECUTION TRIGGER

systemd-firstboot is typically invoked by a systemd service unit (e.g., systemd-firstboot.service) which is enabled to run very early in the boot process, conditioned on the presence of the first-boot marker.

FIRST BOOT MARKER

The presence of the file /etc/.firstboot (or an empty /etc directory, depending on configuration) acts as the primary trigger for systemd-firstboot. Upon successful completion, this file is removed to prevent subsequent runs.

HISTORY

systemd-firstboot was introduced as part of the systemd project, which aimed to replace the traditional SysVinit system on Linux.

Its development emerged from the need to standardize and streamline the initial system setup process across different Linux distributions. Prior to systemd-firstboot, initial setup was often handled by disparate, distribution-specific scripts. By integrating this functionality into systemd, it provides a more robust, consistent, and declarative way to manage first-boot configurations, aligning with systemd's broader goal of unified system management.

SEE ALSO

systemd(1), systemctl(1), systemd-sysusers(8), systemd-tmpfiles(8), systemd-preset(8), useradd(8), passwd(1)

Copied to clipboard