Here is a clear and complete guide for removing swap for both single and non-single partition setups:
๐ Scenario 1: Non-Single Partition Setup
Where SWAP is on a dedicated partition (e.g. /dev/vda2
)
โ Step 1: View current partitions
lsblk
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 253:0 0 30G 0 disk
+-vda1 253:1 0 29G 0 part /
+-vda2 253:2 0 1G 0 part [SWAP]
loop0 7:0 0 1.1G 0 loop /var/tmp
โ Step 2: Turn off SWAP
swapoff -v /dev/vda2
โ
Step 3: Edit /etc/fstab
to remove SWAP entry
nano /etc/fstab
Find the line referencing /dev/vda2
or swap
and delete or comment it out.
Example to remove:
/dev/vda2 swap swap defaults 0 0
โ
Step 4: Delete SWAP partition using fdisk
fdisk /dev/vda
Then:
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
Command (m for help): w
This will write the changes and remove /dev/vda2
.
โ Step 5: (Optional) Remove device node (if needed)
Only run this if /dev/vda2
is still visible:
rm -v /dev/vda2
๐ Scenario 2: Single Partition System (e.g. swap file, not partition)
โ Step 1: Turn off SWAP
swapoff -a
โ
Step 2: Remove the swap entry from /etc/fstab
nano /etc/fstab
Remove or comment out the line like:
/swapfile none swap sw 0 0
โ Step 3: (Optional) Delete the swap file
rm -v /swapfile
โ All done! Youโve successfully removed SWAP.