Fundamentals 11 min read

How Linux Boots: From Kernel Load to User Login Explained

This article walks through the Linux boot sequence on a Debian system, covering kernel loading, the init process, runlevel scripts, service management, and the various ways users log in, while also explaining the role of login and non‑login shells and Bash configuration files.

21CTO
21CTO
21CTO
How Linux Boots: From Kernel Load to User Login Explained

Linux Boot Overview

After the BIOS hands control to the hardware, the Linux kernel is read from the /boot directory. Typical files include vmlinuz-3.2.0‑amd64, initrd.img-3.2.0‑amd64, and various config-* files.

Loading the Kernel

The kernel image is loaded first, then the first user‑space program /sbin/init starts with PID 1. This init process is responsible for initializing the system environment and launching other services.

Init Process and Runlevels

Init reads /etc/inittab to determine the default runlevel (usually 2 on Debian). Each runlevel (0‑6) has a corresponding directory /etc/rcN.d containing scripts that start (prefix S) or stop (prefix K) services. The two‑digit numbers in script names define the order of execution.

$ ls /etc/rc2.d
README
S01motd
S13rpcbind
S14nfs-common
S16binfmt-support
S16rsyslog
S16sudo
S17apache2
S18acpid
...

All scripts in these directories are symbolic links to real startup scripts stored in /etc/init.d, simplifying management.

Managing Services

To restart a service, invoke its script in /etc/init.d, e.g.:

$ sudo /etc/init.d/apache2 restart

User Login Methods

After services start, the system presents three login options:

Console login: gettylogin (and PAM modules) reads /etc/passwd to start the user's shell.

SSH login: sshd replaces getty and starts the shell.

Graphical login: a display manager (e.g., gdm) starts the session after authentication.

Login Shell Initialization

The login shell reads /etc/profile (system‑wide) and then one of the user files ~/.bash_profile, ~/.bash_login, or ~/.profile, stopping after the first one found.

Non‑Login Shells

When a user opens a new terminal after logging in, a non‑login shell is started. It does not read the login files but loads ~/.bashrc, where most user customizations reside.

Ensuring .bashrc Is Executed

Debian’s ~/.profile contains logic to source ~/.bashrc if Bash is the shell:

if [ -n "$BASH_VERSION" ]; then
  if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
  fi
fi

If a ~/.bash_profile exists, it may bypass ~/.profile. Adding the following to ~/.bash_profile forces ~/.profile to run:

if [ -f ~/.profile ]; then
  . ~/.profile
fi

Why Bash Has Multiple Config Files

Historically, loading all configuration at once was slow, so Bash split settings: system‑wide in /etc/profile, inherited user settings in ~/.profile, and non‑inherited settings in ~/.bashrc. macOS also uses Bash, loading only ~/.bash_profile which then sources ~/.bashrc.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ShellinitDebianbootRunlevel
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.