System Configuration ubuntudebiancentos beginner

Create Swap Partition

Create a 2GB swap partition

Overview

Create a 2GB swap partition

Commands

This will create a 2GB swap partition, continue?

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab

Use Cases

VPS with < 2GB memory, sudden memory usage spikes, compiling large projects.

Prerequisites

Sufficient disk space.

FAQ

  • Priority → check the swappiness value: cat /proc/sys/vm/swappiness
  • View Disk Usage