Linux swap space on a regular file

by Martin Monperrus
Here is a short howto for setting up swap space on a regular file:

1/ creating the swap file of 512M (the size is set by parameter "count")
$ dd if=/dev/zero of=/swap count=1000000 2/ configuring as swap
$ mkswap /swap

3/ Adding "/swap none swap loop 0 0" to the file /ect/fstab

4/ Mounting the swap file. Note that this will automatically be done at startup thanks to the line in fstab.
$ swapon -a

Note that this swap space can not be used for hibernating.
Tagged as: