Filesystem Administration  «Prev  Next»

Lesson 2 Ext2 configuration, part 1
Objective Use the mke2fs command to adjust the filesystem's block size.

mke2fs Command

The `mke2fs` command is still used in Red Hat Linux. It is used to create an ext2, ext3, or ext4 file system on a block device. Ext4 is the default file system for Red Hat Enterprise Linux (RHEL), so the `mke2fs` command is commonly used to format new partitions and disks.
To create an ext4 file system using the `mke2fs` command, you would run the following command:
mke2fs -t ext4 /dev/sdb1

This would create an ext4 file system on the device `/dev/sdb1`.
The `mke2fs` command also has a number of other options that can be used to control the size and features of the file system. For more information, please see the `man` page for the `mke2fs` command.
Here are some examples of when you might use the `mke2fs` command in Red Hat Linux:
  1. When you are installing a new operating system and need to format the partition where the operating system will be installed.
  2. When you are adding a new disk to your system and need to create a file system on it.
  3. When you are resizing a partition and need to create a new file system on the newly resized space.
  4. When you are creating a new logical volume using LVM and need to create a file system on it.

Although the `mke2fs` command is still used in Red Hat Linux, there are other file system options available, such as XFS and Btrfs. These file systems offer additional features and performance benefits, so you may want to consider using them instead of ext4 for some applications.
Linux provides a number of tools to configure and optimize filesystems. These tools, part of the e2fsprogs package, provide administrators with the functionality they need to get the most out of their Linux filesystems.
The e2fsprogs package provides the following tools.
  1. mke2fs
  2. tune2fs
  3. dumpe2fs
  4. debugfs

We will explore mke2fs in this lesson and the others in the following lesson.
"block size" is "the number of bytes allocated to individually accessible units in the ext2 filesystem."

mke2fs

Use the mke2fs command with the -b option to adjust the ext2 filesystem's block size. The block size should match the filesystem's expected usage, because block size directly impacts disk read and write performance. Filesystems that have frequent, large file I/O operations, such as partitions containing executable programs, will perform better when the block size of the filesystem is larger than the default 1024 bytes. A block size of 4096 bytes is typically used.
When using these larger block sizes, each lookup into the filesystem retrieves more data. Unfortunately, if these files aren't exact multiples of the block size, more disk space will be wasted inside each block. Filesystems that have many, small file I/O operations, such as partitions containing temporary files, will perform better with a smaller block size, such as 1024 bytes. In this scenario, the smaller files and smaller block size reduces wasted bytes at the end of blocks while not significantly affecting performance.
To use mke2fs to adjust the block size, provide the -b parameter and the partition name. For example, to adjust the /dev/hda5 partition to 2048 bytes, use mke2fs -b 2048 /dev/hda5.
Block size: Block size is the number of bytes allocated to individually accessible units in the ext2 filesystem.
The command mke2fs is destructive. mke2fs places a new, formatted filesystem onto the partition. If you mistakenly type the wrong partition name, you will overwrite all existing data!

Question: Enter the command to format /dev/hdb3 with a block size of 1024 bytes.
Answer:
mke2fs -b 1024 /dev/hdb3

The next lesson discusses the use of tune2fs, dumpe2fs, and debugfs.