Quickly create a (swap)file on linux

The traditional way for creating a linux swapfile would be using dd to create an empty file e.g.

dd if=/dev/zero of=/swapfile1 bs=1M count=2048

A faster way is to use “fallocate” e.g. 1) http://www.cyberciti.biz/faq/ubuntu-linux-create-add-swap-file/

fallocate -l 2G /swapfile1

Don’t forget the usually procedure for swapfiles:

chmod 0600 /swapfile1
chown root:root /swapfile1
mkswap /swapfile1
swapon /swapfile1
# edit /etc/fstab to add the swapfile during boot

References   [ + ]

1. http://www.cyberciti.biz/faq/ubuntu-linux-create-add-swap-file/

Comments are closed.