Lesson  in  Linux for SRE / DevOps - Beginner Level

Boot, Shutdown, and Targets - Doing It Safely

on Linux
A high-level view of the boot sequence, runlevels vs. systemd targets, and shutdown/reboot/wall - rebooting a shared box without dropping anyone else's session unannounced.

What happens between power-on and a login prompt

Roughly: the kernel loads and takes over the hardware, then hands control to init - on almost every modern distro, that's systemd, process ID 1, the parent of every other process on the box. systemd then brings the system up to a target - a named bundle of services that should be running - rather than the old numbered runlevels (0-6) you'll still see referenced in older material and documentation. graphical.target and multi-user.target are the two you'll meet most - a plain headless server is usually multi-user.target (full networking and services, no GUI), though plenty of real boxes, this one included, default to graphical.target even with no monitor ever attached to them. Don't guess which one a given box uses - the entire point of this lesson is to check instead:

systemctl get-default
graphical.target

On this particular box it's graphical.target, even though it's a headless cloud VM with no monitor ever attached - proof it really is worth checking instead of assuming.

Who else is even here

Before you touch a shared box, see who's actually logged in right now:

w
 03:49:07 up 0 min,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU  WHAT
laborant          -                03:49    4.00s  0.00s   ?    -bash

The first line is a summary: how long the box has been up, how many users are logged in, and load average. Each line after that is one active session - USER and WHAT (what they're actually running right now) are the two columns worth reading before you disrupt anything. One user here means it's just you; three or four different usernames would be a very different situation to reboot into without warning anyone.

Shutting down without surprising anyone

sudo shutdown -r now          # reboot immediately
sudo shutdown -r +5             # reboot in 5 minutes
sudo shutdown -c                  # cancel a pending scheduled shutdown
sudo reboot                         # equivalent to shutdown -r now

A shared box might have other people logged in right now. Before you drop their session, tell them:

wall "Rebooting in 5 minutes for a kernel update - save your work"

wall ("write to all") puts a message on every logged-in terminal at once. Scheduling with shutdown -r +5 instead of now and sending a wall first is the entire difference between a routine maintenance window and someone's unsaved work vanishing without warning.

Record what this box actually boots into

systemctl get-default > ~/current-target.txt
Why not actually practice rebooting here?

On a real server you'd absolutely practice shutdown -r +5 and shutdown -c during a quiet window. This lesson keeps the graded part non-disruptive so it doesn't restart your playground mid-course - but the commands above are exactly what you'd run for real.