Lab activity
Swap Management
Learn how to manage Linux swap space by creating and activating swap files and swap partitions, configuring swap priorities, monitoring usage, and adjusting kernel swappiness.
Overview
In this lab, you will learn how to manage swap space in Linux using swap files and virtual disk images. You will inspect current memory and swap usage, create and activate swap files, configure swap priorities, and prepare a loop device as a swap area. You will also adjust the kernel's swappiness value, explore the format for persistent swap entries in /etc/fstab, and safely disable swap areas and clean up the lab environment.
Learning Outcomes
- Inspect memory and swap usage using
free -h,swapon --show, and/proc/swaps. - Check the current kernel swappiness value using
sysctl. - Create swap files with
dd, set secure permissions, and initialize them usingmkswap. - Activate and deactivate swap files using
swaponandswapoff. - Create a virtual disk image, attach it as a loop device, and use it as a swap area.
- Temporarily modify the kernel's swappiness value using
sysctl -w. - Understand the format of
/etc/fstabentries for persistent swap configuration.
Key Concepts
- Swap space: Understand how Linux uses swap files and swap areas to supplement physical memory.
- Swap initialization: Use
mkswapto prepare a file or block device for swap. - Swap activation: Enable and disable swap areas with
swaponandswapoff. - Swap priority: Control the preference for swap areas using priority values.
- Swappiness: Inspect and temporarily adjust the kernel parameter that influences swap usage.
- Persistent configuration: Learn the syntax for configuring swap files and priorities in
/etc/fstab. - Loop devices: Practice using a virtual disk image as a swap area without requiring a dedicated physical disk.
Why Needed?
- Swap management is an important Linux system administration skill for managing memory resources.
- Understanding swap priorities helps administrators control how multiple swap areas are used.
- Monitoring swap usage and adjusting swappiness supports informed system performance troubleshooting.
- Practicing swap configuration and cleanup builds hands-on skills relevant to LFCS preparation and real-world Linux administration.