Skip to main content

Using one file as Linux Swap instead of a partition

Sometimes wasting a partition for Linux Swap is quite annoying, so let's use a file instead.

Steps are simple:

cd /whatever-dir/
dd if=/dev/zero of=./swapfile bs=1024 count=<num in KB>
mkswap ./swapfile
swapon ./swapfile

# That's it, you just enabled your swapfile

If you'd hope that it'll start at boot, add it to your /etc/fstab:

echo "/whatever-dir/swapfile none swap sw 0 0" >> /etc/fstab


Comments powered by Disqus