4

I want to increase my swap size to be able to have the hibernate option. First, I tried to add some swapfile. I followed

https://bogdancornianu.com/change-swap-size-in-ubuntu/

and typed this in my terminal:

sudo dd if=/dev/zero of=swapfile bs=1G count=16

I get:

16+0 records in
16+0 records out
17179869184 bytes (17 GB, 16 GiB) copied, 206.949 s, 83.0 MB/s

then, I followed the instructions:

sudo mkswap /swapfile

But I get this error:

mkswap: cannot open /swapfile: No such file or directory

Then, I decided to resize my swap partition instead of swapfile. So I want to delete them. (I didn't create any before so I assume I can delete them all?) I followed this:

https://askubuntu.com/questions/904628/default-17-04-swap-file-location

I tried:

$ cat /proc/swaps
$ grep swap /etc/fstab

But I get nothing from the first one. Output from the second one is:

              total        used        free      shared  buff/cache   
available
Mem:          11862        3498        1014         138        7349        
7907
Swap:             0           0           0

I also tried (after reboot):

swapon -s

and get

Filename                Type        Size    Used    Priority
/dev/sdb3                               partition   3905532 0   -2

I wonder that did I successfully create swapfiles? How do I delete them if I did?

  • 1
    Hello, our new contributor! Please read our guidelines, and maybe more important note: You should really really read properly what you are typing, there is no space for typos in Linux! – Vlastimil Mar 26 at 16:19
9

The first issue is that your first command created a file, swapfile, in your current directory, and that your subsequent command(s) were explicitly referencing /swapfile, a file called swapfile in the root directory. If that was not your current working directory when you executed the first command, all of the subsequent commands would be referring to a file that is not there to operate upon.

If you got no output from cat /proc/swaps, that indicates that either your system does not have procfs running (unlikely), or that you currently have no active swap space configured.

The output you claim to get from grep swap /etc/fstab makes no sense whatsoever. That looks like the output of free -m (incidentally confirming that you have no active swap configured), not the partial contents of the filesystem table.

Your post-reboot swapon -s (which as the manual states gives the same information as cat /proc/swaps) indicates that at some point prior to your reboot, someone executed swapoff.

  • Got it! I found the swapfile in ~/, since I didn't cd to any other directory. So can I just remove it with rm command? Thank you! – Frank Wang Mar 28 at 15:04
  • 1
    You can indeed, or you can mv it to where you intended it to be if you haven't already started over from the correct directory. – DopeGhoti Mar 28 at 15:34
4

You made a typo:

of=swapfile

should be

of=/swapfile

the guide creates the swap file in the root directory, whereas the command that you entered would have created a swap file in your current directory.

1

Delete the swapfile(s) by

sudo swapoff -v /?/swapfile 

where /? represents the directory where you inadvertently created an extra swapfile.

sudo nano /etc/fstab 

allows you to edit fstab where you can delete any reference to /?/swapfile

sudo rm /?/swapfile

deletes the spurious swapfile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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