Create a swap file on Linux

L'Antre du Tryphon

schedule
2025-03-26 | 17:17h
update
2025-03-26 | 17:21h
person
www.ctheroux.com
domain
www.ctheroux.com

Create a swap file on Linux

The simple following steps will create a swap file. Swap files are used when the operating system need more memory. It uses the swap space as memory. Its usage shall be limited, since a swap space is less efficient than memory. It will save you a memory upgrade if it is need seldomly.

  • swapon –show
    • Display the current status of the swap spaces
  • sudo dd if=/dev/zero of=/swapfile bs=1024 count=8388608
    • Create a swap file of 8 GB (8388608 / 1024 / 1024)
  • sudo mkswap /swapfile
    • Prepare the file to be used as a swap file
  • sudo chown root:root /swapfile
    • Set the owner of the swap file
  • sudo chmod 600 /swapfile
    • Set the permissions of the swap file
  • sudo swapon /swapfile
    • Enable the swap file. Reboot is not required.
  • swapon –show
    • Display the status of the new swap space

Advertisement

Imprint
Responsible for the content:
www.ctheroux.com
Privacy & Terms of Use:
www.ctheroux.com
Mobile website via:
WordPress AMP Plugin
Last AMPHTML update:
10.01.2026 - 10:17:20
Privacy-Data & cookie usage: