004 Create and Configure File Systems

Tech Tutorial: Create and Configure File Systems in RHEL #

Introduction #

For the Red Hat Certified System Administrator (RHCSA) exam, one of the critical skills you need to master is the creation and configuration of file systems. This tutorial is tailored to help you understand how to handle file systems on Red Hat Enterprise Linux (RHEL) effectively. We’ll cover creating, checking, mounting, and configuring various types of file systems, including ext4, xfs, and vfat.

Step-by-Step Guide #

1. Creating File Systems #

Before you can use a new disk in Linux, you need to perform several steps: partitioning the disk, creating a file system, and then mounting the file system to make it accessible. We’ll start with creating file systems.

a. Partitioning a Disk #

First, you will need to identify the disk and create a partition. We will use lsblk to list all block devices and their partitions:

lsblk

Assuming the new disk is /dev/sdb and has no partitions, you can create a new partition using fdisk:

sudo fdisk /dev/sdb

Within fdisk, the following commands can be used:

  • n to create a new partition,
  • p to specify it as a primary partition,
  • 1 to assign it as the first partition,
  • Accept default values for the first and last sectors to use the full disk,
  • w to write the changes to disk.

b. Creating an ext4 File System #

To create an ext4 file system on the new partition (/dev/sdb1):

sudo mkfs.ext4 /dev/sdb1

c. Creating an XFS File System #

Alternatively, if you prefer to use XFS, which is typical for RHEL:

sudo mkfs.xfs /dev/sdb1

d. Creating a VFAT File System #

For creating a VFAT file system (commonly used for USB flash drives):

sudo mkfs.vfat /dev/sdb1

2. Checking File Systems #

Before mounting a new file system, it’s a good practice to check its integrity. For ext4:

sudo e2fsck /dev/sdb1

For XFS:

sudo xfs_repair /dev/sdb1

3. Mounting File Systems #

To make use of the file system, you need to mount it:

sudo mkdir /mnt/mynewdrive
sudo mount /dev/sdb1 /mnt/mynewdrive

To ensure the file system is mounted automatically at boot, add an entry in /etc/fstab:

/dev/sdb1   /mnt/mynewdrive   ext4   defaults   0   2

Replace ext4 with xfs or vfat depending on the file system you created.

4. Configuring File Systems #

a. Adjusting Mount Options #

You might want to adjust mount options for performance reasons. For instance, for an ext4 file system:

/dev/sdb1   /mnt/mynewdrive   ext4   defaults,noatime   0   2

noatime updates accesses only for modifications (not reads), which can improve performance.

b. Resizing File Systems #

To increase the size of an XFS file system after expanding the underlying partition:

sudo xfs_growfs /mnt/mynewdrive

For ext4, first ensure the partition is unmounted:

sudo umount /mnt/mynewdrive
sudo resize2fs /dev/sdb1
sudo mount /dev/sdb1 /mnt/mynewdrive

Conclusion #

Managing file systems is a fundamental skill for any Linux administrator, especially for those preparing for the RHCSA exam. By following the steps outlined in this tutorial, you should be able to proficiently create, check, mount, and configure various types of file systems on RHEL. Remember, practice is key, so ensure to try these commands in a safe testing environment to build your confidence and proficiency.