mke2fs: command not found

mke2fs is a utility that creates an ext2, ext3, or ext4 file system inside a partition on a Linux-based operating system. It is used to format a disk partition and make it ready for use as a Linux file system. The mke2fs command creates the file system structure, such as the superblock and inode tables, which are required for the proper functioning of the file system.

At its simplest, the command is used as

# mke2fs partition

such as:

# mke2fs /dev/hdc4

Here are some of the most useful options for mke2fs:

  • -c — This option checks for bad blocks during file system creation.
  • -N — This option overrides the default number of inodes created. (The default number is usually agood choice, but you might need to use this option to allow additional useable disk space.)
  • -m — This option frees up some space on the disk, but you do so at your peril. By default, the system allocates 5% of the blocks to the super-user—to be used in file recovery during fsck. You can lower that allocation, but you might not leave enough blocks for fsck to recover enough files.
  • -L — This option gives the volume a label, which is useful if you need to be reminded what the filesystem is used for; it also provides some flexibility in identifying volumes in /etc/fstab.
  • -S — This option is a last-ditch effort for recovering a broken file system; it writes only the superblock and descriptors, leaving the information in the inodes unchanged. Always run fsck after using this option.

If you encounter the below error while running the command mke2fs:

mke2fs: command not found

you may try installing the below package as per your choice of distribution:

Distribution Command
Debian apt-get install e2fsprogs
Ubuntu apt-get install e2fsprogs
Alpine apk add e2fsprogs
Arch Linux pacman -S e2fsprogs
Kali Linux apt-get install e2fsprogs
CentOS yum install e2fsprogs
Fedora dnf install e2fsprogs
OS X brew install e2fsprogs
Raspbian apt-get install e2fsprogs

mke2fs Command Examples

1. To create a file system on a device:

# mke2fs /dev/sda2 

2. To specify the block size in bytes:

# mke2fs -b 1024 /dev/sda2 

3. To check the device for bad blocks:

# mke2fs -c /dev/sda2 

4. To set extended options for file system:

# mke2fs -E stride=stride-size
# mke2fs -E stripe-width=stripe-width
# mke2fs -E resize=max-online-resize
# mke2fs -E lazy_itable_init[= ]
# mke2fs -E test_fs

5. To Specify the size of fragments in bytes:

# mke2fs -f fragment-size 

6. To force mke2fs to create file system:

# mke2fs -F /dev/sda2 

7. To specify the number of blocks in a block group:

# mke2fs -g blocks-per-group 

8. To specify the number of block groups that will be packed together to create a larger virtual block group:

# mke2fs -G number-of-groups 

9. To specify the bytes/inode ratio:

# mke2fs -i bytes-per-inode 

10. To specify the size of each inode in bytes:

# mke2fs -I inode-size 

11. To create the ext3 journal using options specified on the command-line:

# mke2fs -J size=journal-size
# mke2fs -J device=external-journal 

12. To keep, do not attempt to discard blocks at mkfs time:

# mke2fs -K 

13. To read the bad blocks list from filename:

# mke2fs -l filename 

14. To set the volume label for the filesystem to new-volume-label:

# mke2fs -L new-volume-label 

15. To specify the percentage of the filesystem blocks reserved for the super-user:

# mke2fs -m reserved-blocks-percentage 

16. To set the last mounted directory for the filesystem:

# mke2fs -M last-mounted-directory 

17. To not actually create a filesystem, but display what it would do if it were to create a filesystem:

# mke2fs -n  

18. To overrides the default calculation of the number of inodes that should be reserved for the filesystem:

# mke2fs -N number-of-inodes 

19. To overrides the default value of the “creator operating system” field of the filesystem:

# mke2fs -o creator-os 

20. To create a filesystem with the given features:

# mke2fs -O dir_index
# mke2fs -O extent
# mke2fs -O filetype
# mke2fs -O flex_bg
# mke2fs -O has_journal
# mke2fs -O journal_dev
# mke2fs -O large_file
# mke2fs -O resize_inode
# mke2fs -O sparse_super
# mke2fs -O uninit_bg 

21. To quit execution:

# mke2fs -q 

22. To set the filesystem revision for the new filesystem:

# mke2fs -r revision 

23. To write superblock and group descriptors only:

# mke2fs -S 

24. To specify the filesystem type:

# mke2fs -t fs-type 

25. To specify how the filesystem is going to be used:

# mke2fs -T usage-type[,...] 

26. To create the filesystem with the specified UUID:

# mke2fs -U UUID 

27. For verbose execution:

# mke2fs -v 

28. To print the version info:

# mke2fs -V 
Related Post