1

I used sudo swapoff -a && sudo swapon -a, but swapon is not turning the swap back on, although on my older machines this always worked for cleaning up swap. What could be wrong? Ubuntu 16.04.

EDIT:

$ sudo blkid
/dev/sda1: UUID="6ead6194-b15f-4108-b71c-f91bac560daf" TYPE="ext4" PARTUUID="e8b65a13-5140-4b3b-9a09-565c3283fd0d"
/dev/sdb1: LABEL="big" UUID="cdfd673f-a33f-46cd-81e4-e3c6c1e9b902" TYPE="ext4" PARTUUID="1df024fd-cf87-40e8-9347-4c4073fcf9ca"
/dev/sdc1: UUID="644fe734-074a-4801-b2b8-fdff946d438d" TYPE="ext4" PARTUUID="ebd3d525-9edf-4a50-b6ea-bd745e03bb7c"
/dev/sdc2: UUID="05e01b5a-915c-4fe7-9ed1-5a1c5224fce9" TYPE="swap" PARTUUID="ca7cbc08-535a-4c18-9afd-c4b7553155c5"
/dev/sdc3: PARTUUID="d7edea62-ee24-49d0-8818-a4445d5cca7b"


$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=644fe734-074a-4801-b2b8-fdff946d438d /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
#UUID=9bb0f54c-3d82-4376-9e07-a0c3dd7aae69 none            swap    sw              0       0

#added
UUID=cdfd673f-a33f-46cd-81e4-e3c6c1e9b902 /disk2               ext4    errors=remount-ro 0       1
UUID=6ead6194-b15f-4108-b71c-f91bac560daf /disk3               ext4    errors=remount-ro 0       1

$ cat /etc/crypttab
cat: /etc/crypttab: No such file or directory
5
  • Doing that probably does more harm than good. Leave swap alone. However, if you edit your question to include sudo blkid and cat /etc/fstaband cat /etc/crypttab I'll take a look. Ping me at @heynnema.
    – heynnema
    Nov 22, 2017 at 17:09
  • You can also enable swap directly bu uuid, like sudo swapon -U 862bcf62-5b3b-4e9a-9ede-3706ae9bbd04.
    – Hi-Angel
    Nov 22, 2017 at 17:35
  • @heynnema I edited as per your request, thank you for checking. Why does it do more harm than good? Sometimes, after a lot of memory was used, I find that after clearing swap I get everything back in memory, which does slightly increase the performance as perceived by me (obviously, I never actually measured:))
    – fbence
    Nov 22, 2017 at 20:08
  • 1
    It only does harm if you have overcommitted your physical memory, then when you do a swapoff, the system might come to a fateful stop due to lack of physical memory.. :-)
    – mdpc
    Nov 22, 2017 at 20:57
  • Oh, ok as I thought, I always do the math before :D
    – fbence
    Nov 22, 2017 at 21:13

2 Answers 2

4

The swap partition is not identified in the /etc/fstab file. Thus when you do a swapon -a, there is no swap file to add.

Based on your blkid output, there is a swap partition present on /dev/sdc2 which is NOT in your fstab listing.

Thus you could add a line such as the following to your fstab:

 /dev/sdc2   none     swap      sw     0 0

Or if you insist on using UIDs:

 UUID=05e01b5a-915c-4fe7-9ed1-5a1c5224fce9   none   swap   sw    0 0
1
  • 1
    Oh, wow, I was completely sure I had one in the fstab (so sure I didn't check its a comment). But then, how does the system know at boot to mount the swap if its not in the fstab?
    – fbence
    Nov 22, 2017 at 21:12
-2

There is a more simpler way. I assume you want a 4gb swap on file? Just follow my instructions :)

dd if=/dev/zero of=/mnt/myswap.swap bs=1M count=4000

Make the Swap:

mkswap /mnt/myswap.swap

Do swapon

swapon /mnt/myswap.swap

Now the final step :)

nano /etc/fstab

now you just add this to the end of the File:

/mnt/myswap.swap none swap sw 0 0

and save the file and your done! Hope it helped. If it helped, please do an upvote!

2
  • Putting a 4GB swap file on your filesystem /mnt/myswap.swap should be used in emergencies. The Better Way is to dedicate a disk partition on your fastest disk for swap. Read man mkswap, man fstab, man ecryptfs-setup-swap.
    – waltinator
    Nov 22, 2017 at 17:52
  • I am not sure that I necessarily agree with the emergencies part. Generally what I have found is in normal practice one should have sufficient memory thus avoiding swapping. Thus the swap file although allocated is not frequently used. I DO agree that it is better to allocate swap to a partition for efficiency. Also, if somebody goofs and does not leave sufficient swap space and there is no way to easily modify partitioning or add additional disk, augmenting it with a file might be your only choice.
    – mdpc
    Nov 22, 2017 at 21:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .