Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some sensitive data in ram that i prefer not to be on disk. How do i disable swap? I have more then enough ram. If ram gets too high i have no problems with processes being terminated. How do I disable swap?

Note: I do not have a swap partition and this is running in a VM (VMWare)

share|improve this question
Even if you have a lot of RAM, it's not the best idea to completely work without swap (see for instance ). Depending on your requirements you might consider putting the swap partition on a dm-crypt secured device, so that everything written to it will be encrypted. You have to make sure in such a case, that swap is enabled after encrypted volumes get available, and disabled before the device mapping is disabled, of course (I think that's default on Ubuntu, but I'm not sure). Just search the web for "encrypted swap" to find numerous guides. – soulsource May 13 '14 at 9:01
Apropos:… You don't need swap until you need it. And then you really need it. – jdv Oct 28 '15 at 19:19
What about a cryptswap ? /dev/mapper/cryptswap1 – chris Feb 10 at 4:20
up vote 49 down vote accepted


sudo swapoff -a  

is the usual way to turn off swap, with the swapon -a command used to turn it back on. See man swapoff for more information about turning off swap for explicit devices.

share|improve this answer
This doesn't seem to persist across a reboot? – ebyrob Apr 20 '13 at 2:31
Permanent changes to swap are usually made in /etc/fstab. – ubfan1 Apr 20 '13 at 5:51
Do we just copy this into /etc/fstab – Max Mar 5 at 23:23

You may disable swap after reboot by just commenting out the swap entry in /etc/fstab file. It will prevents swap partition from automatic mounting after a reboot.

sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab



sudo sed -i '/ swap / s/^/#/' /etc/fstab

Now your swap entry on /etc/fstab will look like this,

#UUID=1dc65039-4ac4-xxxxx-xxx-4xxxxf96xxxx none            swap    sw              0       0
share|improve this answer
Why does your quoted UUID have some concrete digits? Should they be identical for all UUIDs? My partitions' UUIDs don't have any coincidence with your specified digits. – Ruslan May 31 at 17:51

If your concerned about the content of the swap partition you can always turn it off as specified in the usual way with sudo swapoff -a and then fill the swap partition with zeros or random data using dd.

First find your swap partition use Disks, Disk Utility, gparted (GUI) or the content of fstab to find it (cat /etc/fstab)

Having located it and double and triple checked it's location at say sda5 or some such issue the "disk destroyer" command (not to be used lightly)

sudo dd if=/dev/zero of=/dev/sda5

to blast it full of zeros or

sudo dd if=/dev/random of=/dev/sda5

to blast it full of random data.

The next time you turn swap on with

swapon -a

The system will happily use it again. If you have plenty of RAM you may not need swap at all. Issue the command

free when the system is under heavy load and see how much is in use to make this determination.


share|improve this answer

Go into terminal and execute this command: gnome-disks. It is not installed in all distributions. If so, follow the instructions printed to install it and try again. Look for a device with the word 'swap' on the left pane. It usually has a size the same as your physical memory. Click the square button to disable it. Authenticate this change with your root password.


In the System Monitor application (gnome-system-monitor), you will see it reports the swap area as 'not available'. The swap area is disabled but not deleted. You can enable it easily again in the future. Deleting the swap space has caused my system no harm but you will create more work for yourself if you do decide you want it back (hibernation) in the future.

edit: to prevent it mounting at startup, you should go into the "Edit Mount Options..." in gnome-disks and uncheck "Mount at startup".

share|improve this answer
Do you think that this answers the users concern about having sensitive data on the swap partition? Can you tell us why? – Elder Geek May 9 '14 at 2:33
The user's main point was asking how to disable swap. If you have sensitive data, you should be using pre-boot encryption ideally. – user170544 May 9 '14 at 3:28
I respectfully disagree. When I read the question the first sentence I come across is "I have some sensitive data in ram that i prefer not to be on disk." I believe this was his main concern which is why he started with it. Regardless, I believe I have covered every aspect of his question in my answer. Consider it a helpful example. – Elder Geek May 9 '14 at 11:11

It may be lame solution, but I used it often. You can simply type

sudo -s
crontab -e

And add

@reboot sudo swapoff -a  

So, it will be disabled automatically on boot.

share|improve this answer
I hope it goes without saying that this is a very poor method. Why create a boot-time task to turn off another option, when there's another file that can be edited to stop it being turned on in the first place – underscore_d Oct 29 '15 at 18:18
sudo swapoff -a

Above command disables swap only for a current session, you need to comment out swap partition in /etc/fstab file. To do this you just need to add "#" to the beginning of swap line. Steps are as:

  1. Open fstab file, type sudo gedit /etc/fstab in terminal.

File's contents would look like this:

proc            /proc           proc    nodev,noexec,nosuid 0       0
/host/ubuntu/disks/root.disk /               ext4    loop,errors=remount-ro 0       1
/host/ubuntu/disks/swap.disk none            swap    loop,sw         0       0
#/dev/sda10 /media/ASD  vfat    defaults    0   0
#/dev/sda1  /media/98   vfat    defaults    0   0
  1. Just add hash (#) to the beginning of the swap partition line, so the line looks as:

#/host/ubuntu/disks/swap.disk none swap loop,sw 0 0

  1. Reboot your PC
share|improve this answer

Replace the defaults with sw,noauto, the line in the /etc/fstab, which consists of the swap entry:

` /dev/mapper/centos-swap swap swap sw,noauto 0 0


Now checkout the output after reboot, your swap never get mounted:

# free -m
              total        used        free      shared  buff/cache   available
Mem:           3791         100        3408           8         282        3483
**Swap:             0           0           0**
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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