Ubuntu 2gb Swap File

Posted March 8, 2014 21.8k views
I was getting a Wordpress database connection error every other day. I created a 512 swap file (1GB droplet) and it made it about a week. I'm trying to increase the swap file 2GB. Here are the steps I took. sudo swapoff /swapfile sudo dd if=/dev/zero of=swapfile bs=2048 count=1048576 sudo mkswap /swapfile It reports: Setting up swapspace version 1, size = 1048572 KiB... sudo swapon /swapfile It looks like it only created a 1GB swapfile. When I use free-m it says 1023 for the swap. The file size via WinSCP is 2GB. Is there a limit on the size of a swap file? If so, can I have two swap files? Or should I get a bigger droplet?
1 comment
  • On the original article how-to-configure-virtual-memory-swap-file-on-a-vps , it used count=1000 , I looked at the man page but did not make sense to me. I guess it works either way but wondered what the difference was.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
4 answers
sudo dd if=/dev/zero of=swapfile bs=2048 count=1048576 
should be
sudo dd if=/dev/zero of=/swapfile bs=2048 count=1048576 
Yep, that was it. I redid all those steps replacing the dd with yours and it free -m now shows 2047. Thanks for the help.

i use this command :

sudo dd if=/dev/zero of=/swapfile bs=1024 count=2048k

is it correct ?

i checked with "top" command it it show

KiB Swap: 2150396

is there anything wrong with my command or not ?

what is "bs=2048 " mean ?


"bs" stands for block size. So each "block" will be 2048 bytes. The Wikipedia article on the topic is pretty good: