The main idea here is to gain more swap space so you can run more applications, but to do so without re-partitioning or messing with the partitions at all.

Since Linux is a unix, and unix uses files for everything, there theory here is that we will make a file (instead of a partition) be used for swap.

This solution has been tested and works under linux kernel versions 1.1, 1.2, 1.3, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5 and 2.6.

  1. Decide where you are going to put the file - typically on your fastest harddrive. (I keep mine in /dev -- like it is a device, but it really isn't) You will of course need to put it somewhere where you have enough harddrive space.
    Here I make the 256MB file:
    dd count=256 bs=1048576 < /dev/zero > /dev/swap0
    
    Notice that I called the output file /dev/swap0. Keep in mind that it is only a file and not a device or special file in any way.
  2. Next secure the file.
    chmod 000 /dev/swap0
    
    Root (the kernel) can read this no matter what anyway but this will keep users out of your virtual memory.
  3. Format the file for swap.
    mkswap /dev/swap0
    
  4. Add the swap to the live system
    swapon /dev/swap0
    
  5. Optionally, you might want to add this to your /dev/fstab so that the swap is enabled every time you boot.
    /dev/swap0              swap                    swap    defaults        0 0
    

That's it. I hope you've enjoyed this installment of how to rape linux, see you next time.

2001/06/05 - First writing.
2004/01/15 - Update: It's still pertinent. Updated kernel list.