Bootstrap FreeKB - Linux Commands - mke2fs (create a file system)
Linux Commands - mke2fs (create a file system)

Updated:   |  Linux Commands articles

Formatting a storage device typically involves the following steps. This article includes the directions for steps 1 and 2.

  1. Create one or more partitions (see fdiskgdiskparted)
  2. Format each partition with a file system (see mkfs and mke2fs)
  3. Mount the partition in /etc/fstab

 

Before using the mkfs command to create a file system, the fsck command can be used to determine if the partition has a file system type.

fsck -N /dev/sda1

 

If the partition does have a file system type, something like this should be returned. In this example, the /dev/sda1 partition has the XFS file system.

Even if the partition already has a file system, the mkfs command can be used to change the partition to use some other file system.

[/usr/sbin/fsck.xfs (1) -- /boot] fsck.xfs /dev/sda1

 

The mke2fs command can be used to assign a new file system to a partition or to change the partition to use some other file system. In this example, either of these commands will configure the /dev/sda2 partition to use the ext4 file system.

mke2fs.ext4 /dev/sda2

 

Or like this.

mke2fs --type ext4 /dev/sda2

 

It is somewhat common to use the -j option, which uses journaling and the ext3 file system.

mke2fs -j /dev/sda2

 

Following are some of the more popular filesystem types used by Linux.

  • ext2 (second extended file system)
  • ext3 (third extended file system)
  • ext4 (fourth extended file system)
  • xfs (extended file system)
  • lvm (logical volume)
  • raid

 

You are now ready to mount the partition /etc/fstab so that the partition is available at boot.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 041706 in the box below so that we can be sure you are a human.