My Ubuntu server has no more than 512 MB of memory. It is not enough for running Node.js + MongoDB.
Hence I decided to add a swap file:
# dd if=/dev/zero of=/root/myswapfile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 4.69263 s, 229 MB/s
# mkswap /root/myswapfile
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=3c64da32-d0b4-49e5-92db-fba961b8ae28
# swapon /root/myswapfile
No error message => successful!
The new swap file should now be listed, but it is not:
# swapon -s
Filename Type Size Used Priority
(empty list)
How can I make it work? What might be the reason for the missing swap?
First, erase your original swapfile:
Next, run the following commands one by one:
The output should be similar to the following:
Now, run the following commands:
Now, edit /etc/fstab to make the changes permanent:
and add the following line to the end of the file:
Press CTRL + o and then press ENTER to save the file.
Press CTRL + x to exit nano.
source: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04
If that still doesn't work, you may want to check swappiness:
This command should return a number. The default should be 60.
If no output, run the following commands one by one:
The
-a
is important aftertee
or you will overwrite the entire file!!!You swap file should be in /swapfile with 600 rights.
add swap file. I think you forget this command
Use
fdisk
to create a swap. Add a new partition, select Linux swap, write the changes.mkswap /dev/sd?
You need to add it to your/etc/fstab/
. Change XXX to the swap UUID.Run
swapon -a
to make it available from/etc/fstab
.you could do this:
and write in where swap is this:
and then this:
and then run gpart and set the swap drive as swap, and mount it on the root dev drive, and it might work fine this way.