Courseiva
Service Configuration →mediumMultiple Choice

LFCS Service Configuration Practice Question

A Linux administrator is configuring a systemd service unit for a custom application. The application requires that the /opt/app/data directory exists and is writable before the service starts. The administrator wants to ensure this directory is created automatically if it does not exist. Which systemd directive should be added to the [Service] section to achieve this?

⚠ Common exam trap

The trap here is assuming that StateDirectory or RuntimeDirectory can create arbitrary directories, when they are restricted to /var/lib and /run respectively.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

ExecStartPre=/bin/mkdir -p /opt/app/data

The ExecStartPre directive allows running a command before the main service starts. Using /bin/mkdir -p /opt/app/data will create the directory and any missing parent directories, ensuring it exists before the application starts. Other directives like StateDirectory and RuntimeDirectory only manage directories in specific system locations (/var/lib and /run, respectively). WorkingDirectory merely sets the working directory but does not create it. Thus, ExecStartPre is the correct solution for creating a custom directory under /opt.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    ExecStartPre=/bin/mkdir -p /opt/app/data

    Why this is correct

    ExecStartPre specifies a command to run before the main ExecStart command. Using /bin/mkdir -p /opt/app/data ensures the directory exists and creates parent directories as needed. This is a flexible and direct way to meet the requirement, as it can create any path and set permissions if needed. It is the correct approach for this scenario.

  • ✗

    StateDirectory=app/data

    Why it's wrong here

    StateDirectory is used to create and manage directories under /var/lib for persistent state. It does not create directories under /opt. This directive is not suitable for the scenario because the required path is /opt/app/data, not /var/lib/app/data. Using it would create the wrong directory and not satisfy the application's requirement.

  • ✗

    RuntimeDirectory=app/data

    Why it's wrong here

    RuntimeDirectory creates directories under /run (or /var/run) for runtime data. It is intended for volatile runtime files and does not persist across reboots. The scenario requires a directory under /opt, which is not managed by RuntimeDirectory. Therefore, this directive does not meet the requirement.

  • ✗

    WorkingDirectory=/opt/app/data

    Why it's wrong here

    WorkingDirectory sets the working directory for the service's processes. It does not create the directory if it does not exist; if the directory is missing, the service will fail to start. This directive is used to specify where the process runs, not to ensure directory existence. It does not satisfy the requirement of automatically creating the directory.

About these practice questions

One of 406 original LFCS practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Linux Foundation exam blueprint

This LFCS practice question is part of Courseiva's free Linux Foundation certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the LFCS exam.