×

Notice

The forum is in read only mode.

Swap Files (If the ram is not enough)

  • Stefan
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
12 years 2 weeks ago #6811 by Stefan
I guess many know this already, but it recently helped me with a lot of problems,
and I guess there are many who don't know how to work with swap on Linux.
So I give a short Howto on Swap-Files

  • What is Swap?Swap is a special filesystem in Linux systems which provides the system an alternative memory space if the RAM is full.
  • For what can I use it: If your Programs (e.g. Code_Aster) run out of Memory, you can create Virtual RAM for your Programs
  • How can I create Swap
  • 2 Possibilities: Create a Swap Partition is the standard way, but what if you only need swap temporarily or simply don't have the user rights? Then you can create a Swapfile.

Do the following steps in a terminal:
  1. Work as root-user:
    sudo -i
  2. Create an empty file with zeros (here we create swapfile in the root directory with 512 Megabiyte (M) ):
    dd if=/dev/zero of=/swapfile bs=1M count=512
    Explaination: dd makes a file full with zeros in the file swapfile (or what name and location you wish to give; you could also create one in your user directory with of=/home/username/myswapfile) ; bs=1M gives the blocksize. You could also use e.g. 1G for one Gigabyte instead. Count is the number of Blocks. In this case we have 512 blocks with 1 Megabyte, i.e. 512 MB
  3. Set the right user rights (not necessary but highly recommended for security reasons):
    chmod 600 /swapfile
  4. Activate Swapfile:
    swapon /swapfile
  5. Set entry in
    /etc/fstab
    (optional) if you want to keep the file if you reboot the machine:
    /swapfile none swap defaults 0 0
  6. To safely remove the swapfile:
    swapoff -a
    to turn it off an then
    rm -rf /swapfile

Thats it. For further reading i Refer to my source in the Arch Linux Wiki

Hope that helps some people!
Moderators: catux
Time to create page: 0.114 seconds
Powered by Kunena Forum