Swap – How to create a swap file

Swap file is used to “expand” the memory RAM, so increase the capability to execute more softwares at same time. In a GNU/Linux, it’s possible to create a dedicated swap partition or use a file.

Below I’ll show step by step how to create a Swap file in a Linux OS.

With this feature activated, will be possible to run many applications and keep the unactive process in “stand-by” in HD or SSD while you can play any heavy game or execute a HTTP or FTP service.

00 – Getting superuser access

In Ubuntu:

# sudo su

In Debian:

# su –

01 – Create swap file

# dd if=/dev/zero of=/swap bs=1M count=1024

02 – Give write permission to file

# chmod 600 /swap

03 – Create a swap area

# mkswap -f /swap

04 – Add Swap file to Linux startup

Add swap configuration to “/etc/fstab”. Modify the file with something like this:

# nano /etc/fstab

05 – Test

First restart your machine and run the follow command:

# free

If you get a result like below, everything worked ok!


Any question, just leave a comment below!

See ya! đŸ˜‰

  • Rodrigo Horie

    Mano, muito bom! Obrigado! :DD