RAID & Swap Management
This guide covers three key storage management topics: creating and managing software RAID arrays with mdadm, creating and tuning Swap space, and controlling disk usage with XFS disk quotas.
Software RAID Basics (mdadm)
Section titled “Software RAID Basics (mdadm)”RAID Level Overview
Section titled “RAID Level Overview”| RAID Level | Min Disks | Redundancy | Usable Space | Use Case |
|---|---|---|---|---|
| RAID 0 | 2 | None | N x disk size | High performance, non-critical data |
| RAID 1 | 2 | Mirror | 1 x disk size | OS disk, critical data |
| RAID 5 | 3 | Single disk fault tolerance | (N-1) x disk size | General storage |
| RAID 10 | 4 | Mirror + stripe | N/2 x disk size | Databases, high IOPS |
Installing mdadm
Section titled “Installing mdadm”sudo dnf install mdadm -yPreparing Disks
Section titled “Preparing Disks”Before creating a RAID array, confirm the disks have no existing partitions:
lsblklsblk -f /dev/sdb /dev/sdcsudo blkid /dev/sdb /dev/sdcsudo wipefs -a /dev/sdbsudo wipefs -a /dev/sdcCreating RAID 1 (Mirror)
Section titled “Creating RAID 1 (Mirror)”sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdccat /proc/mdstatsudo mdadm --detail /dev/md0Creating RAID 5
Section titled “Creating RAID 5”sudo mdadm --create /dev/md1 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sddCreating RAID 10
Section titled “Creating RAID 10”sudo mdadm --create /dev/md2 --level=10 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sdeFormatting and Mounting RAID Arrays
Section titled “Formatting and Mounting RAID Arrays”sudo mkfs.xfs /dev/md0sudo mkdir -p /mnt/raidsudo mount /dev/md0 /mnt/raidecho '/dev/md0 /mnt/raid xfs defaults 0 0' | sudo tee -a /etc/fstabSaving RAID Configuration
Section titled “Saving RAID Configuration”The mdadm configuration must be saved, otherwise the array may not auto-assemble after reboot:
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.confsudo dracut --forceMonitoring RAID Arrays
Section titled “Monitoring RAID Arrays”cat /proc/mdstatsudo mdadm --detail /dev/md0You can also use systemd for automatic monitoring:
sudo systemctl enable mdmonitorsudo systemctl start mdmonitorSimulating Disk Failure and Rebuilding
Section titled “Simulating Disk Failure and Rebuilding”sudo mdadm --manage /dev/md0 --fail /dev/sdccat /proc/mdstatsudo mdadm --detail /dev/md0sudo mdadm --manage /dev/md0 --remove /dev/sdcsudo mdadm --manage /dev/md0 --add /dev/sdfwatch cat /proc/mdstatAdding a Hot Spare
Section titled “Adding a Hot Spare”sudo mdadm --manage /dev/md0 --add-spare /dev/sdgWhen a disk in the array fails, the hot spare will automatically join the rebuild process.
Swap Management
Section titled “Swap Management”Swap space provides additional virtual memory when physical RAM is insufficient. It can be implemented via a swap partition or a swap file.
Checking Current Swap Status
Section titled “Checking Current Swap Status”free -hswapon --showCreating a Swap File
Section titled “Creating a Swap File”Starting with EL 8, swap files are recommended over swap partitions for greater flexibility:
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096sudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfileswapon --showfree -hecho '/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstabCreating a Swap Partition
Section titled “Creating a Swap Partition”If you need a dedicated partition for Swap:
sudo fdisk /dev/sdbIn fdisk: n to create a new partition, t to change type to 82 (Linux swap), w to save.
sudo mkswap /dev/sdb1sudo swapon /dev/sdb1echo '/dev/sdb1 none swap defaults 0 0' | sudo tee -a /etc/fstabResizing Swap
Section titled “Resizing Swap”Enlarging a Swap File
Section titled “Enlarging a Swap File”sudo swapoff /swapfilesudo dd if=/dev/zero of=/swapfile bs=1M count=8192sudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfileRemoving Swap
Section titled “Removing Swap”sudo swapoff /swapfilesudo rm /swapfileRemember to also remove the corresponding line from /etc/fstab.
Swappiness Tuning
Section titled “Swappiness Tuning”The vm.swappiness parameter controls how aggressively the kernel uses Swap (0-100):
- 0 — Avoid using Swap as much as possible (only when memory is critically low)
- 10 — Suitable for database servers, reduces Swap usage
- 60 — System default
- 100 — Aggressively use Swap
cat /proc/sys/vm/swappinesssudo sysctl vm.swappiness=10echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.d/99-swappiness.confsudo sysctl -p /etc/sysctl.d/99-swappiness.confRecommended values:
| Scenario | swappiness |
|---|---|
| Database server | 10 |
| Web server | 10-30 |
| Desktop system | 60 |
| Server with ample RAM | 1-10 |
XFS Disk Quotas (xfs_quota)
Section titled “XFS Disk Quotas (xfs_quota)”Disk quotas are used to limit the disk usage of users or groups on a filesystem.
Enabling XFS Quotas
Section titled “Enabling XFS Quotas”Quota support must be enabled at mount time:
sudo vi /etc/fstabModify the mount options to include uquota,gquota:
/dev/md0 /mnt/data xfs defaults,uquota,gquota 0 0sudo umount /mnt/datasudo mount /mnt/dataOr remount without unmounting:
sudo mount -o remount,uquota,gquota /mnt/dataViewing Quota Status
Section titled “Viewing Quota Status”sudo xfs_quota -x -c 'report -h' /mnt/datasudo xfs_quota -x -c 'report -u -h' /mnt/datasudo xfs_quota -x -c 'report -g -h' /mnt/dataSetting User Quotas
Section titled “Setting User Quotas”sudo xfs_quota -x -c 'limit bsoft=5g bhard=10g testuser' /mnt/data- bsoft — Soft limit (can be temporarily exceeded within a grace period)
- bhard — Hard limit (absolute maximum, cannot be exceeded)
sudo xfs_quota -x -c 'limit isoft=10000 ihard=15000 testuser' /mnt/dataSetting Group Quotas
Section titled “Setting Group Quotas”sudo xfs_quota -x -c 'limit -g bsoft=50g bhard=100g devteam' /mnt/dataViewing Specific User Quotas
Section titled “Viewing Specific User Quotas”sudo xfs_quota -x -c 'quota -u -h testuser' /mnt/dataSetting Grace Period
Section titled “Setting Grace Period”sudo xfs_quota -x -c 'timer -u 7d' /mnt/dataBest Practices
Section titled “Best Practices”- RAID is not a backup — RAID only provides redundancy; it does not replace data backups
- Monitor RAID status — Regularly check array health and enable email alerts
- Configure hot spares — Critical arrays should have hot spare disks for automatic rebuilding
- Plan Swap appropriately — Generally 1-2x physical RAM is recommended (up to 8GB max)
- Tune swappiness — Database and high-performance workloads should use a lower swappiness value
- Use quotas to prevent full disks — Configure disk quotas in multi-user environments to prevent one user from filling all space