- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud

Creating Swap Space on a Linux System
Swap space is used by the system to store memory pages or blocks that are used less frequently to free up space in the physical RAM. In this hands-on lab, you will be tasked with creating and enabling a swap partition and a swap file and ensuring that they persist through a reboot.

Lab Info
Table of Contents
-
Challenge
Create and enable a swap partition using /dev/xvdg1.
- Use the
mkswap
command to create swap space on/dev/xvdg1
:
mkswap /dev/xvdg1
- Use the
swapon
command to enable the swap partition:
swapon /dev/xvdg1
- Use the
-
Challenge
Add an entry to /etc/fstab to ensure that the swap partition persists though a reboot (use the UUID).
Obtain the UUID for the partition using the
blkid
command:- Use the editor of your choosing (i.e.,
vim
,nano
, etc.) to add an entry to/etc/fstab
for the swap partition:
vim /etc/fstab
- At the bottom of the file add the following entry:
UUID=partition_UUID swap swap sw 0 0
- Use the editor of your choosing (i.e.,
-
Challenge
Create and enable a 1 GB swap file in the root directory called "extraswap".
- Use the
dd
command to create a 1 GB file called extraswap:
dd if=/dev/zero of=/extraswap bs=1M count=1024
- Update the permissions on the swap file to be read right only for the root user:
chmod 600 /extraswap
- Use the
mkswap
command to turn extraswap into a swap file:
mkswap /extraswap
- Use the
swapon
command to enable the swap file:
swapon /extraswap
- Use the
-
Challenge
Add an entry to /etc/fstab to ensure that the swap file persists through a reboot (use the full path to the file name).
- Use the editor of your choosing (i.e., vim, nano, etc) to add an entry to
/etc/fstab
for the swap file:
vim /etc/fstab
- At the bottom of the file add the following entry:
/extraswap swap swap sw 0 0
- Use the editor of your choosing (i.e., vim, nano, etc) to add an entry to
About the author
Real skill practice before real-world application
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.