Bird
Raised Fist0
Linux CLIscripting~5 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. Which command is used to create an ext4 file system on a disk partition?
easy
A. format /dev/sdX1
B. mkfs.xfs /dev/sdX1
C. mkfs.ext4 /dev/sdX1
D. diskformat ext4 /dev/sdX1

Solution

  1. Step 1: Understand the command for ext4 file system creation

    The command mkfs.ext4 is specifically designed to create ext4 file systems on a given partition.
  2. Step 2: Identify the correct usage with device name

    Using mkfs.ext4 /dev/sdX1 formats the partition /dev/sdX1 as ext4.
  3. Final Answer:

    mkfs.ext4 /dev/sdX1 -> Option C
  4. Quick Check:

    ext4 creation command = mkfs.ext4 [OK]
Hint: ext4 uses mkfs.ext4 command to format partitions [OK]
Common Mistakes:
  • Confusing mkfs.xfs with mkfs.ext4
  • Using generic format commands not valid in Linux
  • Trying to use unsupported commands like diskformat
2. Which of the following is the correct syntax to create an XFS file system on /dev/sdb1?
easy
A. mkfs.ext4 /dev/sdb1
B. mkfs.xfs /dev/sdb1
C. mkfs.xfs -t xfs /dev/sdb1
D. format xfs /dev/sdb1

Solution

  1. Step 1: Identify the command for XFS file system creation

    The command mkfs.xfs is the standard way to create an XFS file system on a partition.
  2. Step 2: Confirm the correct device usage

    Using mkfs.xfs /dev/sdb1 formats the partition /dev/sdb1 as XFS.
  3. Final Answer:

    mkfs.xfs /dev/sdb1 -> Option B
  4. Quick Check:

    XFS creation command = mkfs.xfs [OK]
Hint: Use mkfs.xfs for XFS file system creation [OK]
Common Mistakes:
  • Using mkfs.ext4 instead of mkfs.xfs
  • Trying mkfs.xfs -t xfs which is invalid syntax
  • Using Windows-like format commands
3. What will be the output of the command file -s /dev/sdc1 after formatting /dev/sdc1 with ext4?
medium
A. /dev/sdc1: Linux rev 1.0 ext4 filesystem data
B. /dev/sdc1: XFS filesystem data
C. /dev/sdc1: data
D. /dev/sdc1: DOS/MBR boot sector

Solution

  1. Step 1: Understand the file command with -s option

    The file -s command reads the device or file to identify its type.
  2. Step 2: Recognize the output for ext4 formatted partition

    After formatting with ext4, the output shows Linux rev 1.0 ext4 filesystem data indicating ext4 file system.
  3. Final Answer:

    /dev/sdc1: Linux rev 1.0 ext4 filesystem data -> Option A
  4. Quick Check:

    file -s on ext4 = ext4 filesystem data [OK]
Hint: file -s shows filesystem type on device [OK]
Common Mistakes:
  • Expecting XFS output after ext4 format
  • Confusing raw data output with filesystem info
  • Assuming DOS/MBR boot sector output on formatted partition
4. You ran mkfs.ext4 /dev/sdd1 but got an error: "device is mounted". What is the best fix?
medium
A. Unmount the device using umount /dev/sdd1 and retry
B. Use mkfs.xfs instead of ext4
C. Reboot the system and run the command again
D. Format a different device without unmounting

Solution

  1. Step 1: Understand the error cause

    The error "device is mounted" means the partition is currently in use and cannot be formatted.
  2. Step 2: Unmount the device before formatting

    Using umount /dev/sdd1 frees the device so mkfs.ext4 can run successfully.
  3. Final Answer:

    Unmount the device using umount /dev/sdd1 and retry -> Option A
  4. Quick Check:

    Unmount device before formatting = umount [OK]
Hint: Unmount device before formatting to avoid errors [OK]
Common Mistakes:
  • Trying different filesystem without unmounting
  • Rebooting unnecessarily instead of unmounting
  • Ignoring the mounted status and forcing format
5. You need a file system for a large data server that requires fast write speed and supports files larger than 16TB. Which file system should you choose?
hard
A. ext4
B. NTFS
C. FAT32
D. XFS

Solution

  1. Step 1: Analyze file system limits and performance

    ext4 supports large files but has a practical limit around 16TB; XFS supports very large files and is optimized for high-speed writes.
  2. Step 2: Match requirements to file system features

    XFS is designed for large data servers with fast write speeds and supports files larger than 16TB, making it the best choice.
  3. Final Answer:

    XFS -> Option D
  4. Quick Check:

    Large fast files = XFS [OK]
Hint: Choose XFS for large files and fast writes on servers [OK]
Common Mistakes:
  • Choosing ext4 without checking file size limits
  • Selecting FAT32 which has small file size limits
  • Confusing NTFS as a Linux-native file system
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard