How to resize already existing swap file

Have you ever make mistake with size of your swap file during linux installation ? Good news is that size can be resized.

This article is written after successful usage of tutorial mentioned here :

First at all you can check where your swap file is located.

cat /proc/swaps

In first column you can find path to your swap file. So let’s go …

  1. Turn off your swap

    sudo swapoff -a

  2. Create an empty swapfile ( next command will create 8G swap file

    sudo dd if=/dev/zero of=/swapfile bs=1G count=8

  3. If your swap file was already created, you probably have correct permissions on file. But to be sure adjust permissions

    sudo chmod 0600 /swapfile

  4. Set up a Linux swap area

    sudo mkswap /swapfile

  5. Turn the swap on

    sudo swapon /swapfile

And that should be it. Check your swap size with command


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.