Traditionally, swap partitons
are used, and that's still the easiest and
probably best way to go. This is about using swap files
you have a need to.
At the present time VL installers detect and automatically use swap partitions,
but not swap files. Until there's a consensus on swap file naming and location,
auto-enabling swap files will be nearly impossible.
FWIW, I use a swap file. Let's assume you've made the same choice.
Those in a hurry can just read the Code:
Any user can create and format a swap file, but to put it in a good location
and enable it requires root, so do all this as root
I don't like plain files on / directory, but don't find a better place to put
it. When looking for your own location, pick something that's definitely
mounted before swap might be turned on. Look at the order in /etc/fstab
Until there's a convention, the file's name doesn't matter and we'll use
1024 bytes to a KB, so bs=1024. 1024 KB to a MB; this example creates a 256 MB
swap file. 1024 * 256 = 262144, so count=262144.
Create the swap file.
root:# dd if=/dev/zero of=/swap0 bs=1024 count=262144I thought you said 256 MB, not (268 MB)!
That, too, is an ongoing debate. Try "ls -h -l /swap0". Won't be solved here --
Format the swap file.
root:# mkswap /swap0
Now edit /etc/fstab, adding the following lines. Be sure they come after the
lines for the partition the swap file was created on. The comment (starts with
"#") lines are already there in some cases.
# Swap partitions
# The 'sw' option means auto activating with 'swapon -a'.
/swap0 none swap sw 0 0
The swap file should be activated and used at next reboot and . . .
You can turn it on now, without rebooting:
root:# swapon -a
"swapon /swap0" works, as well.
If you've turned on your new swap file, check its status. This step can work
for a normal user, but you need the full path to swapon, as follows.
Check swap status.
vluser:$ /sbin/swapon -s
Filename Type Size Used Priority
/swap0 file 262136 0 -1
If you get the same answer to "/sbin/swapon -s" after a reboot, you're all set.