Categories: Disks and Partitions

mkfs command on Linux (format disk) [Basic Guide]

The mkfs command on Linux formats the partition created by fdisk/gdisk/parted with the file system.

The file system type is defined by the —t option and are the native formats ext2, ext3, ext4, fat, vfat, minix, msdos, and xfs.

The mke2fs and mkdosfs commands are variations of mkfs.

mkfs has some variations that allow you to choose the type of file system directly:

$ ls -l /usr/sbin/mk * 
lrwxrwxrwx 1 root 8 Aug 29 22:48 /usr/sbin/mkdosfs -> mkfs.fat
-rwxr-xr-x 4 root root 96328 Jul 26 2018 /usr/sbin/mke2fs
-rwxr-xr-x 1 root 11432 Jul 26 2018 /usr/sbin/mkfs -rwxr-xr-x 1 root 11432 Jul 26 2018 /usr/sbin/mkfs
-rwxr-xr-x r-x 4 root root & nbsp; 96328 July 26 2018 /usr/sbin/mkfs.ext2
-rwxr-xr-x 4 root root 96328 July 26 2018 /usr/sbin/mkfs.ext3
-rwxr-xr-x 4 root root 96328 Jul 26 2018 /usr/sbin/mkfs.ext4 -rwxr-xr-x 1 root 28512 Aug 2 2018 /usr/sbin/mkfs.ext4
-rwxr-xr-x 1 root 28512 Aug 2 2018 /usr/sbin/mkfs.ext4 mkfs.fat
-rwxr-xr-x 1 root root 83824 Jul 26 2018 /usr/sbin/mkfs.minix

lrwxrwx 1 root 8 Aug 29 22:48 /usr/sbin/mkfs.msdos -> mkfs.fat
lrwxrwxrwx 1 root August 8 29 22:48 /usr/sbin/mkfs.vfat -> mkfs.fat -rwxr-xr-x 1 root 37r/24 Jan 24 2019 /usr/sbin/mkfs.vfat -> mkfs.fat
-rwxr-xr-x 1 root 37r/24 Jan 24 2019 /usr/sbin/mkfs.vfat -> mkfs.fat -rwxr-xr-x 1 root 37r/24 Jan 24 2019 sbin/mkfs.xfs

Depending on the variation you choose, mkfs may have more or fewer options.

In general, the possible mkfs command options are:

  • -t: Indicates the type of format the partition should be
  • -c: Check the device for bad blocks (defects); -L: name Configure the device
  • name; -n: name Configure the device
  • name; -n: name Configure the device name to the msdos format;
  • -q: Make mkfs work with a minimum of possible video output;
  • -v: Make mkfs work with the maximum possible video output;
  • -m: Percentage of reserved disk

An interesting mkfs option is the “-m percentage”, which allows you to reserve disk space as a percentage to avoid crashing the system in the event of a full disk. The idea is for the operating system to warn that the disk is full for ordinary users, BEFORE the disk is actually completely full. This allows the system to continue working for a while until the administrator can take some action to prevent a really full disk from stopping the system from functioning or causing data loss.

Example:

Format with ext3 file system:

# mkfs.ext3 /dev/xvdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux
Block size=4096 (log=2) 
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2096891 blocks
104844 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks for group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done

Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Format the disk with xfs:

# mkfs.xfs /dev/xvdb1 
meta-data=/dev/xvdb1 isize=512 agcount=4, agsize=524223 blks
= sectsz=512& nbsp; attr=2, projid32bit=1
= crc=1 finobt=1, sparse=0
date = bsize=4096 blocks=2096891, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii -ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

File Systems

Once the partitions are already defined, you can create the File System that will be used. Linux supports several file systems and your choice depends largely on the usefulness that will be given to the system and the type of disk.

Disks formatted with ext2, ext3, and ext4 have a wide range of tools. Since they use a fixed block size, they are not good file systems for small files, as they can consume a lot of disk unnecessarily.

For example, ext4 uses 4K blocks as standard. If you have a lot of files as small as 1k, each file will use an entire 4k block, even if its size is smaller than that.

XFS, in turn, is excellent at performing parallel input/output (I/O) operations using several physical disks, since it was designed for high performance graphics stations. It is ideal for applications that edit images and videos.

BTRFS, on the other hand, seems to be the right choice, since it allows snapshots, compression, defragmentation and so many other advantages, but it is not always available in all distributions.

The following table will help you choose the file system:

File System Type Suggested Use Advantages Disadvantages Disadvantages
ext2 Used in /boot and USB sticks Simple and fast Doesn’t have journaling
ext3 General use on Linux Add Journaling to ex2 without having to format Not as fast and reliable as ext4
ext4 General use on Linux Better performance and reliability than ext3 Doesn ‘t allow a series of features that BTRFS has
XFS General use on Linux Better performance than ext3. Ideal for videos. It does not allow a number of features that BTRFS has
ReiserFS It is no longer used Efficient for small files High CPU consumption
VFAT Memory cards and pendrives Easy portability with Windows All 🙂
BTRFS General use on Linux All 🙂 Virtually none

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Uirá Endy Ribeiro

Uirá Endy Ribeiro is a Software Developer and Cloud Computing Architect with a 23-year career. He has master's degrees in computer science and fifteen IT certifications and is the author of 11 books recognized in the IT world market. He is also Director at Universidade Salgado de Oliveira and Director of the Linux Professional Institute - LPI Director's Board.

Recent Posts

Sudo command on Linux (privilege scale) [Basic Guide]

The sudo command on Linux executes a given command as if it were another user.…

2 years ago

SS command on Linux (investigate the network) [Basic Guide]

The ss command on Linux is extremely useful for investigating sockets, providing various information about…

2 years ago

Free Linux command (memory usage) [Basic Guide]

Free Linux command shows the amount of total memory in use and available, as well…

2 years ago

Linux while command (loop – while) [Basic Guide]

The shell has structures for testing conditions and executing certain program sequences several times (loop),…

2 years ago

Linux fstab file (disk mount setup) [Basic Guide]

The /etc/fstab file stores the configuration of which devices should be mounted and what is…

2 years ago

Netcat command on Linux (Swiss network knife) [Basic Guide]

The Netcat Command in Linux or nc is a utility used to do “almost anything”…

2 years ago

This website uses cookies.