Creating Swap Space on a Linux System

Get Started
15 minutes
  • 4 Learning Objectives

About this Hands-on Lab

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.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create and enable a swap partition using /dev/xvdg1.
  1. Use the mkswap command to create swap space on /dev/xvdg1:

mkswap /dev/xvdg1

  1. Use the swapon command to enable the swap partition:

swapon /dev/xvdg1

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:

  1. 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

  1. At the bottom of the file add the following entry:

UUID=partition_UUID swap swap sw 0 0

Create and enable a 1 GB swap file in the root directory called “extraswap”.
  1. Use the dd command to create a 1 GB file called extraswap:

dd if=/dev/zero of=/extraswap bs=1M count=1024

  1. Update the permissions on the swap file to be read right only for the root user:

chmod 600 /extraswap

  1. Use the mkswap command to turn extraswap into a swap file:

mkswap /extraswap

  1. Use the swapon command to enable the swap file:

swapon /extraswap

Add an entry to /etc/fstab to ensure that the swap file persists through a reboot (use the full path to the file name).
  1. 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

  1. At the bottom of the file add the following entry:

/extraswap swap swap sw 0 0

Additional Resources

You are a part of a team that supports the back end servers for your web farm. The physical memory on the hosts is being heavily utilized and could cause major issues on the servers if they were to run out of memory. There is an initiative to increase the amount of physical memory on the hosts as well as to add additional servers to the pool. In the meantime, you have been tasked with adding swap space to the hosts in order to provide greater virtual memory overhead.

A partition has been provided, /dev/xvdg1, that should be used as a swap partition. Create the swap space on the partition, enable it, and then add an entry to /etc/fstab to ensure that it will persist through a reboot. You will also need to create a swap file to be used as additional swap space. The file should be 1GB in size, created using the dd command. Once created, you will need to turn it into swap space, enable it, and ensure that it will also persist through a reboot.

Note:

  • All tasks should be performed as the root user.
  • The UUID of the partition will differ for each attempt.
What are Hands-on Labs

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?