Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Managing Swap Files and Partitions

Managing swap files and partitions may be a necessary system administration task, if our system ever runs low on memory. In this activity, we will be creating a swap partition and a swap file. We will also be looking at activating and deactivating swap space, viewing swap usage, and making swap space available persistently. At the conclusion, we will understand how to work with swap files and partitions when needed to augment system memory.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Intermediate
Last updated
Apr 06, 2025
Duration
30m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Create a Persistent 1 GB Swap Partition

    Using fdisk, create the swap partition:

    sudo -i
    fdisk /dev/xvdg
    

    Press the following to create the partition:

    • n for new partition
    • Enter to select the default (primary) type
    • Enter for the default first sector
    • +1G for the size of the partition
    • t to change the type
    • L to list the types
    • 82 for Linux Swap
    • w to write changes and quit

    Execute mkswap to format the partition:

    mkswap /dev/xvdg1
    

    Add an entry to /etc/fstab:

    /dev/xvdg1   none     swap    defaults        0 0
    

    Verify swap partition is activated:

    swapon -s
    swapon -a
    swapon -s
    
  2. Challenge

    Create a Persistent 512 MB Swap File

    Use the dd command to create a 512 MB /root/extra.swp file:

    dd if=/dev/zero of=/root/extra.swp bs=1M count=512
    

    Format and activate the /root/extra.swap by executing mkswap:

    mkswap /root/extra.swp
    swapon /root/extra.swp
    

    Set more secure 0600 permissions using the chmod command:

    chmod 0600  /root/extra.swp
    ls -l /root/extra.swp
    

    Add an entry to /etc/fstab to activate the swap file:

    /root/extra.swp none swap defaults 0 0
    

    Activate the swap file entry:

    swapoff /root/extra.swp
    swapon -a
    swapon -s
    
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

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.

Get started with Pluralsight