Solved

Swap-file

Posted on 1996-12-10
2
435 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

705 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