RED HAT ENTERPRISE LINUX

Storage Management

Partitions, Filesystems, and Swap from the Command Line

College-Level Course Module | RHEL System Administration

Learning Objectives

1
Identify and examine storage devices

Use lsblk, fdisk, and blkid to view disk information

2
Create and manage disk partitions

Use fdisk and parted to partition disks with MBR or GPT

3
Create and mount filesystems

Format partitions with XFS or ext4 and mount them for use

4
Configure swap space

Create and activate swap partitions and swap files

Storage Concepts

Linux storage follows a hierarchy: physical disks are divided into partitions, partitions are formatted with filesystems, and filesystems are mounted to directories.

Physical Disk

/dev/sda, /dev/nvme0n1. The raw storage device. Appears as a block device in /dev.

Partition

/dev/sda1, /dev/nvme0n1p1. A section of a disk. Has a defined start and end.

Filesystem

XFS, ext4, vfat. Organizes data into files and directories. Created with mkfs.

Mount Point

/mnt/data, /home. Directory where filesystem is attached. Makes data accessible.

The workflow: Identify disk → Create partition → Create filesystem → Mount to directory → (Optional) Add to /etc/fstab for persistence

Identifying Devices

# List block devices with lsblk
[root@server ~]# lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda             8:0    0   100G  0 disk 
├─sda1          8:1    0     1G  0 part /boot
└─sda2          8:2    0    99G  0 part 
  ├─rhel-root 253:0    0    50G  0 lvm  /
  └─rhel-swap 253:1    0     4G  0 lvm  [SWAP]
sdb             8:16   0    50G  0 disk 
nvme0n1       259:0    0   500G  0 disk 
└─nvme0n1p1   259:1    0   500G  0 part /data

# Show filesystems with lsblk -f
[root@server ~]# lsblk -f
NAME        FSTYPE      FSVER    LABEL UUID                                   MOUNTPOINTS
sda                                                                           
├─sda1      xfs                        a1b2c3d4-...                            /boot
└─sda2      LVM2_member LVM2 001       e5f6g7h8-...                            
sdb                                                                           

# Show all block device attributes
[root@server ~]# blkid
/dev/sda1: UUID="a1b2c3d4-..." TYPE="xfs" PARTUUID="..."
/dev/sda2: UUID="e5f6g7h8-..." TYPE="LVM2_member" PARTUUID="..."

Device Naming

Device TypeDisk NamePartition NameExample
SATA/SAS/USB/dev/sdX/dev/sdX#/dev/sda, /dev/sda1
NVMe SSD/dev/nvmeXnY/dev/nvmeXnYp#/dev/nvme0n1, /dev/nvme0n1p1
Virtual (VirtIO)/dev/vdX/dev/vdX#/dev/vda, /dev/vda1
SD Card/MMC/dev/mmcblkX/dev/mmcblkXp#/dev/mmcblk0, /dev/mmcblk0p1
# View detailed disk information
[root@server ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: Virtual disk    
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

# Check if disk has partitions
[root@server ~]# cat /proc/partitions | grep sdb
   8       16   52428800 sdb
Device names can change! Use UUIDs or labels in /etc/fstab, not device names like /dev/sdb1. Device order may change on reboot.

MBR vs GPT

MBR (Master Boot Record)

  • Legacy standard, widely compatible
  • Maximum disk size: 2 TB
  • Maximum 4 primary partitions
  • Or 3 primary + 1 extended (with logical)
  • Use: Legacy systems, small disks
  • Tool: fdisk

GPT (GUID Partition Table)

  • Modern standard, UEFI systems
  • Maximum disk size: 9.4 ZB (huge)
  • Up to 128 partitions (default)
  • No extended/logical distinction
  • Use: Modern systems, large disks
  • Tool: gdisk or parted
MBR Partition Layout
MBR
Primary 1
Primary 2
Log 5
Log 6

Partitioning with fdisk

# Start fdisk on a disk
[root@server ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.37.4).
Command (m for help): n          # New partition
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p           # Primary partition
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048): [Enter]  # Accept default
Last sector... (+/-sectors or +/-size{K,M,G,T,P}): +10G  # 10 GB partition

Created a new partition 1 of type 'Linux' and of size 10 GiB.

Command (m for help): p          # Print partition table
Device     Boot   Start      End  Sectors Size Id Type
/dev/sdb1          2048 20973567 20971520  10G 83 Linux

Command (m for help): w          # Write changes and exit
The partition table has been altered.
Syncing disks.
Key commands: n=new, p=print, d=delete, t=change type, w=write, q=quit without saving

Partitioning with parted

# Start parted on a disk
[root@server ~]# parted /dev/sdb
(parted) print
Error: /dev/sdb: unrecognised disk label

# Create GPT partition table
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed...
(parted)

# Create a partition
(parted) mkpart primary xfs 1MiB 10GiB
(parted) mkpart primary xfs 10GiB 20GiB

# View partitions
(parted) print
Number  Start   End     Size    File system  Name     Flags
 1      1049kB  10.7GB  10.7GB               primary
 2      10.7GB  21.5GB  10.7GB               primary

(parted) quit

# One-liner (non-interactive)
[root@server ~]# parted /dev/sdb mkpart primary xfs 20GiB 30GiB
parted changes are immediate! Unlike fdisk, parted writes to disk as you go. There's no "write" command - be careful!

Filesystem Types

XFS

RHEL Default

Excellent for large files

Good parallel I/O

Can grow, not shrink

Robust journaling

ext4

Traditional Linux

Mature, well-tested

Can grow AND shrink

Good general purpose

Better for small files

vfat

Cross-Platform

Windows compatible

USB drives, EFI

No permissions

4GB file size limit

# Check which filesystems are supported
[root@server ~]# cat /proc/filesystems | grep -v nodev
	xfs
	ext4
	ext3
	vfat
	iso9660

# View filesystem of mounted partitions
[root@server ~]# df -Th
Filesystem          Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs       50G  4.5G   46G   9% /
/dev/sda1            xfs      1014M  186M  829M  19% /boot

Creating Filesystems

# Create XFS filesystem (RHEL default)
[root@server ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
data     =                       bsize=4096   blocks=2621440, imaxpct=25
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
realtime =none                   extsz=4096   blocks=0, rtextents=0

# Create ext4 filesystem
[root@server ~]# mkfs.ext4 /dev/sdb2
Creating filesystem with 2621440 4k blocks and 655360 inodes
Superblock backups stored on blocks: ...

# Create filesystem with label
[root@server ~]# mkfs.xfs -L "data_storage" /dev/sdb1

# Force creation (overwrite existing)
[root@server ~]# mkfs.xfs -f /dev/sdb1

# Verify filesystem
[root@server ~]# blkid /dev/sdb1
/dev/sdb1: LABEL="data_storage" UUID="abc123..." TYPE="xfs"
⚠ Warning: mkfs destroys all data on the partition! Double-check the device name before running.

Mounting Filesystems

# Create mount point directory
[root@server ~]# mkdir /mnt/data

# Mount the filesystem
[root@server ~]# mount /dev/sdb1 /mnt/data

# Verify the mount
[root@server ~]# mount | grep sdb1
/dev/sdb1 on /mnt/data type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8)

# Check available space
[root@server ~]# df -h /mnt/data
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1        10G   33M   10G   1% /mnt/data

# Mount using UUID (more reliable)
[root@server ~]# mount UUID="abc123-def456-..." /mnt/data

# Mount using label
[root@server ~]# mount LABEL="data_storage" /mnt/data

# Mount with specific options
[root@server ~]# mount -o ro,noexec /dev/sdb1 /mnt/data

# Unmount when done
[root@server ~]# umount /mnt/data

Persistent Mounts: /etc/fstab

# View current fstab
[root@server ~]# cat /etc/fstab
#
# /etc/fstab - Static filesystem mount table
#
#                                            
UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890 /           xfs     defaults         0 0
UUID=b2c3d4e5-f6a7-8901-bcde-f12345678901 /boot       xfs     defaults         0 0
/dev/mapper/rhel-swap                     none        swap    defaults         0 0

# Get UUID for new partition
[root@server ~]# blkid /dev/sdb1
/dev/sdb1: UUID="f1e2d3c4-b5a6-9807-6543-210987654321" TYPE="xfs"

# Add entry to /etc/fstab
[root@server ~]# vim /etc/fstab
# Add this line:
UUID=f1e2d3c4-b5a6-9807-6543-210987654321 /mnt/data   xfs     defaults         0 0

# Test fstab entry (mount all unmounted entries)
[root@server ~]# mount -a

# Verify
[root@server ~]# df -h /mnt/data
⚠ Critical: A typo in /etc/fstab can prevent system boot! Always test with mount -a before rebooting.

fstab Fields

UUID=abc123... /mnt/data xfs defaults 0 0

FieldPurposeExamples
DeviceWhat to mountUUID=..., LABEL=..., /dev/sdb1
Mount PointWhere to mount/mnt/data, /home, /var/log
TypeFilesystem typexfs, ext4, swap, auto
OptionsMount optionsdefaults, ro, noexec, nosuid
DumpBackup with dump0 (don't backup), 1 (backup)
fsckCheck order at boot0 (skip), 1 (first), 2 (after 1)
# Common mount options
defaults    = rw,suid,dev,exec,auto,nouser,async
ro          = Read-only
noexec      = Prevent execution of binaries
nosuid      = Ignore setuid/setgid bits
noatime     = Don't update access times (performance)
nofail      = Don't fail boot if device missing

# Example with options
UUID=abc123... /mnt/backup xfs defaults,noexec,nosuid,nofail 0 0

Introduction to Swap

Swap is disk space used as virtual memory when physical RAM is full. The kernel moves inactive memory pages to swap, freeing RAM for active processes.

Swap Partition

A dedicated partition formatted as swap. Traditional approach. Fixed size, very fast.

Swap File

A file on a filesystem used as swap. Flexible sizing. Can be added without repartitioning.

# Check current swap status
[root@server ~]# swapon --show
NAME           TYPE      SIZE USED PRIO
/dev/dm-1      partition   4G   0B   -2

# Check memory and swap usage
[root@server ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           7.8Gi       2.1Gi       4.2Gi       128Mi       1.5Gi       5.3Gi
Swap:          4.0Gi          0B       4.0Gi
How much swap? Traditional rule: 2x RAM. Modern guidance: at least equal to RAM for hibernation, otherwise 2-8GB is often sufficient depending on workload.

Creating Swap Partition

# Create partition with fdisk (set type to 82 for swap)
[root@server ~]# fdisk /dev/sdb
Command (m for help): n          # New partition
Partition number: 3
First sector: [Enter]
Last sector: +2G
Command (m for help): t          # Change type
Partition number: 3
Hex code or alias: 82          # Linux swap type
Command (m for help): w          # Write and exit

# Format as swap
[root@server ~]# mkswap /dev/sdb3
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=swap-uuid-here-1234-567890abcdef

# Activate swap
[root@server ~]# swapon /dev/sdb3

# Verify
[root@server ~]# swapon --show
NAME      TYPE      SIZE USED PRIO
/dev/dm-1 partition   4G   0B   -2
/dev/sdb3 partition   2G   0B   -3
Three steps: 1) Create partition (type 82), 2) mkswap to format, 3) swapon to activate.

Persistent Swap

# Get UUID of swap partition
[root@server ~]# blkid /dev/sdb3
/dev/sdb3: UUID="swap-uuid-1234-5678-90ab-cdef12345678" TYPE="swap"

# Add to /etc/fstab
[root@server ~]# vim /etc/fstab
# Add this line:
UUID=swap-uuid-1234-5678-90ab-cdef12345678  none  swap  defaults  0  0

# Or use device name (less reliable)
/dev/sdb3  none  swap  defaults  0  0

# Test by deactivating and reactivating all swap
[root@server ~]# swapoff /dev/sdb3
[root@server ~]# swapon -a          # Activate all swap in fstab
[root@server ~]# swapon --show

# View swap entry in fstab
[root@server ~]# grep swap /etc/fstab
/dev/mapper/rhel-swap                         none  swap  defaults  0  0
UUID=swap-uuid-1234-5678-90ab-cdef12345678    none  swap  defaults  0  0
Mount point for swap: Use none or swap as the mount point. Swap isn't mounted to a directory.

Creating Swap File

# Create a 1GB swap file using dd
[root@server ~]# dd if=/dev/zero of=/swapfile bs=1M count=1024 status=progress
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 2.5 s, 429 MB/s
1024+0 records in
1024+0 records out

# Or use fallocate (faster)
[root@server ~]# fallocate -l 1G /swapfile

# Set correct permissions (required!)
[root@server ~]# chmod 600 /swapfile
[root@server ~]# ls -l /swapfile
-rw------- 1 root root 1073741824 Jan 20 14:00 /swapfile

# Format as swap
[root@server ~]# mkswap /swapfile
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)

# Activate
[root@server ~]# swapon /swapfile

# Add to /etc/fstab for persistence
/swapfile  none  swap  defaults  0  0

# Verify
[root@server ~]# swapon --show
Permissions matter! Swap file must be 600 (owner read/write only). World-readable swap is a security risk.

Managing Swap

# View all swap with details
[root@server ~]# swapon --show
NAME       TYPE       SIZE USED PRIO
/dev/dm-1  partition    4G  10M   -2
/swapfile  file         1G   0B   -3

# Set priority when activating
[root@server ~]# swapon -p 10 /swapfile

# Deactivate specific swap
[root@server ~]# swapoff /swapfile

# Deactivate all swap
[root@server ~]# swapoff -a

# Check swap usage
[root@server ~]# free -h
[root@server ~]# vmstat 1 3
procs -----------memory---------- ---swap--
 r  b   swpd   free   buff  cache   si   so
 1  0  10240 524288  65536 1048576    0    0

# Adjust swappiness (tendency to use swap)
[root@server ~]# sysctl vm.swappiness
vm.swappiness = 60
[root@server ~]# sysctl vm.swappiness=10    # Reduce swap usage
vm.swappiness: 0-100. Higher values = more aggressive swapping. Default is 60. Reduce to 10-20 for servers with plenty of RAM.

Complete Workflow

1

Identify disk: lsblk, fdisk -l to find available disk (e.g., /dev/sdb)

2

Create partition: fdisk /dev/sdb or parted /dev/sdb

3

Create filesystem: mkfs.xfs /dev/sdb1 or mkfs.ext4 /dev/sdb1

4

Create mount point: mkdir /mnt/data

5

Test mount: mount /dev/sdb1 /mnt/data

6

Get UUID: blkid /dev/sdb1

7

Add to fstab: UUID=... /mnt/data xfs defaults 0 0

8

Test fstab: umount /mnt/data && mount -a

Always test! Test mount before fstab. Test fstab with mount -a before reboot. Errors in fstab can prevent boot!

Best Practices

✓ Do

  • Use UUID in /etc/fstab
  • Test mounts before adding to fstab
  • Test fstab with mount -a before reboot
  • Label filesystems for easy identification
  • Use GPT for new disks (especially >2TB)
  • Use XFS for most workloads (RHEL default)
  • Document your storage layout
  • Use nofail for non-critical mounts

✗ Don't

  • Use device names in fstab (/dev/sdb1)
  • Skip testing before reboot
  • Format the wrong partition
  • Forget to create mount point
  • Ignore fstab syntax errors
  • Use MBR for disks >2TB
  • Make swap world-readable
  • Forget backups before partitioning
Recovery tip: If system won't boot due to fstab error, boot rescue mode, mount root filesystem, fix /etc/fstab, reboot.

Key Takeaways

1

Identify: lsblk, fdisk -l, blkid to view disks, partitions, and UUIDs.

2

Partition: fdisk for MBR, parted for GPT. Remember to write changes (fdisk) or they're immediate (parted).

3

Filesystem: mkfs.xfs or mkfs.ext4. Mount with mount command. Persist in /etc/fstab using UUID.

4

Swap: Partition or file. mkswap to format, swapon to activate. Add to /etc/fstab for persistence.

LAB EXERCISES

  • List all block devices with lsblk and lsblk -f
  • Create a partition on an available disk using fdisk
  • Create an XFS filesystem with a label
  • Mount the filesystem and add it to /etc/fstab
  • Create a 512MB swap file and activate it
  • Add the swap file to /etc/fstab and test with swapon -a

Next: Managing Logical Volumes