How to activate swap on Linux? "swapon -a" doesn't seem to work?

1

My computer has quite some memory (6GB) which is enough for most of what I do. A while back I was messing with my swap, turning it on and off with sudo swapon -a and sudo swapoff -a. In then end I must have left it turned off, since I now seem to have 0MBs of swap.

No problem normally, but I am now running some hefty analyses which are now using about 5GB of my swap and growing. So in order to avoid the analyses to terminate I wanted to turn on my swap again. So I ran "sudo swapon -a", but unfortunately this results in:

swapon: /dev/mapper/cryptswap1: stat() has failed: File or folder does not exist.

(I translated the output from Dutch to English, so the words may be off a little bit).

Does anybody know how I can enable my swap again? Since I don't want to halt my analyses, it is of course quite important that I can do it while the machine is running.

[EDIT] I'm on Ubuntu 12.04 and the contents of my fstab are as follows:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
UUID=f2ef1c1b-f606-44ed-9405-979fb6fa8ca4 /               ext4    errors=remount-ro 0       1
# /home was on /dev/sda3 during installation
UUID=7a1f29ef-3fcd-40ce-8e2a-4b9181a46863 /home           ext4    defaults        0       2
# swap was on /dev/sda2 during installation
#UUID=d0ef2314-6a84-432d-94f8-0d46c91c3d99 none            swap    sw              0       0
/dev/mapper/cryptswap1 none swap sw 0 0

kramer65

Posted 2013-06-24T09:26:40.683

Reputation: 1 335

Which version of linux? – Aaron Digulla – 2013-06-24T09:41:26.753

Do you try to swap to a partition or to a file ? If partition: Is there swap defined in /etc/fstab? If a file, which file. Is it still present? Can you rerun mkswap on that file? Did you try to use encrypted swap (/dev/mapper/cryptswap1 seems to indicate that). Please add more information. – Hennes – 2013-06-24T09:44:54.387

@AaronDigulla - I'm on Ubuntu 12.04. Added it to my question. – kramer65 – 2013-06-24T09:56:16.857

@Hennes - I've barely done anything with fstab or swaps, apart from swapon and swapoff. I didn't even know you could swap to a partition as well as a file, so I hope you can bear with me. I added the contents of fstab to my question. Does that tell you anything? – kramer65 – 2013-06-24T09:56:33.063

Answers

1

Make sure the volume you are trying to access exists. From the looks you had an LVM or something else using the device mapper and your swap-volume was deleted or renamed from the mapper.

So you have to either recreate it or update your swap definition to the renamed device path.

Izzy

Posted 2013-06-24T09:26:40.683

Reputation: 273

Sorry, but your answer is a bit like Greek to me. I don't know what a device mapper is and I wouldn't know how to "update my swap definition to the renamed device path". Could you maybe explain it a little bit more simple? At which files do I have to look (I added fstab to my initial question) and which commands do I have to run? – kramer65 – 2013-06-24T10:00:47.407

The device mapper is a part of the linux file systems, enabling you to use devices that are mapped together(like LVM or Fake-RAID storages). Please try sudo lvdisplay -C to see if you are using LVM storage. – Izzy – 2013-06-24T13:57:22.077

Ah, thanks for the explanation. When running sudo lvdisplay -C I get an error saying: "sudo: lvdisplay: command not found". So I guess I am using something else (right?). Would you have any idea what I should do now? – kramer65 – 2013-06-24T16:02:19.470

That seems about right. Just noticed your fstab has the last line before the actual swap commented out. It shows that the mapper is used on the plain device that is encrypted. This line shows also a swap. You can try re-crypt /dev/sda2. Just google for "encrypted swap ubuntu" on how to do that. – Izzy – 2013-06-24T19:56:58.107

1

The text /dev/mapper/cryptswap1 in the output means two things:

  1. You use LVM (Logical Volume Manager) to manage your partitions
  2. The swap partition is encrypted

So the error you get can mean two things:

  1. There is something wrong with your LVM. Try sudo lvmdump to see what the current status of LVM is. That might give you a clue.
  2. You didn't specify the correct password during boot and the system couldn't decrypt the swap partition.

Also check your boot.log and other log files in /var/log/ for errors. That might give you an idea what's wrong.

Aaron Digulla

Posted 2013-06-24T09:26:40.683

Reputation: 6 035

>

  • sudo: lvmdump: command not found. 2) I always log in using my normal password which hasn't changed in ages. I think I indeed selected "encrypted" wherever possible when I installed Ubuntu, so could it have something to do with the fact that I disabled swap using 'sudo swapoff -a' and after that rebooted (many times in fact)?
  • < – kramer65 – 2013-06-24T10:19:27.603

    Oh, and 3) I can't find any errors in boot.log. Would you have any other tip on how I could proceed from here? – kramer65 – 2013-06-24T10:25:14.860

    >

  • try sudo /sbin/lvmdump 2) The system should ask a password before the login screen, while you can see text on a black screen. This link might also help: https://help.ubuntu.com/community/EncryptedFilesystemHowto3
  • – Aaron Digulla – 2013-06-24T10:25:48.167

    >

  • sudo: /sbin/lvmdump: command not found. 2) I've never seen my pc ask for a password before my login screen. The link you give revers to Ubuntu 5.10 and 6.06, is that information still valid? (ps. thanks for your efforts!)
  • < – kramer65 – 2013-06-24T10:32:27.647