System and processes

The mkfs.ext4 command

Formats a partition with ext4 and erases what was on it.

Syntax

mkfs.ext4 [opciones] DISPOSITIVOTry it in the terminal →

Most useful options

-L ETIQUETASets the volume label. It can be up to 16 bytes long
-m PORCENTAJEReserves that percentage of blocks for root. The default is 5%
-b TAMAÑOBlock size. In most cases the default is 4 KB
-nFormats nothing: shows what it would do. It helps locate the backup superblocks
-qQuiet mode, useful inside scripts
-U UUIDSets the UUID: a specific value, or clear, random or time
-FForces creation even if the device is not a block partition. If it is also mounted or in use, give it twice

Copy-ready examples

$ sudo mkfs.ext4 -n /dev/sdb1shows what it would do with that partition, without formatting anything.
$ sudo mkfs.ext4 -L datos /dev/sdb1warning: formats the partition and erases all its contents. Check it with lsblk first.
$ sudo mkfs.ext4 -q -m 1 -L copias /dev/sdb1warning: formats without messages and reserves only 1% for root.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
/dev/sdb1 is mounted; will not make a filesystem here!The partition is mounted, and mkfs.ext4 refuses to format it.Check with lsblk that it is the right partition and unmount it with sudo umount /dev/sdb1.

Typical mistakes

  • Formatting erases all the partition contents: confirm the device with lsblk before running anything.
  • If you write /dev/sdb instead of /dev/sdb1, you will format the whole disk, over its partition table.
  • There is no undo. Make the backup before, not after.
  • Giving -F twice forces formatting even when the device is mounted or in use. Do not use it out of habit.

Differences from similar commands

  • mkfs.vfat: formats FAT, meant for USB drives and for reading on Windows. ext4 is the native Linux filesystem.
  • e2fsck: checks and repairs an ext4 filesystem that already exists. mkfs.ext4 creates one from scratch and erases what was there.

FAQ

How do I find the partition name?

With lsblk, which shows disks, partitions, sizes and mount points. Check the size before formatting.

Can the data be recovered after formatting?

There is no undo. Formatting creates an empty filesystem on the partition, and the previous data is no longer accessible.

What is the label for?

It is the volume name you see when mounting it and with lsblk -f. In /etc/fstab you can use it with LABEL= instead of /dev/sdX.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course