mkfs command on Linux (format disk)
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:
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:
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Format the disk with xfs:
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 |