Solved

Swap-file

Posted on 1996-12-10
2
421 Views
Last Modified: 2014-01-27
Is it possible to have a swap-file in Linux
and not a full swap-partition.
0
Comment
Question by:LarsC
2 Comments
 

Accepted Solution

by:
dspencer earned 50 total points
ID: 1631511
Not that I know of.  (I would just say "no, it is not", except for the possibility that since it's the Linux community and all, *anything* is remotely possible. =])

The utilities dealing with swap interaction, specifically mkswap and swapon/off, and the way it is accessed to the system through /etc/fstab, seem to be irrevocably tied to swap space being on one or more separate partitions.

See the Installation-HOWTO and (if you're interested in possibly sharing swapfile space with a Windows 3.x installation) the Swap-Space mini-HOWTO for supporting details.

Sorry!

(And just as long as we're on the subject of separate partitions:  my favorite schema is /, /usr, /usr/local, /home, /var, /tmp, and swap, with sharing as appropriate for your installation. Post another question if you want better explanation :) )
0
 
LVL 1

Expert Comment

by:stgreenwalt
ID: 39811926
The accepted solution is wrong.  You can create a swap file in Linux that is not a part of a separate partition as follows.  This creates a 1GB swap file:

All from a root prompt (or preceed each line with sudo):
     $ sudo dd if=/dev/zero of=/mnt/swapfile bs=1024 count=1048576
     $ sudo chmod 600 /mnt/swapfile
     $ sudo mkswap /mnt/swapfile
     $ sudo swapon /mnt/swapfile
     $ sudo echo '/mnt/swapfile none swap sw 0 0' >> /etc/fstab
     $ sudo sysctl vm.swappiness=10

Open in new window

Check if your new swap is working;
    $ sudo swapon -s

Open in new window

   If '/mnt/swapfile' appears in the results, then it is working.

Other notes:

If swappiness=0, swapping will occur only if RAM is exhausted.  Increasing the number increases the likelihood that swap will be used even when RAM not exhausted.  You have to experiment with this.  A value of 60 would be reasonable, but a lot depends on your system configuration.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Currently, there is not an RPM package available under the RHEL/Fedora/CentOS distributions that gives you a quick and easy way to allow PHP to interface with Oracle. As a result, I have included a set of instructions on how to do this with minimal …
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now