Red Hat Certified System Administrator(RHCSA)

Create and Configure File Systems

Create and configure file systems

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:

sudo mkfs.xfs /dev/sdb1

If you choose to use the ext4 file system instead, the command is similar:

sudo mkfs.ext4 /dev/sdb1

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:

man mkfs.xfs

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:

sudo mkfs.xfs -L "BackupVolume" /dev/sdb1

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:

sudo mkfs.xfs -i size=512 -L "BackupVolume" /dev/sdb1

After entering your password, you should expect output similar to:

[aaron@LFCS-CentOS ~]$ sudo mkfs.xfs -i size=512 -L "BackupVolume" /dev/sdb1
[sudo] password for aaron:
meta-data              = /dev/sdb1
data                   =
name                   = version 2
log                    = internal log
realtime               = none
[aaron@LFCS-CentOS ~]$

Note

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:

[aaron@LFCS-CentOS ~]$ xfs
xfs_admin         xfs_estimate       xfs_mkfile         
xfs_bmap          xfs_freeze         xfs_io            
xfs_copy          xfs_fsr            xfs_logprint       
xfs_db            xfs_growfs         xfs_mdrestore      
xfsdump           xfs_info           xfs_metadump      
                  xfs_ncheck         xfs_quota         
                  xfs_repair         xfsrestore        
[aaron@LFCS-CentOS ~]$

To display the current label (using a lowercase "l"), run:

sudo xfs_admin -l /dev/sdb1

For instance, the output may show:

label = "BackupVolume"

To change the label, use the uppercase -L option. For example, to update the label to "FistFS", run:

sudo xfs_admin -L "FistFS" /dev/sdb1

A confirmation message such as the following indicates that the label has been successfully updated:

writing all SBs
new label = "FistFS"

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:

man mkfs.ext4

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:

sudo mkfs.ext4 -L "BackupVolume" -N 500000 /dev/sdb2

The output should resemble:

Creating filesystem with 1048576 4k blocks and 500224 inodes
Filesystem UUID: 903a4d4d-af29-4bf3-9fad-1dfdd0cd9f39
Superblock backups stored on blocks:
 32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

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:

sudo tune2fs -L "SecondFS" /dev/sdb2

To verify that the label change has been applied, use:

sudo tune2fs -l /dev/sdb2

The output will include an entry similar to:

Filesystem volume name:   SecondFS
...

Warning

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

Watch video content

Previous
Setup user and group disk quotas for filesystems