Linux swap partition management
Table of Contents
Creating a new swap space from a new disk
- Format the new partition with:
mkswap /dev/sdx1
- Add the new swap partition to /etc/fstab
/dev/sdx1 swap swap defaults 0 0
- Run swapon -a to activate the new swap.
Creating a new swap file
Create the file. This command creates a 1 gigabyte file:
dd if=/dev/zero of=/swap bs=1M count=1000
Format the swap file:
mkswap /swap
Add the new swap file to /etc/fstab:
/swap swap swap defaults 0 0
Run swapon -a to activate immediately the new swap space.
Deactivating an existing swap space
- Run “swapoff -a“
- Comment / delete the related entry on file /etc/fstab
/dev/sdx1 swap swap defaults 0 0