4.2.35 · HinglishOperating Systems

ext4 structure — superblock, block groups, inodes

1,983 words9 min readRead in English

4.2.35 · Coding › Operating Systems


WHY does ext4 need structure at all?

WHY block groups? Spinning disk pe head ko door jump karana slow hota hai. Agar ek file ka metadata (inode) aur uske data blocks ek hi region mein hon, toh head mushkil se hilaata hai. ext4 yeh locality idea SSDs pe bhi rakhta hai kyunki yeh fragmentation bhi kam karta hai aur allocation bitmaps ko chhota rakhta hai.


Teen layers

1. Superblock — "filesystem ka ID card"

Pehle 1024 bytes reserved hain (boot sector), isliye primary superblock byte offset 1024 pe rehta hai.

2. Block group — "ek self-contained mini-filesystem"

Figure — ext4 structure — superblock, block groups, inodes

3. Inode — "file ke baare mein sab kuch, naam chhod ke"


HOW ek path data tak resolve hota hai (poori chain)

/home/ada/x.txt padhne ke liye:

  1. Inode 2 hamesha root / hota hai. Uska data block padho → directory listing → home dhundho → inode #.
  2. Woh inode padho → uska data → ada dhundho → inode #.
  3. Woh inode padho → x.txt dhundho → inode #.
  4. Woh inode padho → uske extents → physical data blocks → bytes.

Worked examples


Common mistakes


Flashcards

What does the superblock store?
Global filesystem info: total blocks/inodes, block size, blocks-per-group, free counts, UUID, mount count, magic number 0xEF53.
Why are there backup superblocks?
Superblock critical metadata hai; agar primary (offset 1024) corrupt ho, toh fsck selected block groups mein stored backups se restore karta hai.
Why does ext4 split the disk into block groups?
Metadata ko uske data ke paas rakhne ke liye (locality/kam seek), bitmap size bound karne ke liye, aur fragmentation kam karne ke liye.
What does the block bitmap track and how big is it?
Group mein har block ke liye ek bit, used/free; yeh exactly ek block hota hai, isliye ek group 8B blocks hold karta hai (B = block size in bytes).
Blocks per group for 4 KiB blocks?
8 × 4096 = 32768 blocks = 128 MiB per group.
What is an inode and what does it NOT contain?
Ek fixed record (256 B) jisme file ka metadata + data-block locations hain; isme filename nahi hota.
Where is the filename stored?
Directory entry mein, jo name → inode number map karti hai.
What makes hard links possible?
Multiple directory entries same inode number pe point karti hain; inode mein link count hota hai, data tab free hota hai jab count 0 ho.
What are ext4 extents and why are they better?
Ek record jo logical blocks ki contiguous range ko physical blocks pe map karta hai; bade files ke liye ext2/3 indirect pointers se kaafi zyada compact/fast.
Which inode is the root directory?
Inode 2 (inodes 1–10 reserved hain).
Group of inode N with I inodes/group?
floor((N-1)/I); 1 isliye subtract karte hain kyunki inode numbers 1-based hain.
What does df -i show?
Inode usage (disk space se alag ek fixed pool), mkfs time pe set hota hai.

Recall Feynman: ek 12-saal ke bachche ko samjhao

Socho ek bada parking lot (disk) identical chunks of spaces (block groups) mein baanta gaya hai. Entrance pe ek sign (superblock) hai jo bata raha hai lot kitna bada hai aur rules kya hain. Har chunk mein ek chhota-sa checklist (bitmap) hai jo dikhata hai kaun-se spaces taken hain. Har gaadi (file) ka ek ID card (inode) hota hai jo bata hai kaun uska owner hai, kab parking ki, aur exactly kaun-se spaces use karta hai — lekin card pe gaadi ka nickname nahi hota. Nicknames ek phone book (directory) mein hain jo kehti hai "Ada ki gaadi → ID card #4732." Isliye ek gaadi ke do nicknames ho sakte hain: do phone-book lines, ek ID card.

Connections

  • Operating Systems — filesystems Virtual File System layer aur block device ke beech mein hote hain.
  • ext2 vs ext3 vs ext4 — extents aur journaling ext4 ke bade upgrades hain.
  • Hard links vs Symbolic links — name/inode separation se explain hota hai.
  • Disk Scheduling — block-group locality seeks kam karta hai.
  • Bitmaps for allocation — same trick Memory Management free-frame tracking mein bhi use hoti hai.
  • Journaling — ext4 ka crash consistency layer is structure ke upar.

Concept Map

structured by

split into

described by

holds block size, counts, magic 0xEF53

replicated as

reduces seek via locality

contains

contains

contains

caps size to 8B blocks

stores

points to

Raw block device N blocks

ext4 filesystem

Block groups

Superblock

Block bitmap 1 block

Inode bitmap

Inode table

Data blocks

Inode per file

Superblock backups