Error creating Swap File. Ubuntu 18.04
Please be gentle with me, I am a noob and will need simple explanations.
I wanted to increase swap file size, but encountering some weird behavior.
Full story - I had 2G and wanted to allocate more space. First, I followed a suggestion to have double of ram and entered 8G, but then changed my mind and decided to change it to 4G. BUT after following the same procedure as the first time, it stays 8G still.
I followed this guide
This is what I get (edited to show main points):
~$ sudo swapon --show
~$
~$ sudo fallocate -l 4G /swapfile
~$ ls -lh /swapfile
-rw------- 1 root root 8.0G Feb 14 12:14 /swapfile
~$ sudo swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 8G 0B -2How do I set it to 4G and make sure it's functioning correctly?
31 Answer
First, stop using and delete the old swap file:
sudo swapoff /swapfile
sudo rm /swapfileSecondly, create the new swapfile:
sudo dd if=/dev/zero of=/swapfile bs=1G count=4
sudo chmod 600 /swapfileThirdy, configure the file for use as a swapfile:
sudo mkswap /swapfileFinally, utilize the new 4G swapfile:
sudo swapon /swapfilePlease note that you can but should not use fallocate to create your swapfile. Notes in man swapon indicate that it should work, if the underlying disk structure is XFS, but that problem may occur otherwise.