Swap partitions provide dedicated disk space used as overflow memory when physical RAM is exhausted. On modern Linux systems with ample RAM or a preferred swap file, an old or oversized swap partition can waste disk space that could otherwise be used for data or additional volumes.
The kernel exposes active swap areas through swapon and /proc/swaps, while partition layout is managed by tools such as lsblk, fdisk, and parted. Swap partitions are normally enabled at boot through an entry in /etc/fstab that references the underlying block device or its UUID, so both runtime state and configuration must be updated when removing swap.
Before modifying partitions, backups of important data and configuration files reduce the risk of data loss. Removing the wrong partition or leaving a stale swap entry in /etc/fstab can lead to boot errors or memory pressure under heavy workloads. The procedure uses sudo for elevated privileges and standard disk utilities commonly available on most Linux distributions.
Steps to safely remove a swap partition in Linux:
- Check the currently active swap areas.
$ sudo swapon --show NAME TYPE SIZE USED PRIO /var/lib/swap file 1024M 0B -2 /dev/loop0 partition 128M 0B -3
If no rows appear, no active swap is present and the partition might already be unused.
- Display block devices and confirm which partition is marked as swap.
$ lsblk --fs NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS loop0 [SWAP] ##### snipped #####
Note the device name (for example /dev/loop0) or UUID of the swap partition for later steps.
- Deactivate the swap partition so the kernel stops using it.
$ sudo swapoff /dev/loop0
Disabling swap on a system with very limited RAM can cause applications to fail under heavy load.
- Verify that no swap area is still active.
$ swapon --show NAME TYPE SIZE USED PRIO /var/lib/swap file 1024M 0B -2
The absence of the loop device in swapon --show confirms that swap is fully disabled.
- Remove the persistent swap reference from /etc/fstab.
$ sudo sed -i "/UUID=6c2b5271-7333-4ce9-a493-21ac96c28bb0 none swap sw 0 0/d" /etc/fstab
An incorrect /fstab entry can prevent a system from booting until the file is repaired from a recovery environment.
- Detach the loop device and delete the backing file.
$ sudo losetup -d /dev/loop0 $ sudo rm /root/sg-work/loop14.img
If you used a real disk partition, skip the loop cleanup and manage the device with your usual partitioning tools.
- Confirm that the swap partition is gone and no swap area remains active.
$ swapon --show NAME TYPE SIZE USED PRIO /var/lib/swap file 1024M 0B -2 $ grep UUID=6c2b5271-7333-4ce9-a493-21ac96c28bb0 /etc/fstab
The absence of a swap entry in /etc/fstab and an empty swapon --show for the loop device confirm that the swap partition has been fully removed.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
