Linux Auto Swap File Creator

£1.95

Automatically size and create a persistent swap file on your Linux server, based on the RAM it actually has. One command, no manual tuning, safe to re-run. Works on AlmaLinux, Rocky, RHEL, Ubuntu and Debian.

Description

Linux Auto Swap File Creator – right-sized swap for small servers, in one command

Overview

New to swap sizing, or not sure you need this at all? How much swap does a Linux server need? explains the sizing rule this script uses and walks through doing it by hand.

Small cloud servers run out of memory long before they run out of work. A swap file is the cheapest insurance against a process being killed mid-job, but sizing it by hand is fiddly, and getting it wrong wastes disk or leaves you still exposed.

This script works out a sensible swap size from the RAM your machine actually has, creates the swap file, and makes it survive reboots. It is deliberately readable: you are running it as root, so you should be able to see exactly what it does before you do.

Key Features

  • Sizes on RAM, not guesswork. Below 2 GB of RAM you get 1.5x RAM, which is enough headroom to survive a spike. At 2 GB and above you get 1x RAM, capped at 4 GB, because swap beyond that is disk you will never touch. Never smaller than 512 MB.
  • Persistent across reboots. Adds the correct /etc/fstab entry, so the swap is still there after a restart.
  • Safe to run twice. Detects an existing /swapfile and resizes it only if the size is wrong. It will not stack duplicate swap files.
  • Checks there is room first. Verifies free space on the target filesystem before writing anything, and stops if there is not enough.
  • Preview before you commit. --dry-run prints the full plan – the RAM it detected, the size it chose, and every change it would make – without touching the system.
  • Tunable when you need it. --size to override the calculated size, --swappiness to set the kernel value (0-100, default 10), --force to recreate the swap file even when it is already correct, and --log to choose where the log goes.
  • Touches nothing else. It only ever manages /swapfile. It does not alter other swap devices or partitions.
  • Your swap file does not depend on us. Everything the script does for your server is done locally and offline. It needs no network to work, and it keeps working if our servers do not.
  • One optional call, and you can turn it off. After it finishes, the script reports whether the install succeeded so your licence shows an accurate number of remaining installs. It sends three things: your copy ID (printed in the script), success or failure, and a one-way hash of your machine ID so that reinstalling on the same server never costs you a second install. No hostname, no IP address, no file contents, nothing about what else you run. Set DD_NO_PHONE_HOME=1 to disable it, and the install behaves identically – the call is best-effort and never blocks.
  • It does not delete itself or clear your shell history. Some scripts do. We removed that behaviour deliberately: you should be able to read, keep and re-run what you paid for.

How It Works

  1. Download your copy from your DataDrifter account.
  2. Read it. It is plain, commented bash and we would rather you did.
  3. Run sudo bash linux-auto-swap-file-creator-2.1.2.sh --dry-run to see the plan.
  4. Run sudo bash linux-auto-swap-file-creator-2.1.2.sh to apply it.
  5. Reboot if you want to confirm persistence, or check with swapon --show.

Requirements / Prerequisites

  • A Linux server you have root on
  • util-linux and coreutils (present on every supported distribution by default)
  • Free disk space on the filesystem holding /swapfile
  • Not suitable for containers. Swap is a kernel-level facility that is not namespaced, so running this inside a container would alter the host. Use it on a VM or a bare-metal server.

What’s Included

  • The linux-auto-swap-file-creator script, version 2.1.2, individually marked for you
  • Licence covering 3 installs on your own infrastructure
  • Free updates within the 2.x series
  • Email support at [email protected]

Compatibility

Supports AlmaLinux 8 and 9, Rocky Linux 8 and 9, RHEL 8 and 9, Ubuntu 20.04, 22.04 and 24.04, and Debian 11 and 12.

FAQ

How much swap will it actually create? Below 2 GB RAM, 1.5x your RAM. At 2 GB or more, 1x your RAM, capped at 4 GB. Never below 512 MB. A 1 GB server gets 1.5 GB; an 8 GB server gets 4 GB.

Does it size the swap based on my disk? No. It sizes on RAM. It checks your disk has room, but disk size does not change the answer.

I already have a swap file. Will this break it? No. It detects /swapfile and resizes it only if the size is wrong. Other swap devices are left alone.

Can I choose my own size? Yes, with --size.

Is my copy traceable to me? Yes, and we want you to know that before you buy. Every download is stamped with an anonymous copy ID such as DD-4KQ2-8ZTV-9M3X, shown in the file header and in the script’s output. It lets us tell copies apart. It contains no personal data – not your name, not your email, not your order number – so a copy you share does not leak anything about you. It is there so that redistribution is attributable, not to identify you to anyone.

What does the licence allow? Three installs on infrastructure you control. Need more? Email us.

Can I read the source before running it as root? Yes, and please do. That is why it ships as readable bash rather than a compiled binary.

Support & Updates

Email [email protected]. Updates within the 2.x series are free: your existing licence downloads the current version, so re-downloading gets you the latest release at no extra cost and without using an install.

Links & Resources

Resource Link
How much swap does a Linux server need? https://datadrifter.io/how-much-swap-linux-server-needs/
Linux swap sizing guidance (AWS) https://repost.aws/knowledge-center/ec2-memory-swap-file
kernel.org – swappiness and VM tuning https://docs.kernel.org/admin-guide/sysctl/vm.html

DataDrifter is a marketplace of automation tools, scripts, and templates - built for SMEs and technical teams who want to move faster. A product of Elyxia Global Limited.

Data Drifter © 2025 - 2026, All rights reserved.