Basics of mke2fs command in Linux with examples
Last Updated :
11 Jul, 2022
mke2fs command is used to create a filesystem usually in form of a disk partition or file directly from the Linux terminal, it is a part of the e2fsprogs package.
The e2fsprogs package provides the following tools :
- mke2fs
- tune2fs
- dumpe2fs
- debugfs
Through mke2fs we can create ext2, ext3, or ext4 filesystems
Relation between mkfs and mke2fs :
We should keep in consideration that mkfs is part of the util-linux package and allows you to create filesystems of many different varieties, whereas mke2fs being a part of the e2fsprogs package used only to create ext2/3/4 filesystems.
Also, we should keep in consideration that mkfs calls mke2fs when it is requested to create an ext2/3/4 filesystem.
The basic syntax of mke2fs command :
mke2fs [ -c | -l filename ] [ -b block-size ] [ -f fragment-size ] [ -g blocks-per-group ] [ -G number-of-groups ] [ -i bytes-per-inode ] [ -I inode-size ] [ -j ] [ -J journal-options ] [ -K ] [ -N number-of-inodes ] [ -n ] [ -m reserved-blocks-percentage ] [ -o creator-os ] [ -O feature[,...] ] [ -q ] [ -r fs-revision-level ] [ -E extended-options ] [ -v ] [ -F ] [ -L volume-label ] [ -M last-mounted-directory ] [ -S ] [ -t fs-type ] [ -T usage-type ] [ -U UUID ] [ -V ] device [ blocks-count ]
mke2fs -O journal_dev [ -b block-size ] [ -L volume-label ] [ -n ] [ -q ] [ -v ] external-journal [ blocks-count ]
Note: mke2fs command is destructive. mke2fs places a new, formatted filesystem onto the partition. typing the wrong partition name will overwrite all existing data!!
Some Basic Commands :
To avoid significant loss of data, it is recommended to use these commands after you have made a backup of your data.
For safe operation try executing these commands after making an image file and creating file systems within that. We can explore and experiment with file systems without a need for spare hardware. We’ll use the dd command to create our image file.
dd if=/dev/zero of=~/abcx.img bs=1M count=250
- bs: block size (1MB)
- count: number of blocks(250)
- the total size of our image file: 250 MB
1. To get mke2fs version:
mke2fs -V
2. To get the basic syntax for mke2fs along with the tags:
mke2fs
3. To find bad blocks and create an ext2 filesystem:
sudo mke2fs -c ~/abcx.img
Note: Specifying -c twice leads to a slower read-write test instead of a fast read-only when the -c is specified only once
4. To create a filesystem and quickly check for bad blocks:
sudo mke2fs -t fs_type -c ~/abcx.img
In the command above -t is used for specifying the filesystem type we want to create followed by fs_type which can be replaced by ext2/3/4.
5. To create an ext4 filesystem with a BACKUP volume label:
sudo mke2fs -t ext4 -L BACKUP ~/abcx.img
6. To create an ext4 filesystem with 8290 bytes per inode, with a volume label BACKUP:
sudo mke2fs -t ext4 -L BACKUP -i 8290 ~/abcx.img
7. To find the number of bytes per inode:
df -i /dev/sdb
Similar Reads
mkfs Command in Linux with Examples
The mkfs command stands for âmake file systemâ and is utilized to create a file system, which organizes a hierarchy of directories, subdirectories, and files, on a formatted storage device. This can be a partition on a hard disk drive (HDD), a USB drive, or other storage media. A partition is a logi
4 min read
as command in linux with examples
as command is the portable GNU assembler in Linux. Using as command, we can read and assemble a source file. The main purpose of 'as' is to assemble the output of the GNU compiler of the C language.as command reads and assembles the .s File. Also, whenever you do not specify the file, it normally re
3 min read
bison command in Linux with Examples
bison command is a replacement for the yacc. It is basically a parser generator similar to yacc. Input files should follow the yacc convention of ending in .y format. Similar to yacc, the generated files do not have fixed names, but instead use the prefix of the input file. Moreover, if you need to
4 min read
uname command in Linux with Examples
Linux, renowned for its open-source flexibility and powerful performance, offers a range of commands that reveal the inner workings of your system. Among these, the 'uname' command stands out as a versatile tool that provides key details about your Linux machine. Here, we will learn the basics of th
4 min read
modinfo command in Linux with Examples
The modinfo command in Linux is used to display information about a Linux kernel module. It extracts detailed information from the modules available in the system and provides insights into their properties, dependencies, parameters, and more. If the module name is provided without a file name, the
3 min read
ar command in Linux with examples
The 'ar' command in Linux is a versatile tool used for creating, modifying, and extracting files from archives. An archive is essentially a collection of files bundled together in a specific structure, making it easy to manage multiple files as a single entity. Each file within the archive is referr
5 min read
badblocks command in Linux with examples
badblock command in Linux is used to search for bad blocks (block of memory which has been corrupted and can no longer be used reliably) in a device. It is by default set to run in non-destructive read-only mode. Syntax: badblocks [-b block_size] [-i input_file] [-o output_file] [-svwnf] [-c blocks_
2 min read
rm -rf Command in Linux With Examples
rm command in UNIX stands for remove and by default is used for removing files. It can also be used as an alternative to rmdir command which is primarily used for removing empty directories by using -d option but is mainly used with options such as -rf which allow it to delete non-empty directories
6 min read
rm command in Linux with examples
rm stands for remove here. rm command is used to remove objects such as files, directories, symbolic links and so on from the file system like UNIX. To be more precise, rm removes references to objects from the filesystem, where those objects might have had multiple references (for example, a file w
5 min read
cfdisk command in Linux with examples
cfdisk command is used to create, delete, and modify partitions on a disk device. It displays or manipulates the disk partition table by providing a text-based "graphical" interface. cfdisk /dev/sda Example: After running you get a prompt like this: Choose gpt from the list. Now you will see a parti
3 min read