You want to frequently change the swap size.
You want to save entries in the partition table.
You want to add swap without repartitioning.
For all above, Swap partitions (default under openSUSE) cannot be used.
This How-To uses standard GNU/Linux commands, therefore it is not specific to openSUSE.
In every Linux OS you can manually configure swap files:
Before we begin, you must enter the root
mode by using the command su.
Create a new file with the size you like, for example, 256 MiB.
# dd if=/dev/zero of=swapfile.img bs=$[1024*1024*256] count=1
NOTE: strictly speaking, the ".img" extension is not required, but I use it to destinguish between abstract term and the actual file. (and for easier searching)
Initialize and Format the file:
# mkswap swapfile.img
Start using swapfile:
# swapon swapfile.img
Stop using swapfile:
# swapoff swapfile.img
Finally, if you want to make loading of swapfile permanent (during system boot), you must add your swapfile to "/etc/fstab", which is a filesystem configuration file used during boot.
This can be done by the command below:
# echo $(pwd)/swapfile.img "swap" "swap" "defaults" "0 0" >> /etc/fstab
There are several commands to diagnose that swap is setup correctly:
shows all swap files and partitions:
# cat /proc/swaps /home/suser/swapfile.img file 262136 0 -2
shows all VirtualRAM, including RAM and swaps:
# free
Understanding the command dd from step1: (not required for successful setup)
Let's explain the command above: dd = disk dump - often used to copy blocks of data. dd is part of "CoreUtils" and comes standard with every Linux system.
As input we use binary "zero"s and as output we use "swapfile.img". "bs" means block size - how big each block of data we want to move. we compute it based on: 1024*1024 (=1 MegaBinaryByte, MiB) and *256 that's what we want to achieve; then we use "count" = 1, that is the multiplier. If we don't specify "count", "dd" will make system calls recursevily until your Hard Disk is full. Using big blocksizes with count=1 is the fastest way.
Understanding the command echo from step5: (not required for successful setup)
You must use "root" mode to access fstab.
echo is often used for simple use such as output text on display. echo is part of "CoreUtils" and comes standard with every Linux system.
Here we use a more complex syntax. To take something from point "A" and move it into file.
So first we get (output) the current directory, then use the filename "swapfile.img", then we have first "swap" occurence for mount point and second occurence for filesystem type. The "0 0" are additional parameters, which we don't use. now the ">>" is redirection to add all of that to existing file "/etc/fstab".
For more information about the term "MegaBinaryByte", "Mebibyte" or simply "MiB" look: http://en.wikipedia.org/wiki/Binary_prefix.
For more information about the dd command, use:man dd