?
Solved

Swap-file

Posted on 1996-12-10
2
Medium Priority
?
438 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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.:
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.
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

743 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