Linux works in layers. The kernel sits on the hardware and manages memory, processes and devices, a distribution packages that kernel with the software around it, and the shell is the program that turns the commands you type into requests to the system.
Strictly, "Linux" means only the kernel. The kernel documentation describes it as "a clone of the operating system Unix, written from scratch by Linus Torvalds". The complete system you install and use is a distribution built around that kernel. The sections below follow a machine from power-on to a shell prompt.
What is the Linux kernel?
The kernel is the one program that runs with full control of the hardware. Everything else asks it for resources. It starts programs and keeps them apart, hands out memory, and talks to disks, network cards and other devices through drivers.
It is not tied to one kind of computer. The kernel documentation says Linux was first developed for 32-bit x86 PCs and now runs on many architectures, including ARM, PowerPC and SPARC. It is distributed under the GNU General Public License version 2.
To see which kernel version you are running, use:
uname -r
Example output (yours will differ):
6.1.0-18-amd64
How do programs talk to the kernel?
Through system calls. The syscalls(2) manual page calls the system call "the fundamental interface between an application and the Linux kernel". Opening a file, starting a process, sending data over a network socket: each one ends up as a system call.
Programs rarely make these calls by hand. The same page says system calls are "generally not invoked directly, but rather via wrapper functions in glibc". The wrapper puts the arguments in the right registers and enters the kernel. If the call fails, the kernel returns an error number, and the wrapper stores it in errno and returns -1 to your program. That is where messages such as No such file or directory come from: the program looked up the error number and printed its text.
This split is the core of how Linux works. Ordinary programs run in user space, where a crash only takes down that program. Only the kernel touches hardware, and it does so on behalf of programs that ask through system calls.
What happens when a Linux computer boots?
The boot(7) manual page describes the sequence in these stages:
- Firmware. After power-on, control goes to a program stored in read-only memory, often called the BIOS. It runs self-tests and reads settings from non-volatile memory, including which device holds the operating system loader.
- Boot loader. The loader finds the kernel, loads it and runs it. On Linux this is usually GRUB.
- Kernel. It initialises hardware through drivers and mounts the root filesystem. Then it creates the first user-space process, which gets process ID 1.
- Init. Process 1 starts everything else: the services, the login prompt, the graphical session.
The page describes the classic System V init, where /sbin/init reads /etc/inittab and runs scripts from /etc/init.d. It also says that many widely used systems now use systemd instead, which takes "a related but fundamentally different approach". Which one you have depends on the distribution. To see the name of process 1 on your machine:
ps -p 1 -o comm=
On a systemd-based distribution this prints systemd. For more on listing processes, see how to read ps aux output.
What is a Linux distribution?
A distribution (distro) is a complete operating system assembled around the Linux kernel. The maintainers pick a kernel version, an init system, the C library, a shell, command-line tools and a package manager, then test them together and publish updates. Many distributions also include a desktop environment.
That is why "Linux" can look so different between machines. A server distribution may have no graphical interface at all, while a desktop one boots straight to a login screen. The kernel underneath is the same project.
Distributions describe themselves in a standard file. The os-release(5) page says /etc/os-release (or /usr/lib/os-release) holds operating system identification as shell-compatible variable assignments. To read it:
cat /etc/os-release
Example output from an Ubuntu system (version fields vary):
NAME="Ubuntu"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 22.04.4 LTS"
VERSION_ID="22.04"
| Field | Meaning according to os-release(5) |
|---|---|
NAME | The operating system name without a version, suitable for showing to users |
ID | A lowercase identifier without version information, meant for scripts |
ID_LIKE | Identifiers of closely related systems, closest first (Ubuntu lists debian) |
VERSION_ID | The version number without name or codename |
PRETTY_NAME | A user-facing name that can include the version or codename |
Scripts that must behave differently per distribution should read ID and VERSION_ID, with ID_LIKE as a fallback, as the page recommends.
What is the Linux shell?
The shell is the program that reads what you type and runs it. The Bash manual defines Bash as "the shell, or command language interpreter, for the GNU operating system", and says that "at its base, a shell is simply a macro processor that executes commands". It works both as an interactive prompt and as a programming language, so a sequence of commands saved in a file becomes a script.
When you type ls /tmp, the shell splits the line into a command and its argument, finds the ls program, and asks the kernel to start it as a new process. The kernel loads the program, it runs and prints its output, and control returns to the shell prompt. The shell is an ordinary user-space program, not part of the kernel. You can replace it, and Bash is only the most common choice. To see which shell you are using:
echo $SHELL
Example output:
/bin/bash
$SHELL holds your login shell, which is not always the shell you are typing into if you started another one inside it. The commands you run from the shell are covered in basic Linux commands for beginners.
How does Linux handle files and permissions?
Linux follows the Unix idea that most things are reached through the filesystem: one tree that starts at /, with every file owned by a user and a group. The kernel checks those owners and permission bits each time a process opens a file, so access control is enforced by the kernel and not by the programs themselves. The mechanics of the permission bits are in Linux file permissions and chmod explained.
Putting the layers together
When you press the power button, firmware hands over to a boot loader, which starts the kernel, which starts process 1, which starts your services and a login. After you log in, a shell runs. Each command you type becomes a new process that uses system calls to reach the kernel, and the kernel reaches the hardware. The distribution decides which specific programs fill each role, which is why Ubuntu, Fedora and Debian feel alike but are not identical.
Common mix-ups
- "Linux" versus "a distro". A kernel update and a distribution upgrade are different things. The first changes the engine; the second replaces most of the software around it.
- Shell versus terminal. The terminal is the window that displays text. The shell is the program running inside it.
- Linux versus Unix. Linux follows the Unix model and aims at POSIX compliance, but it was written from scratch.
Frequently asked questions
- Is Linux an operating system or a kernel?
- Strictly, Linux is the kernel. The kernel documentation describes it as a clone of Unix written from scratch by Linus Torvalds. What people install and call Linux is a distribution: the kernel plus a shell, system libraries, tools and a package system chosen by the distribution's maintainers.
- What is the difference between Linux and a Linux distribution?
- Linux is one component, the kernel. A distribution such as Debian, Fedora or Ubuntu bundles that kernel with the init system, the C library, the shell, command-line tools, a package manager and usually a desktop. Two distributions can run the same kernel version and still behave quite differently day to day.
- Is Linux the same as Unix?
- No, but it is closely modelled on it. The kernel documentation calls Linux a clone of Unix that aims towards POSIX and Single UNIX Specification compliance. It shares the Unix design (processes, files, a shell, system calls) without being derived from the original Unix source code.
- Is Linux free to use and modify?
- Yes. The kernel is distributed under the GNU General Public License version 2, which lets you run, study, modify and redistribute it under the licence terms. Individual distributions include software under many other licences, so check the terms of anything you plan to redistribute.