How Does Linux Boot? A Step‑by‑Step Guide to the Linux Startup Process
This article walks through the Linux boot sequence on Debian, covering kernel loading, the init process, runlevel selection, startup script execution, user login methods, login shell initialization, and the role of non‑login shells, with command examples and diagrams.
1. Load Kernel
After the operating system takes control of the hardware, it reads the kernel file from the /boot directory.
Example /boot directory listing on a typical machine:
$ ls /boot
config-3.2.0-amd64
config-3.2.0-amd64
grub
initrd.img-3.2.0-amd64
initrd.img-3.2.0-amd64
System.map-3.2.0-amd64
System.map-3.2.0-amd64
vmlinuz-3.2.0-amd64
vmlinuz-3.2.0-amd642. Start Init Process
Once the kernel is loaded, it runs the first program /sbin/init, which initializes the system environment. The init process receives PID 1, and all other processes are its descendants.
3. Determine Runlevel
Programs that start automatically at boot are called daemons. Init runs them according to the system’s runlevel. Linux defines seven runlevels (0‑6); Debian’s default runlevel is 2, which corresponds to multi‑user mode.
Init reads /etc/inittab. The line id:2:initdefault: sets the default runlevel to 2.
Each runlevel has a directory /etc/rcN.d that contains scripts to start (prefix S) or stop (prefix K) services. The numeric suffix determines the order; lower numbers run earlier.
$ ls /etc/rc2.d
README
S01motd
S13rpcbind
S14nfs-common
S16binfmt-support
S16rsyslog
S16sudo
S17apache2
S18acpid
...4. Load Startup Programs
All entries in /etc/rcN.d are symbolic links to real scripts in /etc/init.d. Init executes these scripts in order.
Example of the links in /etc/rc2.d:
$ ls -l /etc/rc2.d
README
S01motd -> ../init.d/motd
S13rpcbind -> ../init.d/rpcbind
S14nfs-common -> ../init.d/nfs-common
S16binfmt-support -> ../init.d/binfmt-support
S16rsyslog -> ../init.d/rsyslog
S16sudo -> ../init.d/sudo
S17apache2 -> ../init.d/apache2
S18acpid -> ../init.d/acpid
...To restart a service manually, invoke its script in /etc/init.d, e.g.:
$ sudo /etc/init.d/apache2 restart5. User Login
After startup programs finish, the system presents a login prompt. Three login methods are supported:
Console (getty → login)
SSH (sshd)
Graphical login (display manager, e.g., gdm)
6. Enter Login Shell
Debian’s default shell is Bash. For console and SSH login, Bash reads /etc/profile and then the first existing file among ~/.bash_profile, ~/.bash_login, or ~/.profile. For graphical login, only /etc/profile and ~/.profile are read.
~/ .bash_profile
~/ .bash_login
~/ .profile7. Open Non‑Login Shell
When a user opens a new terminal, a non‑login shell starts; it does not read /etc/profile or ~/.profile but reads ~/.bashrc. Debian ensures ~/.bashrc is sourced from ~/.profile:
if [ -n "$BASH_VERSION" ]; then
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fiSimilarly, adding the following to ~/.bash_profile guarantees ~/.bashrc runs even when ~/.bash_profile exists:
if [ -f ~/.profile ]; then
. ~/.profile
fiThus, regardless of the login method, user customizations placed in ~/.bashrc are applied.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Linux Cloud Computing Practice
Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
