Creating Linux Filesystems with mke2fs (with examples)

Creating Linux Filesystems with mke2fs (with examples)

Introduction

The mke2fs command is used to create a Linux filesystem within a partition. It can be used to create filesystems with the ext2, ext3, and ext4 formats. In this article, we will explore eight different use cases of the mke2fs command with examples.

Use Case 1: Creating an ext2 Filesystem

Code:

mkfs.ext2 /dev/sdb1

Motivation:

Creating an ext2 filesystem is useful when compatibility with older Linux systems or minimalistic devices is required. The ext2 filesystem has been around since the early versions of the Linux kernel and does not include features such as journaling, which can be desirable in specific scenarios.

Explanation:

  • mkfs.ext2: The main command for creating an ext2 filesystem.
  • /dev/sdb1: The target partition for creating the filesystem.

Example Output:

mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks:
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Use Case 2: Creating an ext3 Filesystem

Code:

mkfs.ext3 /dev/sdb1

Motivation:

The ext3 filesystem is an enhanced version of ext2 that includes journaling capabilities. Journaling helps maintain filesystem consistency and recover from unexpected system shutdowns or power failures more efficiently.

Explanation:

  • mkfs.ext3: The command to create an ext3 filesystem.
  • /dev/sdb1: The target partition for the filesystem creation.

Example Output:

mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks:
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Use Case 3: Creating an ext4 Filesystem

Code:

mkfs.ext4 /dev/sdb1

Motivation:

The ext4 filesystem is the most recent and widely used of the ext family of filesystems. It includes various enhancements over ext3, such as larger file system sizes, improved performance, and support for new features like extents (contiguous file allocations) and delayed allocation.

Explanation:

  • mkfs.ext4: The command for creating an ext4 filesystem.
  • /dev/sdb1: The target partition for the filesystem creation.

Example Output:

mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks:
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Use Case 4: Creating an ext2 Filesystem with Specific Block Size

Code:

mkfs.ext2 -b 4096 /dev/sdb1

Motivation:

Specifying a specific block size can be useful in certain situations, such as optimizing disk I/O performance for large files or improving overall efficiency for specific workloads.

Explanation:

  • mkfs.ext2: The command for creating an ext2 filesystem.
  • -b 4096: Specifies the block size as 4096 bytes.
  • /dev/sdb1: The target partition for the filesystem creation.

Example Output:

mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 102400 4k blocks and 25600 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks:
	32768, 98304

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Use Case 5: Creating an ext3 Filesystem with Reserved Space Percentage

Code:

mkfs.ext3 -m 5 /dev/sdb1

Motivation:

Setting a reserved space percentage can be advantageous to allow root user processes to continue writing to the filesystem even if it becomes full. The reserved space helps avoid system crashes or other unexpected system behavior.

Explanation:

  • mkfs.ext3: The command for creating an ext3 filesystem.
  • -m 5: Specifies that 5% of the filesystem should be reserved for privileged processes.
  • /dev/sdb1: The target partition for the filesystem creation.

Example Output:

mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks:
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Use Case 6: Creating an ext4 Filesystem with Journal Checksums Enabled

Code:

mkfs.ext4 -O ^metadata_csum /dev/sdb1

Motivation:

Disabling the journal checksums can be beneficial in certain situations, such as reducing write access time overhead in high-throughput scenarios. However, it increases the vulnerability to silent data corruption caused by failing storage devices or other system issues.

Explanation:

  • mkfs.ext4: The command for creating an ext4 filesystem.
  • -O ^metadata_csum: Specifies that journal checksums should be disabled.
  • /dev/sdb1: The target partition for the filesystem creation.

Example Output:

mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks:
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Use Case 7: Creating an ext2 Filesystem with Specific Raid Stripe Size

Code:

mkfs.ext2 -E stride=32,stripe-width=64 /dev/sdb1

Motivation:

Specifying the RAID stripe size is beneficial when the filesystem spans multiple disks or partitions in a RAID configuration. By aligning the filesystem blocks with the stripe boundaries, you can enhance read and write performance.

Explanation:

  • mkfs.ext2: The command for creating an ext2 filesystem.
  • -E stride=32,stripe-width=64: Specifies the RAID stripe size with a stride of 32 filesystem blocks and a stripe width of 64 filesystem blocks.
  • /dev/sdb1: The target partition for the filesystem creation.

Example Output:

mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks:
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Use Case 8: Creating an ext4 Filesystem with 64-bit Support

Code:

mkfs.ext4 -O 64bit /dev/sdb1

Motivation:

Enabling 64-bit support allows for larger filesystem sizes and improved performance, especially for systems handling very large files or storage devices.

Explanation:

  • mkfs.ext4: The command for creating an ext4 filesystem.
  • -O 64bit: Specifies 64-bit support should be enabled.
  • /dev/sdb1: The target partition for the filesystem creation.

Example Output:

mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 204800 1k blocks and 51200 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks:
	8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Conclusion

In this article, we have explored eight different use cases of the mke2fs command, which allows creating Linux filesystems with ext2, ext3, and ext4 formats. Each use case provides a specific scenario, motivation, explanation of the arguments used, and an example output when executing the command. By using these examples, you can effectively create Linux filesystems tailored to your specific requirements.

Related Posts

How to use the command cloc (with examples)

How to use the command cloc (with examples)

The command cloc is a tool used for counting lines of source code and comments.

Read More
How to use the command 'peerindex' (with examples)

How to use the command 'peerindex' (with examples)

The ‘peerindex’ command is a tool that allows users to inspect the MRT TABLE_DUMPV2 Peer Index Table.

Read More
How to use the command 'dunstctl' (with examples)

How to use the command 'dunstctl' (with examples)

The dunstctl command is a control command for the dunst notification daemon.

Read More