Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

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.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 15m
Published
Clock icon Jun 19, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    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

  2. 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:

    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

  3. Challenge

    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

  4. 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).

    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

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

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.

Start learning by doing today

View Plans