- Lab
- A Cloud Guru
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.
Path 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
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.