Red Hat System Administration II · RH134

Chapter 10

Managing Basic Storage

Partitioning with parted · Creating filesystems · /etc/fstab · Swap
CIS238RH — Mesa Community College
Partition a disk, create and mount file systems, configure persistent mounts in /etc/fstab, and create and enable swap space.

Key Commands

  • parted
  • mkfs.xfs
  • blkid
  • mount -a
  • mkswap
  • swapon
TermMeaning
Disk / block deviceThe raw physical (or virtual) storage device, e.g. /dev/sdb
PartitionA defined section of a disk, e.g. /dev/sdb1
FilesystemThe structure that organizes files and directories on a partition
Mount pointThe directory a filesystem is attached to and accessed through
Why It MattersEach layer is a separate step. Knowing which layer a problem is in narrows the search.
# Confirm the device you're about to partition (always double-check!)
lsblk

# Open parted interactively on a specific disk
sudo parted /dev/sdb

# Inside parted: create a GPT partition table (required before adding partitions)
(parted) mklabel gpt

# Create a primary partition spanning most of the disk
(parted) mkpart primary 0% 100%

# Show the current partition layout
(parted) print

# Exit parted
(parted) quit
# Or, non-interactively in a single command line
sudo parted /dev/sdb --script mklabel gpt mkpart primary 0% 100%

# Confirm the kernel sees the new partition
lsblk /dev/sdb
Warning — parted Has No Save StepEach change is written to disk immediately. Confirm the device with lsblk first.
# Create an XFS filesystem (RHEL's default) on the new partition
sudo mkfs.xfs /dev/sdb1

# Or ext4, if that's what you need
sudo mkfs.ext4 /dev/sdb1

# Confirm the filesystem type and get its UUID
blkid /dev/sdb1
FilesystemNotes
XFSRHEL's default; scales well to very large filesystems, but cannot be shrunk
ext4Mature and widely compatible; supports both growing and shrinking
TipIf you might need to shrink a filesystem later, choose ext4.

A manual mount doesn't survive a reboot. Permanent mounts go in /etc/fstab.

# /etc/fstab fields:
# device  mount-point  fs-type  options  dump  pass
UUID=1a2b3c4d-...  /data  xfs  defaults  0  2
Tip — Prefer UUID Over /dev/sdXDevice names can change between boots; a UUID belongs to the filesystem itself.
# Get the UUID to use in fstab (preferred over a raw device name,
# which can shift if disks are added/removed)
blkid /dev/sdb1

# Create the mount point
sudo mkdir -p /data

# After editing /etc/fstab, test it WITHOUT rebooting
sudo mount -a

# Confirm it mounted as expected
df -h /data
Warning — Test Before You RebootA bad fstab entry can drop the system into emergency mode at boot. On RHEL 9 and later, also run sudo systemctl daemon-reload after editing fstab.
# Format a partition as swap
sudo mkswap /dev/sdb2

# Enable it immediately
sudo swapon /dev/sdb2

# Confirm it's active
swapon --show
free -h
# Make it persistent by adding to /etc/fstab
UUID=5e6f7a8b-...  none  swap  defaults  0  0
Note — Swap FilesA swap file works the same way: create it with fallocate or dd, format it with mkswap. It's easier to resize than a partition.
# Disk space usage across mounted filesystems
df -h

# Check and repair a filesystem (UNMOUNTED only)
sudo umount /data
sudo fsck /dev/sdb1
sudo mount /data
Warning — Never fsck a Mounted FilesystemAnd for XFS, fsck does nothing. Use xfs_repair on the unmounted device instead.
partition table
Disk structure defining how a disk is divided, such as GPT
parted
Creates and changes partitions; changes apply immediately
mkfs
Commands that create a filesystem, such as mkfs.xfs
/etc/fstab
Lists filesystems to mount automatically at boot
UUID
A unique, stable filesystem identifier, preferred in fstab
swap
Disk space used to extend memory under pressure
fsck
Checks and repairs filesystems; run only on unmounted filesystems
  1. What are the four layers between a physical disk and a file you can open, in order?
  2. Why confirm a device name with lsblk before running parted?
  3. What is a key practical limitation of XFS compared with ext4?
  4. Why use a UUID instead of a name like /dev/sdb1 in /etc/fstab?
  5. Which command tests a new /etc/fstab entry without rebooting?
  6. What two commands format /dev/sdc1 as swap and activate it immediately?
  7. Why must a filesystem be unmounted before running fsck?