AICollection Help

ext2 (Second Extended File System)

ext2 is a widely used file system for Linux, introduced as an improvement over the ext file system. It supports large files and volumes, and while it lacks journaling, its simplicity and efficiency make it suitable for certain use cases like USB drives and embedded systems. Here's a detailed look at the ext2 structure and its features:

Structure of the ext2 File System

1. Boot Sector:

The boot sector (or superblock) contains metadata about the file system, including:

  • Inode Count:

    • Total number of inodes in the file system.

  • Block Count:

    • Total number of blocks in the file system.

  • Reserved Block Count:

    • Number of blocks reserved for the root user.

  • Free Block Count:

    • Number of free blocks available.

  • Free Inode Count:

    • Number of free inodes available.

  • First Data Block:

    • Block number of the first data block.

  • Block Size:

    • Size of each block (e.g., 1024, 2048, or 4096 bytes).

  • Blocks Per Group:

    • Number of blocks in each block group.

  • Inodes Per Group:

    • Number of inodes in each block group.

  • ** Mount Time and Write Time:

    • Timestamps of the last mount and write operations.

2. Block Groups:

The ext2 file system is divided into block groups, each containing:

  • Superblock Copy:

    • Backup of the file system's metadata.

  • Group Descriptor Table:

    • Describes the layout of the block group.

  • Block Bitmap:

    • Tracks the allocation status of blocks.

  • Inode Bitmap:

    • Tracks the allocation status of inodes.

  • Inode Table:

    • Contains metadata for each file and directory.

  • Data Blocks:

    • Stores the actual file and directory data.

3. Inode Structure:

Each file or directory is represented by an inode, which contains:

  • File Type and Permissions:

    • Indicates if it's a file, directory, or special type.

  • File Size:

    • Size of the file in bytes.

  • Timestamps:

    • Creation, modification, and access times.

  • Direct and Indirect Pointers:

    • Point to the data blocks containing the file's content.

4. Directory Structure:

Directories are implemented as files containing a list of directory entries. Each entry includes:

  • Inode Number:

    • Points to the inode representing the file or subdirectory.

  • Entry Length:

    • Length of the directory entry.

  • File Name Length:

    • Length of the file name.

  • File Name:

    • The actual name of the file or subdirectory.

Features of ext2

  • Large File and Volume Support:

    • Supports files up to 2 TB and volumes up to 32 TB (with appropriate block sizes).

  • Efficient Space Allocation:

    • Uses block groups to minimize fragmentation.

  • Sparse Superblocks:

    • Reduces overhead by storing superblock backups only in select block groups.

  • Customizable:

    • Allows tuning of block sizes and reserved space for specific use cases.

Commands to Analyze ext2 File Systems

  • fsck.ext2:

    • Checks and repairs ext2 file systems.

  • dumpe2fs:

    • Displays detailed information about an ext2 file system.

  • tune2fs:

    • Adjusts tunable file system parameters (e.g., reserved blocks).

  • e2label:

    • Sets or retrieves the volume label of an ext2 file system.

  • blkid:

    • Displays file system type and UUIDs for ext2 partitions.

Example

# Check and repair an ext2 partition fsck.ext2 /dev/sdX # Display detailed file system information dumpe2fs /dev/sdX # Adjust reserved block percentage tune2fs -m 1 /dev/sdX # Assign a new label to the partition e2label /dev/sdX MyVolume

ext2 remains relevant for specific use cases requiring simplicity and efficiency.

Last modified: 19 January 2025