0
0
Linux CLIscripting~5 mins

File system types (ext4, xfs) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
File systems organize how data is stored and retrieved on a disk. Ext4 and XFS are two common file system types in Linux that help manage files efficiently and safely.
When setting up a new hard drive or partition for storing files on a Linux server.
When choosing a file system optimized for large files and high performance, like video editing storage.
When you want a reliable and widely supported file system for general use on desktop or server.
When you need a file system that supports journaling to protect data during power failures.
When formatting a disk for a database that requires fast write speeds and scalability.
Commands
This command formats the partition /dev/sdb1 with the ext4 file system, preparing it to store files with ext4's features.
Terminal
sudo mkfs.ext4 /dev/sdb1
Expected OutputExpected
mke2fs 1.46.5 (30-Dec-2021) Creating filesystem with 524288 4k blocks and 131072 inodes Filesystem UUID: 12345678-9abc-def0-1234-56789abcdef0 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
This command formats the partition /dev/sdb2 with the XFS file system, which is good for handling large files and high-performance workloads.
Terminal
sudo mkfs.xfs /dev/sdb2
Expected OutputExpected
meta-data=/dev/sdb2 isize=512 agcount=4, agsize=131072 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1 spinodes=0 data = bsize=4096 blocks=524288, 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
This command lists all block devices with their file system types, so you can verify which partitions use ext4 or xfs.
Terminal
lsblk -f
Expected OutputExpected
NAME FSTYPE LABEL UUID MOUNTPOINT sda ├─sda1 ext4 11111111-2222-3333-4444-555555555555 / sdb ├─sdb1 ext4 12345678-9abc-def0-1234-56789abcdef0 └─sdb2 xfs 87654321-cba9-0fed-4321-0fedcba98765 /mnt/data
Key Concept

If you remember nothing else from this pattern, remember: ext4 is a reliable general-purpose file system, while XFS excels at handling large files and high-performance workloads.

Common Mistakes
Formatting the wrong partition without checking device names.
This can erase important data on the wrong disk or partition.
Always use lsblk or fdisk -l to confirm the correct device before formatting.
Trying to mount a partition before formatting it with a file system.
Mounting an unformatted partition will fail because the system cannot recognize the file system.
Format the partition first with mkfs.ext4 or mkfs.xfs, then mount it.
Summary
Use mkfs.ext4 or mkfs.xfs to format partitions with ext4 or XFS file systems.
Verify file system types with lsblk -f before and after formatting.
Choose ext4 for general use and XFS for large files and high-performance needs.