Updating Swapfile Size in Ubuntu

Steps

  1. Check Disk size if you have enough size

  2. Check your existing swapfile size (in my case 9Gi)

  3. Disable swapfile

  4. Update to the required size (I will do to 10Gi)

  5. Change swapfile permission

  6. Setup Linux Area

  7. Enable swapfile

  8. Make it permanent

  9. Verify

Check Disk size if you have enough size

Let's see the size of your swap file,I have 9Gi I will make it 10G

Disable swapfile, after disable your swapfile size would have become 0B

sudo swapoff /swapfile

Now Let's update it to 10Gi

sudo dd if=/dev/zero of=/swapfile bs=128M count=88

Here if you want 1GB your count value will be 8

Count ValueSwap file size (in Gi)
81Gi
162Gi

Lets change the permission of the swapfile

sudo chmod 600 /swapfile

setup Linux swap area

sudo mkswap /swapfile

Enable the swapfile

sudo swapon /swapfile

Make it Permanent across reboots

Open file /etc/fstab in your favorite editor and write the below contents

/swapfile swap swap defaults 0 0

Verify the new size of your swapfile.