Learn to create and configure file systems on storage partitions using XFS and ext4 in Red Hat and Ubuntu operating systems.
In this lesson, you will learn how to create and configure file systems on a storage partition. By default, Red Hat operating systems use the XFS file system while Ubuntu typically uses ext4. Keep in mind that these default choices may evolve with newer OS releases.
To format a partition with the XFS file system, run the following command. In this example, /dev/sdb1 is the target partition:
Copy
Ask AI
sudo mkfs.xfs /dev/sdb1
The mkfs command stands for “make file system.” If you prefer an ext4 file system instead, simply change the suffix as shown below:
Copy
Ask AI
sudo mkfs.ext4 /dev/sdb1
Most file systems are created with default settings that cater to standard use cases. However, you may need to adjust specific parameters—like setting a custom label or modifying the inode size—using additional command-line options. For a complete list of available options, consult the manual page:
Copy
Ask AI
man mkfs.xfs
The manual displays options specific to XFS. For example, the -L option lets you assign a label to your file system. Consider these examples:
If you search within the manual by typing the forward slash and then -L, you’ll notice that the label must not exceed 12 characters. To set the label “BackupVolume” on /dev/sdb1, execute:
Copy
Ask AI
sudo mkfs.xfs -L "BackupVolume" /dev/sdb1
Before making any changes, verify your devices by listing available file systems. Below is a sample output from using fdisk:
XFS comes with a suite of administrative utilities. By typing xfs and pressing the Tab key, you can view available XFS-related commands. One of the most useful utilities is xfs_admin, which enables you to modify file system properties. For example, to display the current label for /dev/sdb1, run:
Copy
Ask AI
sudo xfs_admin -l /dev/sdb1
To change the label to “FirstFS” (note the uppercase -L), execute:
Ubuntu and similar distributions often utilize the ext4 file system by default. To view configuration options for ext4, refer to the manual page of mkfs.ext4, which internally calls the mke2fs program:
Copy
Ask AI
man mkfs.ext4
The manual details various options for setting block size, inode count, file system label, and more. To create an ext4 file system with default settings on /dev/sdb2, use the command:
Copy
Ask AI
sudo mkfs.ext4 /dev/sdb2
The output might resemble the following:
Copy
Ask AI
mke2fs 1.47.0 (5-Feb-2023)Creating filesystem with 1048576 4k blocks and 262144 inodesFilesystem UUID: 6e7208b3-74f9-4e65-933a-c3e05fcfe53cSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: doneWriting inode tables: doneCreating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done
Running the command again on the same partition will trigger a warning that a file system already exists, preventing accidental overwrites.For scenarios where a higher number of inodes is required—especially on systems handling many small files—use the -N option to specify the exact number of inodes:
Copy
Ask AI
sudo mkfs.ext4 -N 500000 /dev/sdb2
Remember, in ext4, each file or directory uses an inode. Even with ample disk space, a shortage of inodes can restrict file creation.
The tune2fs utility allows you to display and modify ext4 file system properties. To view current properties of /dev/sdb2, run:
Copy
Ask AI
sudo tune2fs -l /dev/sdb2
Although the exact command to change the label with tune2fs is not included here, the manual provides detailed guidance for modifying properties, including updating the label to “SecondFS” using the appropriate options.Finally, tools like cfdisk can be used to inspect the /dev/sdb device, ensuring that partitions have the correct file system types and labels. In our demonstration, the XFS file system was labeled “FirstFS” and the ext4 file system on /dev/sdb2 was set to “SecondFS.”This concludes our lesson on creating and configuring file systems with XFS and ext4. For detailed reference material and further reading, consider reviewing the following resources: