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
| Type | Description | Best Use Case |
|---|---|---|
| Primary | Up to 4 per disk; bootable | OS installation or /boot |
| Extended | Single container to hold logical partitions | Workaround MBR limits |
| Logical | Nested inside extended partitions | Additional data partitions beyond 4 |
Modern setups mostly favor GPT over MBR, reducing the need for extended/logical partitions.
Key Partitioning Schemes: MBR vs. GPT
| Scheme | Max Partitions | Max Disk Size | Boot Mode | Best For |
|---|---|---|---|---|
| MBR | 4 primary (or 3+1 extended) | ~2TB | Legacy BIOS | Older hardware |
| GPT | 128 (default) | Practically unlimited | UEFI | Servers, 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:
| Partition | Size | Filesystem | Purpose |
|---|---|---|---|
/boot | 1GB | ext4 | Kernel and GRUB |
/ | 20GB | XFS | Root filesystem |
swap | 2x RAM (min 4–8GB) | swap | Virtual memory |
/home | 50GB | ext4/XFS | User data |
/var | 20GB | XFS | Logs, packages |
/tmp | 5GB | ext4 | Temporary files |
/opt | Optional | XFS | Third-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
| Tool | Use Case | Notes |
|---|---|---|
fdisk | Interactive MBR partitioning | MBR only, simple CLI |
parted | Scriptable, supports large disks | MBR + GPT, CLI/interactive |
gdisk | GPT specialist | Like fdisk for GPT |
lsblk | List devices and partitions | Useful for identifying disks |
blkid | View UUIDs/filesystem types | Essential for /etc/fstab |
lvcreate (LVM) | Dynamic volumes | Requires 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