Skip to main content
Welcome to this detailed lesson on creating and configuring file systems in Linux. In this guide, we will walk through the process of formatting partitions, using XFS and ext4 file systems, and modifying file system properties with various utilities. This step-by-step explanation is designed to be both technical and SEO-friendly, ensuring an optimal learning experience. Before storing files and directories on any partition, it is essential to create a file system on it. On CentOS, the default file system is XFS, but ext4 is also widely supported and commonly used.

Formatting a Partition with XFS

To format a partition with the XFS file system using default settings, run the following command:
If you choose to use the ext4 file system instead, the command is similar:
The mkfs command (short for “make file system”) supports numerous settings to tailor the file system. The above examples use the default configuration, which is sufficient for most scenarios. However, if you need to customize parameters, refer to the manual pages for more details. For example, to view the configurable options for constructing an XFS file system, check its manual page:
One useful option when creating an XFS file system is the -L flag, which allows you to assign a label. Note that label names are limited to 12 characters. To label your XFS partition as “BackupVolume”, use:
Below is an excerpt from the manual page that highlights the -L flag and additional options:
The image shows a terminal window displaying a manual page for the mkfs.xfs command, which is used to construct an XFS filesystem. It includes sections like NAME, SYNOPSIS, and DESCRIPTION.
Remember, when searching within the manual for specific options, you might need to escape characters like dashes. The manual confirms the label length restriction:
The image shows a terminal window displaying a manual page for the mkfs.xfs command, detailing options and usage for setting filesystem labels and other parameters.
Additionally, you can configure the inode size to store extended file attributes. For instance, to format the partition with 512-byte inodes and label it “BackupVolume”, execute:
After entering your password, you should expect output similar to:
If you encounter any unexpected errors while formatting, double-check your partition identifier and ensure your system supports the chosen file system.

XFS Utilities and Modifying File System Attributes

Once the file system is created, you can explore a suite of XFS utilities by typing xfs and pressing the Tab key twice. This will display tools such as:
To display the current label (using a lowercase “l”), run:
For instance, the output may show:
To change the label, use the uppercase -L option. For example, to update the label to “FistFS”, run:
A confirmation message such as the following indicates that the label has been successfully updated:

Formatting a Partition with ext4

The ext4 file system is a popular choice on Linux systems. The process of creating an ext4 file system is handled by the mke2fs command, with mkfs.ext4 serving as a convenient alias. To access its manual page, use:
For ext4, the same -L flag is used to set a label, and the -N flag allows you to control the number of inodes. This is crucial if you anticipate handling a large volume of small files. If the default inode count is insufficient, you can specify an alternative number. For instance, to create an ext4 file system on /dev/sdb2 with a label “BackupVolume” and 500,000 inodes, execute:
The output should resemble:
To modify properties of an existing ext4 file system, use the tune2fs utility. For example, to change the label of /dev/sdb2 to “SecondFS”, run:
To verify that the label change has been applied, use:
The output will include an entry similar to:
Ensure that you back up any critical data before modifying file system parameters. Changing labels or inode counts on active file systems without proper precautions can lead to data loss.

Summary

In this lesson, you learned how to create and configure file systems on Linux using both XFS and ext4. We covered:
  • Formatting partitions with XFS and ext4
  • Customizing file system parameters such as labels and inode sizes
  • Utilizing utilities like xfs_admin, mkfs.ext4, and tune2fs for managing file system attributes
For further details, consult the manual pages by running man mkfs.xfs, man mkfs.ext4, and man tune2fs. Experimenting with these tools will deepen your understanding and hone your Linux file system management skills. Happy learning and exploring your Linux system configuration! For additional resources, check out:

Watch Video