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,

One thought on “Setup swap File on Disk for Linux

  1. gotcha x

    I wish it was easy to expand the partition for user data losslessly [assuming single drive install]


Leave a Reply

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

Notify me of followup comments via e-mail. You can also subscribe without commenting.