Setting Up and Mounting a External Disk in RHEL: Step-by-Step Guide

Setting Up and Mounting a External Disk in RHEL: Step-by-Step Guide

This guide explains how to verify, partition, format, and mount a new disk (/dev/sda) on Red Hat Enterprise Linux (RHEL). Each step includes commands and detailed explanations to simplify the process.


Prerequisites

Before we start, ensure you have:

  • Administrative access to the RHEL system

  • A new disk attached to your system

  • Basic knowledge of Linux command-line operations


Step-by-Step Guide

Step 1: Verify the Disk

Why: Ensure the disk (/dev/sda) is available, unpartitioned, and ready for use.

Commands:

df -hT
lsblk
sudo fdisk -l /dev/sda

Explanation:

  • lsblk: Lists block devices, showing names, sizes, and mount points. Check if sda is listed as unmounted.

  • sudo fdisk -l /dev/sda: Displays detailed disk information, including partition status and usage.

Step 2: Partition the Disk

Why: Partitioning prepares the disk for formatting and data storage.

Command:

sudo fdisk /dev/sda

Steps:

  1. Press n to create a new partition.

  2. Once inside fdisk:

    • Press n to create a new partition.

    • Select p for a primary partition.

    • Accept the default partition number (e.g., 1) and press Enter.

    • Accept the default first and last sector to use the entire disk.

    • Press w to write changes and exit.

  3. Press w to save changes and exit.

Step 3: Format the Partition

Why: Apply a filesystem for data storage.

sudo mkfs.xfs /dev/sda1
  • Explanation: Formats the partition /dev/sda1 with the XFS filesystem.

  • Replace xfs with another filesystem (e.g., ext4) if desired.

Step 4: Create a Mount Point

Why: A mount point is a directory where the disk will be accessible. We’re creating /app as our mount point.

Command:

sudo mkdir -p /app
  • Explanation

    • mkdir creates a directory named /app if it doesn’t already exist.

    • This directory will serve as the interface for the mounted disk.

Step 5: Mount the Partition

Why: Before making the mount permanent, test if the partition can be mounted successfully.

Command:

sudo mount /dev/sda1 /app

Explanation

  • Mounts /dev/sda1 (the newly formatted partition) at /app.

  • Any files written to /app will now reside on the mounted disk

Step 6: Make the Mount Permanent

Why?

The mount will disappear after a reboot unless made permanent by adding it to /etc/fstab.

Commands

  1. Get the UUID:

     sudo blkid /dev/sda1
    

    1. Copy the above mentioned UUID and edit fstab
  2. Edit /etc/fstab:

     sudo nano /etc/fstab
    

Explanation

  • blkid shows the UUID of /dev/sda1.

  • Add the following line to /etc/fstab to persist the mount:

      UUID=<your-uuid> /app xfs defaults 0 0
    

Step 7: Verify the Mount

Why?

Ensure the disk is mounted correctly and persists after reboots.

Command


sudo mount -a
df -hT

Explanation

  • mount -a applies all /etc/fstab entries.

  • df -hT confirms the mount status and filesystem type.

Conclusion

You’ve successfully set up, formatted, mounted, and configured a persistent disk in RHEL. The disk is now ready for use and will remain accessible after reboots. Regular backups and monitoring are recommended to maintain data integrity and system reliability.


FAQ

Q1: What are the benefits of using mkfs.ext4?

  • Ans: mkfs.ext4 is a widely used command for formatting partitions with the ext4 filesystem, known for its performance and reliability.

Q2: How often should I perform a disk check?

  • Ans:- It's advisable to perform a disk check monthly or as part of your regular maintenance schedule.

Enjoyed this article? Subscribe to our newsletter for more Linux tips and share this post on social media to help others understand the importance of mounting disks.


Did you find this article valuable?

Support ParaNerdOps by becoming a sponsor. Any amount is appreciated!