Pages

RHEL Linux Partitioning

Mastering Disk Partitioning in Linux: A Practical Guide for RHEL Users

Disk partitioning is like dividing a single hard drive into isolated apartments—each one can hold its own operating system, data, or filesystem without interfering with the others. This setup is crucial for organization, security, and performance, especially on servers running Red Hat Enterprise Linux (RHEL).

Whether you’re setting up a dual-boot system, isolating user data, or optimizing a production server, understanding partitioning ensures stability, scalability, and disaster recovery readiness.

Why Partition Your Disks?
Partitioning isn’t just a legacy concept from the DOS era—it solves real problems in modern Linux environments:
  • Organize data effectively: Separate critical areas like /boot (kernel files), / (root), /home (user files), /var (logs), /tmp (temporary data), and swap (virtual memory).
  • Support multiple OSes: Dual- or multi-boot RHEL alongside Windows, Ubuntu, or legacy systems.
  • Boost performance: Place high-I/O partitions (e.g., /var/log, databases) on faster SSDs or dedicated disks.
  • Enhance security and stability: If one partition becomes corrupted, the rest remain intact—a lifesaver for production servers.
  • Experiment with filesystems: Mix ext4 for reliability, XFS (default in RHEL 7+) for high-performance workloads, or Btrfs for snapshots and rollback.
Example: On a web server, isolating /var/www prevents log growth from filling the root filesystem, avoiding downtime.

Partition Types: Primary, Extended, and Logical
TypeDescriptionBest Use Case
PrimaryUp to 4 per disk; bootableOS installation or /boot
ExtendedSingle container to hold logical partitionsWorkaround MBR limits
LogicalNested inside extended partitionsAdditional data partitions beyond 4

Modern setups mostly favor GPT over MBR, reducing the need for extended/logical partitions.

Key Partitioning Schemes: MBR vs. GPT
SchemeMax PartitionsMax Disk SizeBoot ModeBest For
MBR4 primary (or 3+1 extended)~2TBLegacy BIOSOlder hardware
GPT128 (default)Practically unlimitedUEFIServers, large drives, modern RHEL
Note: GPT is mandatory for UEFI booting and disks over 2TB. The RHEL installer defaults to GPT on new systems.

Recommended RHEL Partition Layout
For a typical RHEL server with a 100GB disk, a balanced layout could be:

PartitionSizeFilesystemPurpose
/boot1GBext4Kernel and GRUB
/20GBXFSRoot filesystem
swap2x RAM (min 4–8GB)swapVirtual memory
/home50GBext4/XFSUser data
/var20GBXFSLogs, packages
/tmp5GBext4Temporary files
/optOptionalXFSThird-party apps

Pro Tip: Use LVM on top of partitions for dynamic resizing without downtime—RHEL strongly recommends this in production environments.

Essential Partitioning Tools in RHEL
ToolUse CaseNotes
fdiskInteractive MBR partitioningMBR only, simple CLI
partedScriptable, supports large disksMBR + GPT, CLI/interactive
gdiskGPT specialistLike fdisk for GPT
lsblkList devices and partitionsUseful for identifying disks
blkidView UUIDs/filesystem typesEssential for /etc/fstab
lvcreate (LVM)Dynamic volumesRequires PV → VG → LV hierarchy

2. Create MBR Partitions with fdisk
# fdisk /dev/sda
Inside fdisk:
n   # new partition
p   # primary
1   # partition number
Enter   # default first sector
+20G    # size
w       # write changes

3. Create GPT Partitions with parted
# parted /dev/sda
(parted) mklabel gpt
(parted) mkpart primary xfs 1MiB 20GiB
(parted) set 1 boot on
(parted) print
(parted) quit

4. Format Partitions
# mkfs.xfs -f /dev/sda1     # Default for RHEL
# mkfs.ext4 /dev/sda2       # Alternative
# mkswap /dev/sda3          # Swap space
# swapon /dev/sda3           # Activate swap

LVM example:
# pvcreate /dev/sda1
# vgcreate myvg /dev/sda1
# lvcreate -L 20G -n root myvg
# mkfs.xfs /dev/myvg/root

5. Mount Partitions

Temporary mount:
# mkdir /mnt/newpart
# mount /dev/sda1 /mnt/newpart

Permanent mount via /etc/fstab using UUIDs:
UUID=1234-5678 /mnt/newpart xfs defaults 0 2
# mount -a   # Test fstab

Advanced Tips and Best Practices
Backup first: Partitioning can erase data. Use dd or rsync.
UEFI systems: Ensure a /boot/efi partition (FAT32, 300–500MB).
Boot troubleshooting: grub2-mkconfig -o /boot/grub2/grub.cfg.
Resizing partitions:
# resize2fs for ext4
# xfs_growfs for XFS
LVM simplifies resizing without downtime.
RHEL installers (Anaconda): Auto-partitioning is convenient, but customize for production workloads.
Snapshots: Consider LVM snapshots for backups and safe upgrades.
Monitoring storage health: Use smartctl for disks, lsblk -f for filesystems, and df -h for usage.

Example: Partitioning a Web Server
  • /boot – kernel and bootloader
  • / – root OS
  • /var/www – website data, separate from /var/log
  • /var/log – log-heavy directory on faster disk
  • Swap – sized according to RAM, optional for SSD-only servers

This layout ensures logs or web files never fill the OS partition, improving uptime and maintainability.

No comments:

Post a Comment