fbpx mkfs in Linux: Format Partitions with ext4, XFS, FAT | Certificação Linux

mkfs Command in Linux: Format Partitions with ext4, XFS, FAT

📅 01/01/2019 ⏱ 5 min ✍️ Uira Ribeiro
Linuxcommands
mkfs Command in Linux: Format Partitions with ext4, XFS, FAT
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

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 the native formats are 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 file system type directly:

$ ls -l /usr/sbin/mk*lrwxrwxrwx 1 root root      8 ago 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 root  11432 jul 26  2018 /usr/sbin/mkfs-rwxr-xr-x 4 root root  96328 jul 26  2018 /usr/sbin/mkfs.ext2-rwxr-xr-x 4 root root  96328 jul 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 root  28512 ago  2  2018 /usr/sbin/mkfs.fat-rwxr-xr-x 1 root root  83824 jul 26  2018 /usr/sbin/mkfs.minixlrwxrwxrwx 1 root root      8 ago 29 22:48 /usr/sbin/mkfs.msdos -> mkfs.fatlrwxrwxrwx 1 root root      8 ago 29 22:48 /usr/sbin/mkfs.vfat -> mkfs.fat-rwxr-xr-x 1 root root 372448 jan 24  2019 /usr/sbin/mkfs.xfs

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

In general, the possible options for the mkfs command are:

  • -t: Specifies the formatting type for the partition
  • -c: Checks for bad blocks (defects) on the device;
  • -L: name Sets the device name;
  • -n: name Sets the device name for msdos format;
  • -q: Makes mkfs work with minimal output to the screen;
  • -v: Makes mkfs work with maximum output to the screen;
  • -m: Percentage of reserved disk space

An interesting option of mkfs is "-m percentage" which allows you to reserve a portion of the disk in percentage to prevent the system from freezing in case the disk is full. The idea is for the operating system to alert that the disk is full to regular users BEFORE the disk is actually completely full. This allows the system to continue functioning for a while until the administrator can take some action to prevent a truly full disk from freezing the system or causing data loss.

Example:

Formats with ext3 file system:

# mkfs.ext3 /dev/xvdb1mke2fs 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 blocks524288 inodes, 2096891 blocks104844 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=214748364864 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: done                            Writing inode tables: done                            Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done

Formats the disk with xfs:

# mkfs.xfs  /dev/xvdb1meta-data=/dev/xvdb1             isize=512    agcount=4, agsize=524223 blks         =                       sectsz=512   attr=2, projid32bit=1         =                       crc=1        finobt=1, sparse=0data     =                       bsize=4096   blocks=2096891, imaxpct=25         =                       sunit=0      swidth=0 blksnaming   =version 2              bsize=4096   ascii-ci=0 ftype=1log      =internal log           bsize=4096   blocks=2560, version=2         =                       sectsz=512   sunit=0 blks, lazy-count=1realtime =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 a lot on the intended use of the system and the disk type.

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 may consume a lot of disk space unnecessarily.

For example, ext4 uses 4K blocks by default. If you have many small files like 1k, each file will use an entire 4k block, even if its size is smaller than that.

XFS on the other hand is excellent at performing parallel input/output (I/O) operations using multiple physical disks, as it was designed for high performance of graphical workstations. It is ideal for applications that edit images and videos.

BTRFS on the other hand seems to be the most correct choice, as 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 TypeSuggested UseAdvantagesDisadvantages
ext2Used in /boot and on USB drivesSimple and fastNo journaling
ext3General use on LinuxAdds Journaling to ext2 without needing to formatNot as fast and reliable as ext4
ext4General use on LinuxBetter performance and reliability than ext3Does not allow a series of features that BTRFS has
XFSGeneral use on LinuxBetter performance than ext3. Ideal for videos.Does not allow a series of features that BTRFS has
ReiserFSNo longer usedEfficient for small filesHigh CPU consumption
VFATMemory cards and USB drivesEasy portability with WindowsAll of them :-)
BTRFSGeneral use on LinuxAll of them :-)Virtually none

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp