Fundamentals 10 min read

Unlocking Linux File Systems: Inodes, Partitions, and How Files Really Work

This article explains Linux's hierarchical file system, detailing how the root directory, partitions, boot and super blocks, inodes, and data blocks interact to store and retrieve files, and it also covers file descriptors, sharing, and process forking.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Unlocking Linux File Systems: Inodes, Partitions, and How Files Really Work

Linux file management is organized as a tree: the root directory (/) at the top, intermediate directories as nodes, and files as leaves. A full path starts at the root and traverses directories to reach the target file.

Common operations such as opening, reading, and writing files rely on commands like cat, which displays a file’s contents in the terminal:

$cat test.txt

Understanding the underlying file system structure is essential for system programmers and helps ordinary users design better maintenance strategies.

Storage Device Partition

File systems store data on persistent storage devices (e.g., hard disks). These devices have an MBR for booting, followed by one or more partitions, each described by a partition table located outside the partitions.

Each Linux partition contains several key components:

The first part is the boot block, which assists the computer during startup. After the boot block comes the super block, storing file system metadata such as type, inode count, and block count.

Inodes follow the super block; they act as pointers to the data blocks that actually hold file contents. Each file has a unique inode containing pointers to its data blocks.

The final part consists of the data blocks where the file’s actual data resides.

Inode Overview

Files are organized in directories, and each file’s metadata (size, owner, permissions, timestamps) is stored in its inode. Commands like ls -l display this metadata. The inode number uniquely identifies a file within the file system.

When a file is opened, the kernel locates its inode, follows the pointers to the data blocks, and assembles the file’s contents in memory.

Inode Example

Resolving a path such as $cat /var/test.txt involves locating the inode for the root directory, then the inode for var, and finally the inode for test.txt. The stat command can be used to query a file’s inode number.

Reading a file means finding its inode, following its block pointers, and loading the data into memory; writing a file allocates a new inode, records it in the directory, and assigns free data blocks.

File Sharing

When a process opens a file, it receives a file descriptor, which indexes an entry in a per‑process file descriptor table. This entry points to a file table entry that references the inode and stores status flags and the current offset.

Each process has its own file descriptor array, but the underlying file table and inode can be shared, enabling concurrent reads or writes. After a fork, the child inherits the descriptor array while sharing the kernel’s file table and inode, which requires careful programming.

Summary

Linux uses an inode‑based file system where data is stored in blocks referenced by inodes, which also hold metadata. Understanding this structure is a crucial step toward mastering Linux operating system principles.

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.

linuxstoragefile systeminodePartition
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.