Linucate
~ Linucate_

101.3 Change runlevels and boot targets, shutdown and reboot

All Levels

Introduction

This lesson is about the system after boot.

Linux is not just "on" or "off". It can be in different system states:

  • normal multi-user mode
  • graphical mode
  • rescue mode
  • emergency mode
  • shutdown or reboot

Older Linux systems talked about runlevels. Modern systemd-based systems talk about targets.

For LPIC-1, you should understand both ideas.

Keep this short mental model:

PID 1 controls the system state -> runlevels or targets describe that state -> shutdown and reboot change that state safely

What you should be able to do after this lesson:

  • Identify the init system.
  • Check the current or default runlevel/target.
  • Switch to another state temporarily.
  • Change the default state for the next boot.
  • Shut down or reboot safely.
  • Recognize SysVinit, systemd, and Upstart.

Step 1: Identify the Init System

Everything here starts with one question:

Who is PID 1?

Check it with:

ps -p 1 -o comm=

Common results:

  • systemd
  • init

Why this matters:

  • systemd uses targets and systemctl
  • SysVinit uses runlevels and tools such as init or telinit
  • older Upstart-based systems also often appear as init, but they manage jobs with initctl

Runlevels vs Targets

The idea is the same in both worlds:

a system state is a bundle of behavior

Examples:

  • text-only multi-user mode
  • graphical mode
  • rescue mode
  • reboot mode

Simple translation

  • SysVinit usually uses numbers such as 3 or 5
  • systemd usually uses names such as multi-user.target or graphical.target

You do not need to fear the naming difference. They solve the same problem.

systemd Targets

Most modern Linux distributions use systemd.

Check the default target

systemctl get-default

Example output:

graphical.target

This means the system normally boots into graphical mode.

See active targets right now

systemctl list-units --type=target --state=active

It is normal to see more than one active target.

Temporarily switch target

Use this when you want to change state right now:

sudo systemctl isolate <target>

Common examples:

  • sudo systemctl isolate multi-user.target
  • sudo systemctl isolate graphical.target
  • sudo systemctl isolate rescue.target
  • sudo systemctl isolate emergency.target

What is the difference between rescue and emergency?

rescue.target

  • minimal system
  • useful for maintenance
  • still more complete than emergency mode

emergency.target

  • even smaller environment
  • very limited
  • often used when normal startup is badly broken

Change the default target for future boots

sudo systemctl set-default <target>
systemctl get-default

Example:

sudo systemctl set-default multi-user.target

This means the next boot should land in text mode instead of graphical mode.

Mapping: Runlevels to Targets

This mapping helps a lot in the exam:

  • Runlevel 0 -> poweroff.target
  • Runlevel 1 -> rescue.target
  • Runlevel 3 -> multi-user.target
  • Runlevel 5 -> graphical.target
  • Runlevel 6 -> reboot.target

It is not a perfect one-to-one copy of history, but it is the right beginner picture.

SysVinit Runlevels

Older systems, older books, and many exam questions still use runlevels.

Check the current runlevel

runlevel

Example output:

N 5

How to read it:

  • N = previous runlevel
  • 5 = current runlevel

Change runlevel

sudo telinit <runlevel>

You may also see:

sudo init <runlevel>

Common meanings

  • 0 = halt or power off
  • 1 = single-user or maintenance mode
  • 3 = multi-user text mode
  • 5 = multi-user graphical mode
  • 6 = reboot

Runlevels 2, 3, 4, and 5 can vary by distribution, but the meanings above are the common exam picture.

SysVinit Files You Should Recognize

/etc/inittab

This classic file can define the default runlevel.

Example line:

id:3:initdefault:

/etc/init.d/

This directory contains service scripts.

/etc/rcX.d/

These are runlevel-specific links.

Simple rule:

  • S* links start services
  • K* links stop services

Reload inittab

After editing /etc/inittab, you may see:

sudo telinit q

Upstart Awareness

Upstart is not the main init system on most modern Linux distributions, but LPIC still expects you to recognize it.

In plain words

Upstart is an event-based init system. It manages jobs instead of systemd units or classic SysV runlevels.

Common location

/etc/init/*.conf

Basic commands to recognize

initctl list | head
status <job>
start <job>
stop <job>

What you need to remember for the exam:

  • systemd -> units and targets
  • SysVinit -> scripts and runlevels
  • Upstart -> jobs

Safe Shutdown and Reboot

The important idea is this:

a safe shutdown is not "cut the power"

Linux should:

  • stop services
  • sync and unmount filesystems
  • then power off or reboot

Modern commands with systemd

sudo systemctl poweroff
sudo systemctl reboot

Classic shutdown command

sudo shutdown -h now
sudo shutdown -r now

How to read them:

  • -h = halt or power off
  • -r = reboot
  • now = do it immediately

Schedule shutdown or reboot

sudo shutdown -h +10 "System maintenance"
sudo shutdown -r 23:30 "Planned reboot"

Meaning:

  • +10 = in 10 minutes
  • 23:30 = at 23:30
  • the message is shown to logged-in users

Cancel a scheduled shutdown

sudo shutdown -c

Tell users what is happening

Sometimes you want to warn users even without scheduling a shutdown:

echo "System maintenance in 5 minutes" | wall

wall means "write to all".

Classic command names you may still see

You may also meet:

  • reboot
  • poweroff
  • halt

The exam-friendly mindset is:

  • know these names
  • prefer shutdown or systemctl when you want clear and safe behavior

ACPI and acpid

ACPI is related to power events such as:

  • pressing the power button
  • laptop lid events
  • sleep-related signals

On some systems, acpid handles these events.

Quick awareness check:

systemctl status acpid --no-pager

You do not need deep ACPI internals here. Just know that it is connected to power events.

Properly Terminating Processes

Sometimes a process does not stop when it should. You should prefer a gentle stop first.

Find a process

pgrep -a <name> | head
ps aux | head

Stop it gently

sudo kill -15 <pid>

This sends SIGTERM. It asks the process to stop cleanly.

Force stop as a last resort

sudo kill -9 <pid>

This sends SIGKILL. Use it only when the process refuses to stop normally.

By name instead of PID

sudo pkill -15 <name>
sudo killall -15 <name>

For the exam, the core idea is:

SIGTERM first, SIGKILL only if needed

Practice Step by Step

1) Switch from graphical mode to text mode for this session
  1. Check PID 1: ps -p 1 -o comm=
  2. Check the default target: systemctl get-default
  3. Switch now: sudo systemctl isolate multi-user.target
  4. If needed, return: sudo systemctl isolate graphical.target
2) Change the default boot state to text mode
  1. Check current default: systemctl get-default
  2. Set a new default: sudo systemctl set-default multi-user.target
  3. Verify: systemctl get-default
3) Schedule a reboot and then cancel it
  1. Schedule: sudo shutdown -r +5 "Planned reboot"
  2. Optionally warn users: echo "Planned reboot in 5 minutes" | wall
  3. Cancel: sudo shutdown -c
4) Stop a stuck process the safe way
  1. Find it: pgrep -a <name>
  2. Try graceful stop: sudo kill -15 <pid>
  3. Only if needed: sudo kill -9 <pid>

Cheat Sheet

  • ps -p 1 -o comm= = identify the init system
  • systemctl get-default = show the default target
  • systemctl isolate <target> = switch target now
  • systemctl set-default <target> = change default target for next boot
  • runlevel = show current runlevel
  • telinit <runlevel> or init <runlevel> = switch runlevel
  • /etc/inittab = classic SysVinit configuration file
  • /etc/init.d/ = classic service scripts
  • /etc/rcX.d/ = runlevel links
  • telinit q = reload inittab
  • /etc/init/*.conf = Upstart job files
  • initctl list = list Upstart jobs
  • shutdown -h now = power off now
  • shutdown -r now = reboot now
  • shutdown -h +10 "message" = schedule shutdown
  • shutdown -c = cancel scheduled shutdown
  • wall = send a message to all logged-in users
  • kill -15 = graceful stop
  • kill -9 = forced stop
  • pkill and killall = stop by name
  • systemctl status acpid = check ACPI event handling service
🎯

Test Your Knowledge

Complete the quiz to assess your understanding of this course's concepts.