Ubuntu: swapon -a doesn't turn on swap



Question:

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  


Solution:1

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  


Solution: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!


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »