unix

How do I create a swap file in Linux?

If you have available disk space, you can typically improve performance when needed by adding a swap file. To create a swap file, do the following:

1. dd if=/dev/zero of=/path/to/my/swapfile bs=1024 count=1048576 (1024 * 1024kb = 1 GB)

2. mkswap /path/to/my/swapfile

3. swapon /path/to/my/swapfile

4. To make your swap file accessible across reboots, update your /etc/fstab to add the following line:

/path/to/swapfile swap swap defaults 0 0

5. To confirm your swap space is now available, run the following command:

free -m

Click to comment

Leave a Reply

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

To Top