Home > Package & System Management > swapon

swapon: Activate Swap Space

The swapon command is used on Linux systems to activate a device or file for use as swap space. Swap space is an area on the hard disk that the system uses to store data when physical RAM is insufficient, playing a crucial role in system performance.

Overview

swapon activates a specified swap partition or swap file by adding it to the system's virtual memory space. This helps the system cope with low RAM situations and maintain overall stability.

Key Features

  • Activate swap partitions or files
  • Activate all swap spaces defined in /etc/fstab
  • Display information about currently active swap spaces
  • Set the priority of swap spaces

Key Options

Commonly used options with the swapon command.

Activation and Information Display

Advanced Settings

Generated command:

Try combining the commands.

Description:

`swapon` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Various examples of managing swap space using the swapon command.

Activate a Specific Swap Partition

sudo swapon /dev/sdb2

Activates the /dev/sdb2 partition as swap space.

Activate a Specific Swap File

sudo swapon /swapfile

Activates the file at /swapfile as swap space.

Activate All Swap Defined in /etc/fstab

sudo swapon -a

Used to manually activate swap spaces that are set to be automatically activated at system boot.

Check Information of Currently Active Swap Devices

swapon --show

Displays detailed information about the swap spaces currently active on the system in a table format.

Summary of Swap Space Usage

swapon -s

Displays a summary of the total size, used space, and free space of active swap spaces.

Tips & Precautions

Useful tips and precautions when using the swapon command.

Swap Space Management Tips

  • Swap spaces must be formatted with the `mkswap` command before they can be activated.
  • To use swap space permanently, its information must be added to the `/etc/fstab` file.
  • Use the `swapoff` command to deactivate swap spaces.
  • When creating a swap file, create the file using the `dd` command, format it with `mkswap`, and then activate it with `swapon`.

Precautions

  • Permissions: The swapon command modifies system settings, so root privileges are required (use sudo).
  • Performance Impact: Swap space is on the hard disk and is much slower than RAM. Excessive swap usage can lead to system performance degradation.
  • File System: Swap files are created on top of regular file systems. If the underlying file system is corrupted, the swap file can also be affected.


Same category commands