I had a swap partition on a hard drive (/dev/sdb3), which eventually failed. The drive was removed and replaced. A new swap was created, fstab updated, and turned on (/dev/sdc3), but the old swap still is listed in /proc/swaps, but with (deleted).

[root@server01 ~]# cat /proc/swaps
Filename                Type        Size    Used    Priority
/dev/sdc3                               partition   4194300 0   -2
/dev/sdb3\040(deleted)                  partition   4194300 0   -1
/dev/sda3                               partition   4194300 0   -3

I have tried to remove the swap. swapoff /dev/sdb3 fails with No such file or directory. swapoff -a and swapon -a seem to work without any errors, but /proc/swaps still lists the deleted swap.

How do I remove the swap that doesn't really exist? If needed, will the system still try to use this chunk of swap space? What will happen then?

Additional background: The server can not be rebooted, and the drive was replaced via hotplug interface. The drives are AHCI SATA drives, and do not go through a RAID controller, HBA, or any other special interface. Although /dev/sdb failed and no longer exists, the new drive, when inserted in the same port, became /dev/sdc. /dev/sda exists and works fine throughout this process.

Reference: Another user asked what causes the swap to show as deleted, but I know the cause, just not how to remove it.


1 Answer 1


You need to reboot the system.

On writing data, the kernel should just ignore any deleted swap partitions/files.

On read, whatever process it was trying to swap pages in for will be terminated (I'm not sure what signal gets sent, but I believe it's the same one that gets sent when trying to access a page that contains an uncorrectable memory error). Depending on the exact kernel configuration, this may also cause a kernel panic, crashing the system. This is the big reason you should ideally reboot, as deactivating swap space causes any pages stored there to either be swapped in again or moved to other swap space, so deactivating swap space that is non-existent and has data store din it may result in processes being terminated without advance notice.

In your case, you don't have any data on the swap space in question, so it should be safe to deactivate it. However, as you have found out, the command-line tools to deactivate swap space don't work correctly on non-existent devices. For future reference, make sure to deactivate any swap space on a failed storage device before disconnecting it, so you can avoid situations like this.

Also, you may have to update /etc/fstab again once you reboot. The active but non-existent swap partition is still holding a reference to the removed storage device which will get released on reboot. Until you reboot, the device enumeration order will be different from what it would normally be because of this, so what is currently /dev/sdc may become /dev/sdb on reboot.

  • Great point on the device reorder at boot. Luckily, I used device labels (in liu of GUIDs) in /etc/fstab to prevent this.
    – Paul
    Mar 29, 2018 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.