Skip to content

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.

RAID LevelMin DisksRedundancyUsable SpaceUse Case
RAID 02NoneN x disk sizeHigh performance, non-critical data
RAID 12Mirror1 x disk sizeOS disk, critical data
RAID 53Single disk fault tolerance(N-1) x disk sizeGeneral storage
RAID 104Mirror + stripeN/2 x disk sizeDatabases, high IOPS
Install mdadm
sudo dnf install mdadm -y

Before creating a RAID array, confirm the disks have no existing partitions:

View available disks
lsblk
Confirm the target disks hold no data you need to keep
lsblk -f /dev/sdb /dev/sdc
sudo blkid /dev/sdb /dev/sdc
Wipe existing signatures from disks
sudo wipefs -a /dev/sdb
sudo wipefs -a /dev/sdc
Create a RAID 1 array
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
Check RAID array status
cat /proc/mdstat
View detailed array information
sudo mdadm --detail /dev/md0
Create a RAID 5 array (three disks)
sudo mdadm --create /dev/md1 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd
Create a RAID 10 array (four disks)
sudo mdadm --create /dev/md2 --level=10 --raid-devices=4 /dev/sdb /dev/sdc /dev/sdd /dev/sde
Create an XFS filesystem
sudo mkfs.xfs /dev/md0
Create mount point and mount
sudo mkdir -p /mnt/raid
sudo mount /dev/md0 /mnt/raid
Add to fstab for automatic mounting at boot
echo '/dev/md0 /mnt/raid xfs defaults 0 0' | sudo tee -a /etc/fstab

The mdadm configuration must be saved, otherwise the array may not auto-assemble after reboot:

Save RAID configuration to mdadm.conf
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm.conf
Update initramfs to include RAID configuration
sudo dracut --force
View real-time RAID array status
cat /proc/mdstat
View detailed array information
sudo mdadm --detail /dev/md0
Enable mdadm email monitoring
sudo mdadm --monitor [email protected] --delay=300 /dev/md0 --daemonise

You can also use systemd for automatic monitoring:

Enable the mdmonitor service
sudo systemctl enable mdmonitor
sudo systemctl start mdmonitor
Simulate a disk failure
sudo mdadm --manage /dev/md0 --fail /dev/sdc
View degraded status
cat /proc/mdstat
sudo mdadm --detail /dev/md0
Remove the failed disk
sudo mdadm --manage /dev/md0 --remove /dev/sdc
Add a new disk to rebuild
sudo mdadm --manage /dev/md0 --add /dev/sdf
Monitor rebuild progress
watch cat /proc/mdstat
Add a hot spare disk to the array
sudo mdadm --manage /dev/md0 --add-spare /dev/sdg

When a disk in the array fails, the hot spare will automatically join the rebuild process.

Swap space provides additional virtual memory when physical RAM is insufficient. It can be implemented via a swap partition or a swap file.

View current Swap usage
free -h
View all Swap devices
swapon --show

Starting with EL 8, swap files are recommended over swap partitions for greater flexibility:

Create a 4GB Swap file
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
Set correct permissions
sudo chmod 600 /swapfile
Format as Swap
sudo mkswap /swapfile
Enable the Swap file
sudo swapon /swapfile
Verify Swap is enabled
swapon --show
free -h
Add to fstab for automatic mounting at boot
echo '/swapfile none swap defaults 0 0' | sudo tee -a /etc/fstab

If you need a dedicated partition for Swap:

Use fdisk to create a Swap partition (type 82)
sudo fdisk /dev/sdb

In fdisk: n to create a new partition, t to change type to 82 (Linux swap), w to save.

Format the Swap partition
sudo mkswap /dev/sdb1
Enable the Swap partition
sudo swapon /dev/sdb1
Add to fstab
echo '/dev/sdb1 none swap defaults 0 0' | sudo tee -a /etc/fstab
Disable the current Swap
sudo swapoff /swapfile
Recreate a larger Swap file (8GB)
sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Disable and remove the Swap file
sudo swapoff /swapfile
sudo rm /swapfile

Remember to also remove the corresponding line from /etc/fstab.

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
View the current swappiness value
cat /proc/sys/vm/swappiness
Temporarily change swappiness
sudo sysctl vm.swappiness=10
Permanently change swappiness
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.d/99-swappiness.conf
sudo sysctl -p /etc/sysctl.d/99-swappiness.conf

Recommended values:

Scenarioswappiness
Database server10
Web server10-30
Desktop system60
Server with ample RAM1-10

Disk quotas are used to limit the disk usage of users or groups on a filesystem.

Quota support must be enabled at mount time:

Edit fstab to enable user and group quotas
sudo vi /etc/fstab

Modify the mount options to include uquota,gquota:

fstab example
/dev/md0 /mnt/data xfs defaults,uquota,gquota 0 0
Remount the filesystem
sudo umount /mnt/data
sudo mount /mnt/data

Or remount without unmounting:

Remount in place
sudo mount -o remount,uquota,gquota /mnt/data
View quota status report
sudo xfs_quota -x -c 'report -h' /mnt/data
View all user quotas
sudo xfs_quota -x -c 'report -u -h' /mnt/data
View all group quotas
sudo xfs_quota -x -c 'report -g -h' /mnt/data
Set soft limit 5GB and hard limit 10GB for a user
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)
Set inode quota (limit number of files)
sudo xfs_quota -x -c 'limit isoft=10000 ihard=15000 testuser' /mnt/data
Set disk quotas for a group
sudo xfs_quota -x -c 'limit -g bsoft=50g bhard=100g devteam' /mnt/data
View quota usage for a specific user
sudo xfs_quota -x -c 'quota -u -h testuser' /mnt/data
Set the soft limit grace period to 7 days
sudo xfs_quota -x -c 'timer -u 7d' /mnt/data
  1. RAID is not a backup — RAID only provides redundancy; it does not replace data backups
  2. Monitor RAID status — Regularly check array health and enable email alerts
  3. Configure hot spares — Critical arrays should have hot spare disks for automatic rebuilding
  4. Plan Swap appropriately — Generally 1-2x physical RAM is recommended (up to 8GB max)
  5. Tune swappiness — Database and high-performance workloads should use a lower swappiness value
  6. Use quotas to prevent full disks — Configure disk quotas in multi-user environments to prevent one user from filling all space