Setup swap File on Disk for Linux

By | 2014/06/17

It is easy to create a swap file on an existing filesystem for swap space. Check it out!

1. Create swap file (1GB in this example):

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

2. Set permissions

$ sudo chmod 600 /swap

3. Set filesystem type as swap:

$ sudo mkswap /swap

4. Activate

$ sudo swapon /swap

5. (Optional) Add to /etc/fstab to keep at boot

/swap     none     swap    defaults 0 0

Rock on,