Solved

Swap-file

Posted on 1996-12-10
2
431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Fine Tune your automatic Updates for Ubuntu / Debian
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

726 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