<h1>Add Linux Swap Partition</h1>

Steps to add Swap Partition in Linux

Pre-requirements

Please use fdisk -l to get the target drive you want to use as the Swap space. Note: format the disk will lose all your data, Please back up before proceeding.

1. Format Disk into Linux swap / Solaris

$ fdisk /dev/sdb

Command (m for help): n
Command action: p
Partition number: 1
First cylinder: 
Last cylinder:

Note: Empty means use default value

command (m for help): t
Hex code: 82

command (m for help): w

2. Enable swap

$ mkswap -L swap1 /dev/sdb1

Modify /etc/fstab to add the line below

/dev/sdb1  swap  swap  defaults  0  0

3. Check Swap Space

$ swapon -a
$ swapon -s

<h1>Create Linux Swapfile</h1>

Create additional space use like “RAM”

1. Add Swap File

$ sudo fallocate -l 1G /swapfile

Create a 1GB swap file on Linux system

2. Set Swap File Permission

$ sudo chmod 600 /swapfile

3. Setup Linux Swap Area

$ sudo mkswap /swapfile

4. Enable the Swap

$ sudo swapon /swapfile

Modify /etc/fstab to enable the entry. Append the following line in the file

/swapfile swap swap defaults 0 0

5. Verify the swap status

$ sudo swapon --show