Cyberworld-builders / academy

A designated place for educational and training docs, materials and exercises. Also a place to track issues and progress and a lab for code that can be potentially used elsewere.
0 stars 0 forks source link

Verses - Linux - ext4 #33

Open jaylong255 opened 3 months ago

jaylong255 commented 3 months ago

Ext4 is a journaling file system widely used in Linux operating systems. It is an evolution of the Ext3 file system and offers several improvements in terms of performance, reliability, and scalability. Key features of Ext4 include:

  1. Large File System Support: Ext4 supports large file systems and files, with a maximum individual file size of 16 TiB and a maximum file system size of 1 EiB.

  2. Extent-Based Storage: Ext4 uses extents, which improve large file performance and reduce fragmentation compared to the traditional block mapping used by Ext3.

  3. Delayed Allocation: This feature improves performance and reduces fragmentation by delaying block allocation until data is flushed to disk.

  4. Backward Compatibility: Ext4 is backward compatible with Ext3, allowing users to mount an Ext3 file system as Ext4 and benefit from some of its improvements without requiring a full upgrade.

  5. Persistent Preallocation: Ext4 supports persistent preallocation of on-disk space for files, which is useful for applications like databases that need to ensure contiguous storage.

  6. Journal Checksumming: Ext4 includes checksums in the journal to improve reliability by detecting and handling data corruption in the journal.

  7. Multiblock Allocation: This feature allows Ext4 to allocate multiple blocks in a single operation, improving performance for large files.

  8. Faster File System Checks: The design of Ext4 allows for faster file system checks and repairs compared to its predecessors.

Overall, Ext4 is a robust and versatile file system suitable for a wide range of applications, from personal computing to enterprise-level deployments.


Here's an example of how to create and use an Ext4 file system on a Linux system:

  1. Create a Partition: First, you need a partition to format as Ext4. You can use tools like fdisk or gparted to create a new partition.

    Example using fdisk:

    sudo fdisk /dev/sdX

    Follow the interactive prompts to create a new partition. Replace /dev/sdX with the appropriate device identifier (e.g., /dev/sda).

  2. Format the Partition as Ext4: Once the partition is created, format it with the Ext4 file system using the mkfs.ext4 command.

    sudo mkfs.ext4 /dev/sdX1

    Replace /dev/sdX1 with the appropriate partition identifier (e.g., /dev/sda1).

  3. Mount the Ext4 File System: Create a mount point and mount the newly formatted Ext4 partition.

    sudo mkdir /mnt/mydata
    sudo mount /dev/sdX1 /mnt/mydata

    Replace /dev/sdX1 with your partition identifier and /mnt/mydata with your desired mount point.

  4. Verify the Mount: Verify that the file system is mounted correctly.

    df -h

    You should see an entry for /dev/sdX1 mounted at /mnt/mydata.

  5. Set Up Persistent Mounting: To ensure the file system is mounted automatically on boot, add an entry to /etc/fstab.

    sudo nano /etc/fstab

    Add the following line to the file:

    /dev/sdX1  /mnt/mydata  ext4  defaults  0  2

    Save and exit the editor. This entry will ensure the partition is mounted at /mnt/mydata every time the system boots.

  6. Basic File Operations: You can now perform basic file operations on the mounted Ext4 file system.

    sudo touch /mnt/mydata/testfile
    sudo ls -l /mnt/mydata

    This will create a new file named testfile in the /mnt/mydata directory and list the contents of the directory.

By following these steps, you've created an Ext4 file system, mounted it, and performed basic file operations on it.