Table of Contents
What Swap Is (In Practice)
Swap is disk space that your Linux system can temporarily use as "overflow" memory when RAM is full. It is much slower than real RAM, but it:
- Helps prevent crashes when you run out of RAM
- Can allow you to open more applications than your RAM alone would permit
- Is used for hibernation on many systems (suspend-to-disk)
Swap can be provided in two main ways:
- A swap partition – a dedicated partition on disk
- A swap file – a special file on an existing filesystem
In this chapter, we focus on swap as part of the installation/partitioning process.
Do You Need Swap?
Whether you need swap, and how much, depends mainly on:
- How much RAM you have
- What you use the machine for
- Whether you want hibernation
Some typical guidelines for beginners:
- Very low RAM (≤ 4 GB): swap is strongly recommended
- Moderate RAM (8–16 GB): swap is still recommended, but you can use less
- High RAM (≥ 32 GB): you may still want a small swap area as a safety net
For hibernation, you usually want swap size at least as large as your RAM (or very close), because the system saves the contents of RAM into swap.
How Much Swap Should You Create?
There is no universal rule, but here are practical starting points:
- Desktop / laptop without hibernation:
- RAM ≤ 4 GB → swap: 2–4 GB
- RAM 8 GB → swap: 2–4 GB
- RAM 16 GB → swap: 2–8 GB (2 GB is often enough)
- RAM ≥ 32 GB → swap: 2–4 GB (or none, if you know what you’re doing)
- Desktop / laptop with hibernation:
- Aim for:
$$ \text{swap size} \approx \text{RAM size} $$
or slightly more, e.g. 1–2 GB extra. - Example: 8 GB RAM → 8–10 GB swap
- Server / VM (beginner-friendly rule)
- If RAM ≤ 8 GB → 1–2 GB swap
- If RAM 8–32 GB → 2–4 GB swap
- More than that depends on workload and admin preference
These are conservative, safe defaults for new users. You can adjust later as you learn more.
Swap Partition vs Swap File (At Install Time)
During installation, many distributions give you a choice between:
- Creating a swap partition
- Using a swap file (or letting the installer manage it automatically)
Swap Partition
A swap partition is its own partition, with no filesystem, used only for swap.
Pros:
- Simple and traditional
- Slightly easier for some installers and older tools
- Keeps swap separate from your data
Cons:
- Inflexible: changing its size later requires repartitioning
- Takes up a fixed amount of disk space forever
Typical when you:
- Use manual partitioning schemes (e.g.,
/,/home, andswap) - Want a straightforward, old-school setup
Swap File
A swap file is a regular file on an existing filesystem (often on /).
Pros:
- Flexible: can resize more easily than a partition
- Often created automatically by modern installers
- No need to reserve a separate partition
Cons:
- Slightly more complex under the hood (but installers handle this)
- Historically had some limitations on certain filesystems (mostly solved now)
Many modern distributions default to a swap file on desktop/laptop installs. If you are unsure, accepting the installer’s default is usually the best choice.
Where to Put Swap
During installation, you’ll see disk layouts. Common scenarios:
- Automatic partitioning
- Installer creates swap automatically:
- Either a swap partition, or
- A swap file on the root partition
- Recommended for beginners unless you have special needs.
- Manual partitioning
- You create partitions yourself.
- For swap, you typically:
- Create a new partition
- Set its type to
swaporLinux swap - Do not assign a mount point (swap doesn’t get mounted like
/or/home)
If you plan to use a swap file instead of a partition, you can:
- Skip creating a swap partition during install, and
- Rely on the installer to create a swap file automatically, or set it up later.
Swap and Hibernation
If you intend to use hibernation:
- Ensure your swap area (partition or file) is at least as large as your RAM.
- Many distros:
- Prefer using a swap partition for hibernation, but
- Newer setups also support hibernating to a swap file (with some extra configuration).
When installing:
- Check if the installer offers a “use swap for hibernation” or similar option.
- If you care about hibernation and see such an option, enable it and follow the size recommendation it gives.
Common Installation-Time Choices
Here are some safe, simple choices for typical beginners:
Example 1: 8 GB RAM laptop, single-disk, wants hibernation
- Let the installer use automatic partitioning if possible; verify it creates:
/(root)- Maybe
/home(optional) - Swap (partition or file) of 8–10 GB
- If using manual partitioning:
- Create
swappartition of 8–10 GB - The rest of the disk for
/(and/homeif you want a separate one)
Example 2: 16 GB RAM desktop, no hibernation
- Automatic partitioning: accept default swap setup (file or partition).
- Manual partitioning:
- Create swap partition of 2–4 GB
- The rest goes to
/(and/homeif desired)
Example 3: Small VM with 2 GB RAM
- Swap is important here.
- 1–2 GB swap is reasonable.
- Automatic partitioning is usually fine; otherwise:
- Create swap partition of 1–2 GB
- Assign the rest to
/
Things to Avoid (As a Beginner)
- No swap at all on low-RAM systems
- This makes running out of memory more likely and can cause sudden process kills or system instability.
- Huge swap on tiny disks
- Don’t allocate, for example, 20 GB swap on a 64 GB SSD if you only have 4 GB RAM and no need for hibernation.
- Multiple swap partitions during install
- One swap area is totally sufficient for typical beginner systems.
- Extra swap can be added later if needed.
Summary
- Swap is disk space used as backup memory when RAM is full.
- It can be a swap partition or swap file.
- For most beginners, accept the installer’s default swap configuration.
- Size swap based on RAM size and whether you need hibernation.
- Manual partitioning: create one partition of type
swap(no mount point) if you are not using a swap file.