Operating Systems Concepts & Design
Understanding the relationship between sectors, blocks, and inodes is key to grasping how a computer moves from raw magnetic or flash storage to a searchable file system. While they all deal with data storage, they exist at different layers of the “stack.”
A sector is the smallest physical storage unit on a hard drive platter or flash chip. It is defined by the hardware manufacturer.
A block (sometimes called a “file system block” or “cluster”) is a logical unit used by the Operating System (OS) to manage data. It is a group of one or more contiguous sectors.
An inode (index node) is a data structure in a Unix-style file system that describes a file or directory. It does not contain the actual contents of the file, but rather the “directions” to find it.
ls -i in a terminal.| Feature | Sector | Block | Inode |
|---|---|---|---|
| Layer | Hardware (Physical) | OS (Logical) | File System (Metadata) |
| Defined By | Manufacturer (HDD/SSD) | Operating System / Format | File System (Ext4, XFS, etc.) |
| Stores | Raw binary data | User data (parts of files) | File info and block pointers |
| Addressable | By LBA (Logical Block Address) | By Block Number | By Inode Number |
When you ask to read a file called notes.txt:
notes.txt.To see how these concepts live on your actual system, you can use a few standard Linux utilities. Since you are likely working with a typical Linux distribution, these commands will help you “see” the abstraction layers we discussed.
ls and statThe ls command normally hides the inode number, but the -i flag reveals it. The stat command provides even more metadata stored within that inode.
ls -i /etc/passwdThe first number in the output is the Inode Index.
stat /etc/passwdTo see the logical Block size of your file system and how many total Inodes your disk can support, use tune2fs (for Ext4) or df.
sudo tune2fs -l /dev/sda1 | grep "Block size"Note: Replace /dev/sda1 with your actual partition.
df -iTo see the hardware layer—the Sectors—you need to query the block device directly using fdisk.
sudo fdisk -lSector size (logical/physical): 512 bytes / 4096 bytes.| If you want to see… | Use this command |
|---|---|
| Inode Number | ls -i [file] |
| Full Metadata | stat [file] |
| Inode Capacity | df -i |
| Logical Block Size | blockdev --getbsz /dev/[device] |
| Physical Sector Size | smartctl -a /dev/[device] or fdisk -l |
TODO: how hard links vs. symbolic links interact with these inode numbers
To view file system information for a specific partition in Linux, you generally use tools that query the superblock (for metadata like block size and inode counts) or tools that query the kernel’s mount table (for usage and mount options).
The command you choose often depends on whether the partition is currently mounted or unmounted.
df and findmntIf the partition is active and mounted, these are the quickest ways to see high-level stats.
df -h /dev/sda1 (Human-readable space)
df -i /dev/sda1 (Inode usage)findmnt /dev/sda1
This shows the target mount point, the file system type (ext4, xfs, btrfs), and options like rw (read-write) or relatime.tune2fsIf you are using the standard Linux Ext family, tune2fs provides the most exhaustive “under the hood” data.
sudo tune2fs -l /dev/sda1fsck (file system check).has_journal, extent, or 64bit.xfs_infoIf you are on an Enterprise Linux system (like RHEL or CentOS) using XFS, tune2fs won’t work.
xfs_info /mnt/data (Note: XFS tools usually require the mount point, not the device path).lsblk and blkidTo see how the partition relates to the physical hardware and its unique identifiers.
blkid /dev/sda1
Crucial for editing /etc/fstab so the system mounts the correct disk even if the drive letter changes.lsblk -f
Provides a clean, tree-like view of every partition, its file system type, UUID, and mount point.| If you need to know… | Use this command |
| — | — |
| Is it Ext4 or XFS? | lsblk -f |
| How many Inodes are left? | df -i |
| What is the logical Block Size? | sudo tune2fs -l /dev/xxx |
| **Is the disk Read-Only?** | findmnt |
| **The UUID for fstab?** | blkid` |
It is the most critical metadata structure in the filesystem, containing the “magic number” (a unique hexadecimal value that identifies the filesystem type), the block size, the total number of blocks, and the status of the drive.
Because the superblock is so vital, the filesystem stores multiple redundant copies of it across the partition. If the primary one at the beginning of the disk is corrupted, the system uses these backups to recover.
dumpe2fs (for Ext2/Ext3/Ext4)The dumpe2fs utility is the standard way to dump the superblock information for the Ext family of filesystems.
*The `-h` flag ensures you only get the "header" (superblock) info and not a list of every single block group.*
* **Look for the "Magic number":** In the output, look for `Filesystem magic number: 0xEF53`. This hex code confirms it is an Ext2/3/4 filesystem.
---
## 2. Using `tune2fs`
While `tune2fs` is often used to *change* parameters, its list function is excellent for viewing the primary superblock data in a clean format.
* **Command:**
```bash
sudo tune2fs -l /dev/sda1
This will show you the block size, inode count, and “Filesystem features” (like has_journal or extents).
If your filesystem is corrupted and won’t mount, you need to find where the backup magic blocks are located.
* **CRITICAL:** The `-n` flag is "dry-run" mode. It tells the utility to pretend it’s formatting the drive and show you where it *would* place the superblocks. **Never run this without `-n` on a drive with data.**
* The output will provide a list of block numbers (e.g., 32768, 98304) where backups reside.
---
## 4. The Hex Dump Method (Universal)
If you want to see the "Magic Number" at the raw byte level without relying on filesystem-specific tools, you can use `dd` and `hexdump`.
* **Command:**
```bash
sudo dd if=/dev/sda1 bs=1024 skip=1 count=1 | hexdump -C
0x38. For Ext4, you should see 53 ef (the bytes are swapped due to little-endianness).| Filesystem | Magic Number (Hex) |
|---|---|
| Ext2/3/4 | 0xEF53 |
| XFS | 0x58465342 (ASCII for “XFSB”) |
| Btrfs | 0x91236835 |
| NTFS | 0xEB52904E |