A new partition is empty space. Creating a filesystem on it, often called formatting, writes the structures needed to store files.
Formatting destroys access to whatever was there before. Check the device name twice.
Check before you format
$ lsblk -f /dev/sdb
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sdb
โโsdb1An empty FSTYPE column means no filesystem was detected. If a type or mount point is shown, stop and find out what is on it.
Running mkfs
mkfs is a front end to type-specific tools. These two commands do the same job:
$ sudo mkfs -t ext4 /dev/sdb1
$ sudo mkfs.ext4 /dev/sdb1Run only one of them. Typical output looks like this (shortened):
mke2fs 1.47.2 (1-Jan-2025)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 5ef4138f-5574-4227-8c74-58be9b62c010
Writing superblocks and filesystem accounting information: doneVersion numbers and sizes will differ on your system. Other types have their own tools, such as mkfs.xfs and mkfs.vfat. They come from separate packages (xfsprogs, dosfstools) that may not be installed.
Labels and UUIDs
Every ext4 filesystem gets a UUID, a long unique identifier. You can also give it a readable label with -L:
$ sudo mkfs.ext4 -L data /dev/sdb1For mkfs.vfat, the label option is -n instead. To change the label of an existing ext4 filesystem without reformatting, use e2label:
$ sudo e2label /dev/sdb1 backupsConfirm the result
$ sudo blkid /dev/sdb1
/dev/sdb1: LABEL="backups" UUID="5ef4138f-5574-4227-8c74-58be9b62c010" BLOCK_SIZE="4096" TYPE="ext4"Some tools refuse or ask for confirmation when they find existing data. mkfs.ext4 run in a terminal asks whether to proceed (in a script it may simply carry on), while mkfs.xfs requires -f to overwrite. Do not rely on this as your safety net, and never force a format you have not checked.
Never run mkfs on a mounted filesystem.
Using it
The filesystem is ready but not yet visible in the directory tree. You need to mount it, which is covered in the mount lesson.
Try it
Practise safely on a file instead of a disk:
$ truncate -s 100M fs.img
$ mkfs.ext4 -L practice fs.img
$ blkid fs.imgNo root access is needed because you own the file. If a command is not found, it may live in /usr/sbin, so try /usr/sbin/mkfs.ext4.
Check your understanding
Creating Filesystems
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.