Skip to content

A lightweight, interactive bash script that automatically sets up and optimizes a swap file on Linux VPS instances. Perfect for low-RAM servers (1GB or less) to prevent out-of-memory errors. Features smart defaults, existing swap detection, and proper system configuration.

Notifications You must be signed in to change notification settings

iamhelitha/swap-file-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’Ύ Swap File Auto Setup Script

This script allows you to easily create and configure swap memory on your Linux VPS (ideal for low-RAM servers like those with 1GB RAM). It interactively guides you through the process and applies sensible defaults if you just press Enter.


πŸš€ Quick Install

You can run this script in one line directly from your terminal:

bash <(curl -Ls https://raw.githubusercontent.com/iamhelitha/swap-file-setup/main/install.sh)

πŸ“Œ Features

  • Interactive terminal prompts with default options
  • Auto-creates and enables a swap file
  • Configures swappiness and cache pressure
  • Works with fallocate or falls back to dd
  • Permanently persists settings across reboots
  • Detects and updates existing swap files if requested

πŸ–₯️ Supported Operating Systems

  • Ubuntu (16.04 and above)
  • Debian (9 and above)
  • Other systemd-based Linux distributions (may require minor tweaks)

⚠️ Not tested on CentOS, Fedora, or Alpine β€” feel free to open issues if you'd like support added!


πŸ› οΈ What It Does

  1. Checks if swap is already enabled and offers to update it
  2. Asks for the desired swap size (e.g. 1G, 512M) β€” defaults to 1G
  3. Creates a swap file and enables it
  4. Configures vm.swappiness and vm.vfs_cache_pressure
  5. Adds swap file to /etc/fstab for persistence
  6. Shows memory status at the end

🧩 Example Output

==============================
  SWAP FILE SETUP FOR VPS
==============================

Enter swap size (e.g., 1G, 512M) [default: 1G]:
[*] Creating a 1G swap file at /swapfile...

[βœ“] Swap successfully enabled with 1G

πŸ™‹β€β™‚οΈ Why Use Swap?

Swap helps extend available memory when RAM is full β€” crucial on small VPS servers where running MySQL, Apache, Node, or other services can cause memory pressure.


πŸ“ƒ License

MIT License. Use freely and modify as needed.

About

A lightweight, interactive bash script that automatically sets up and optimizes a swap file on Linux VPS instances. Perfect for low-RAM servers (1GB or less) to prevent out-of-memory errors. Features smart defaults, existing swap detection, and proper system configuration.

Topics

Resources

Stars

Watchers

Forks

Languages