Operations 3 min read

How to Create and Manage Swap Partitions on Linux

This article explains the purpose of swap partitions, shows how to check current swap usage, and provides step‑by‑step instructions for creating swap space both via a dedicated disk partition and by using a swap file on a Linux server.

php Courses
php Courses
php Courses
How to Create and Manage Swap Partitions on Linux

Swap partitions act as overflow memory on Linux systems, allowing the kernel to move rarely used data to disk when physical RAM is insufficient, which is a cost‑effective way to extend usable memory.

The article first demonstrates how to view current memory and swap usage with the # free -h command, showing an example output where a 1 GB swap partition is partially used.

It then describes two methods for creating swap space:

Creating a swap partition on a physical disk

Partition the disk using a partitioning tool (illustrated with an image).

Format the new partition as swap with mkswap /dev/sda5.

Activate the swap partition using swapon /dev/sda5 (no mounting required).

Creating swap space using a file

Allocate a large file on an existing filesystem (illustrated with images).

Set up the file as swap with mkswap /path/to/swapfile (the exact command is implied).

Enable the swap file with swapon /path/to/swapfile.

The article advises keeping swap size under 2 GB for typical use and emphasizes that swap should be used as a backup rather than a primary memory source because excessive swapping can degrade system performance.

Finally, it provides a link to the original source for further reading.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsLinuxcommand-lineSystem AdministrationPartitionSwap
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.