How to activate swap on Linux? "swapon -a" doesn't seem to work?
Solution 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.
Solution 2
The text /dev/mapper/cryptswap1
in the output means two things:
- You use LVM (Logical Volume Manager) to manage your partitions
- The swap partition is encrypted
So the error you get can mean two things:
- 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. - 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.
Related videos on Youtube
kramer65
Updated on September 18, 2022Comments
-
kramer65 over 1 year
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
andsudo 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
-
dingzhihu almost 11 yearsWhich version of linux?
-
kramer65 almost 11 years@AaronDigulla - I'm on Ubuntu 12.04. Added it to my question.
-
kramer65 almost 11 years@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?
-
Jonathan over 7 years
-
-
kramer65 almost 11 yearsSorry, 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 almost 11 yearsOh, and 3) I can't find any errors in boot.log. Would you have any other tip on how I could proceed from here?
-
dingzhihu almost 11 years1) 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: help.ubuntu.com/community/EncryptedFilesystemHowto3 -
kramer65 almost 11 years1) 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!)
-
Izzy almost 11 yearsThe 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. -
kramer65 almost 11 yearsAh, 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?
-
Izzy almost 11 yearsThat 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.