Bird
Raised Fist0
Linux CLIscripting~10 mins

Startup and init systems (systemd) in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - Startup and init systems (systemd)
Power On
↓
Firmware (BIOS/UEFI)
↓
Load bootloader (GRUB)
↓
Start kernel
↓
systemd starts
↓
Read unit files
↓
Start target units (like multi-user.target)
↓
Start services in order
↓
System ready for use
This flow shows how systemd starts after the kernel loads, reads unit files, and starts services to make the system ready.
Execution Sample
Linux CLI
systemctl start sshd.service
systemctl status sshd.service
systemctl enable sshd.service
Starts the SSH service, checks its status, and enables it to start on boot.
Execution Table
StepCommandActionResultOutput
1systemctl start sshd.serviceStart sshd service nowSuccess● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled) Active: active (running) since ...
2systemctl status sshd.serviceCheck sshd service statusActive● sshd.service - OpenSSH server daemon Active: active (running) since ...
3systemctl enable sshd.serviceEnable sshd to start at bootSuccessCreated symlink /etc/systemd/system/multi-user.target.wants/sshd.service → /usr/lib/systemd/system/sshd.service
4systemctl is-enabled sshd.serviceVerify enable statusenabledenabled
5systemctl stop sshd.serviceStop sshd serviceSuccess
6systemctl status sshd.serviceCheck sshd service statusInactive● sshd.service - OpenSSH server daemon Active: inactive (dead) since ...
💡 Commands complete; sshd service started, enabled, then stopped and status checked.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 5Final
sshd.service statusinactiveactive (running)active (running)active (running)inactive (dead)inactive (dead)
sshd.service enableddisableddisableddisabledenabledenabledenabled
Key Moments - 3 Insights
Why does 'systemctl start' not enable the service to start on boot?
'systemctl start' only starts the service now but does not change boot settings. Enabling requires 'systemctl enable' as shown in step 3.
What does 'enabled' mean in systemd context?
'Enabled' means systemd will start the service automatically at boot. This is confirmed in step 4 with 'systemctl is-enabled'.
Why is the service status 'inactive' after stopping it?
Stopping the service with 'systemctl stop' (step 5) halts it immediately, so status changes to 'inactive' as seen in step 6.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the status of sshd.service after step 1?
Afailed
Binactive (dead)
Cactive (running)
Denabled
💡 Hint
Check the 'Result' and 'Output' columns in row for step 1.
At which step is sshd.service enabled to start at boot?
AStep 3
BStep 1
CStep 5
DStep 6
💡 Hint
Look for the command 'systemctl enable sshd.service' in the execution table.
If you skip 'systemctl enable', what happens on next boot?
Asshd.service starts automatically
Bsshd.service does not start automatically
Csshd.service fails to start
Dsshd.service is removed
💡 Hint
Refer to the meaning of 'enabled' in the key moments section.
Concept Snapshot
systemd manages startup by reading unit files and starting services.
Use 'systemctl start <service>' to run now.
Use 'systemctl enable <service>' to start on boot.
Check status with 'systemctl status <service>'.
Stopping a service changes status to inactive.
Full Transcript
When a Linux system boots, systemd starts after the kernel loads. It reads unit files that describe services and targets. Using systemctl commands, you can start services immediately, check their status, and enable them to start automatically on boot. For example, 'systemctl start sshd.service' runs the SSH server now, but does not enable it. 'systemctl enable sshd.service' sets it to start on future boots. Stopping a service with 'systemctl stop' makes it inactive. This flow helps manage system services clearly and reliably.

Practice

(1/5)
1. What is the main purpose of systemd in a Linux system?
easy
A. To manage how the system starts and stops programs automatically
B. To edit text files in the system
C. To compile software from source code
D. To monitor network traffic

Solution

  1. Step 1: Understand systemd's role

    systemd is a system and service manager that controls how programs start and stop on Linux.
  2. Step 2: Compare options

    Only To manage how the system starts and stops programs automatically describes managing startup and shutdown of programs, which matches systemd's purpose.
  3. Final Answer:

    To manage how the system starts and stops programs automatically -> Option A
  4. Quick Check:

    systemd manages startup and shutdown = B [OK]
Hint: Remember: systemd controls startup and shutdown of services [OK]
Common Mistakes:
  • Confusing systemd with text editors
  • Thinking systemd compiles code
  • Mixing systemd with network tools
2. Which of the following is the correct command to enable a service named nginx to start automatically at boot?
easy
A. systemctl enable nginx
B. systemctl start nginx
C. systemctl status nginx
D. systemctl stop nginx

Solution

  1. Step 1: Understand systemctl commands

    To enable a service to start at boot, the command is systemctl enable [service].
  2. Step 2: Match command to action

    systemctl enable nginx uses enable with nginx, which is correct for auto-start.
  3. Final Answer:

    systemctl enable nginx -> Option A
  4. Quick Check:

    Enable means auto-start = A [OK]
Hint: Enable means auto-start at boot, start means immediate run [OK]
Common Mistakes:
  • Using start instead of enable for auto-start
  • Confusing status with enable
  • Using stop instead of enable
3. What will be the output of the command systemctl is-active sshd if the SSH service is running?
medium
A. inactive
B. failed
C. active
D. unknown

Solution

  1. Step 1: Understand systemctl is-active

    This command checks if a service is running and returns its state.
  2. Step 2: Identify expected output when running

    If the SSH service is running, the output is active.
  3. Final Answer:

    active -> Option C
  4. Quick Check:

    Running service status = active [OK]
Hint: Active means running, inactive means stopped [OK]
Common Mistakes:
  • Confusing active with inactive
  • Expecting failed when service is running
  • Thinking unknown means running
4. You run systemctl enable apache2 but the service does not start on boot. What is the most likely reason?
medium
A. The service is already running
B. You used start instead of enable
C. The systemctl command is not installed
D. The service file for apache2 is missing or incorrect

Solution

  1. Step 1: Understand what enable does

    Enable creates links so the service starts at boot but does not start it immediately.
  2. Step 2: Identify why enable might fail

    If the service file is missing or broken, enabling won't work properly, so it won't start on boot.
  3. Final Answer:

    The service file for apache2 is missing or incorrect -> Option D
  4. Quick Check:

    Missing service file blocks enable = D [OK]
Hint: Enable needs a valid service file to work [OK]
Common Mistakes:
  • Confusing enable with start
  • Assuming systemctl is missing
  • Thinking running service means enable failed
5. You want to create a custom service that runs a script at startup. Which two steps must you perform to make sure it starts automatically with systemd?
hard
A. Add your script to /etc/rc.local and make it executable
B. Create a service file in /etc/systemd/system, then run 'systemctl enable yourservice' to auto-start it
C. Place your script in /usr/bin and reboot the system
D. Run 'systemctl start yourservice' and then 'systemctl status yourservice' only

Solution

  1. Step 1: Create a systemd service file

    Write a service file describing your script and place it in /etc/systemd/system/ to define how systemd runs it.
  2. Step 2: Enable the service

    Run systemctl enable yourservice to make it start automatically at boot.
  3. Final Answer:

    Create a service file in /etc/systemd/system, then run 'systemctl enable yourservice' to auto-start it -> Option B
  4. Quick Check:

    Create service file + enable = auto-start [OK]
Hint: Create service file and enable it to auto-start [OK]
Common Mistakes:
  • Only starting service without enabling
  • Using old /etc/rc.local method
  • Placing script without service file
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard