Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

swapon has no effect, /proc/swaps remains empty

Writer Matthew Martinez

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?

12

4 Answers

First, erase your original swapfile:

sudo rm /myswapfile

Next, run the following commands one by one:

sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfile

The output should be similar to the following:

-rw------- 1 root root 1.0G Aug 3 18:20 /swapfile

Now, run the following commands:

sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s

Now, edit /etc/fstab to make the changes permanent:

sudo nano /etc/fstab

and add the following line to the end of the file:

/swapfile none swap sw 0 0

Press CTRL + o and then press ENTER to save the file.

Press CTRL + x to exit nano.

source:


If that still doesn't work, you may want to check swappiness:

cat /proc/sys/vm/swappiness

This command should return a number. The default should be 60.

If no output, run the following commands one by one:

sudo sysctl vm.swappiness=60
echo "vm.swappiness = 60" | tee -a /etc/sysctl.conf

The -a is important after tee or you will overwrite the entire file!!!

0

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.

UUID=XXX none swap sw 0 0

Run swapon -a to make it available from /etc/fstab.

You swap file should be in /swapfile with 600 rights.

#moving file and changing rights
sudo mv /root/myswapfile /myswapfile
sudo chmod 600 /myswapfile
sudo mkswap /myswapfile

add swap file. I think you forget this command

sudo swapon /myswapfile
#check swap is working
sudo swapon -s
5

you could do this:

sudo umount -a
gedit /etc/fstab

and write in where swap is this:

/proc/swap proc default errors=noremount 1

and then this:

sudo mount -a

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.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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