VectorLinux
July 22, 2014, 04:59:46 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: How to create and use swap files  (Read 1906 times)
roarde
Vectorian
****
Posts: 519


move the needle


« on: August 21, 2011, 05:08:01 pm »

Traditionally, swap partitons are used, and that's still the easiest and
probably best way to go. This is about using swap files instead, should
you have a need to.

At the present time VL installers detect and automatically use swap partitions,
but not swap files. Until there's a consensus on swap file naming and location,
auto-enabling swap files will be nearly impossible.
FWIW, I use a swap file. Let's assume you've made the same choice.

Those in a hurry can just read the Code: sections.

Any user can create and format a swap file, but to put it in a good location
and enable it requires root, so do all this as root.


I don't like plain files on / directory, but don't find a better place to put
it. When looking for your own location, pick something that's definitely
mounted before swap might be turned on. Look at the order in /etc/fstab.

Until there's a convention, the file's name doesn't matter and we'll use
"swap0".

1024 bytes to a KB, so bs=1024. 1024 KB to a MB; this example creates a 256 MB
swap file. 1024 * 256 = 262144, so count=262144.

Create the swap file.
Code:
root:# dd if=/dev/zero of=/swap0 bs=1024 count=262144
I thought you said 256 MB, not (268 MB)!
That, too, is an ongoing debate. Try "ls -h -l /swap0". Won't be solved here --
moving on.


Format the swap file.
Code:
root:# mkswap /swap0


Now edit /etc/fstab, adding the following lines. Be sure they come after the
lines for the partition the swap file was created on. The comment (starts with
"#") lines are already there in some cases.

Edit /etc/fstab.
Code:
# Swap partitions
# The 'sw' option means auto activating with 'swapon -a'.
/swap0      none   swap   sw   0 0
The swap file should be activated and used at next reboot and . . .

You can turn it on now, without rebooting:
Code:
root:# swapon -a
"swapon /swap0" works, as well.


If you've turned on your new swap file, check its status. This step can work
for a normal user, but you need the full path to swapon, as follows.


Check swap status.
Code:
vluser:$ /sbin/swapon -s
Filename                                Type            Size    Used    Priority
/swap0                                  file            262136  0       -1

If you get the same answer to "/sbin/swapon -s" after a reboot, you're all set.
« Last Edit: August 21, 2011, 10:55:38 pm by roarde » Logged

Robert
VL STD 7.1 RC2.2.2, icewmvmods
MikeCindi
Tester
Vectorian
****
Posts: 1071


« Reply #1 on: August 21, 2011, 07:47:04 pm »

Thanks for the how-to. What have you found to be the advantage of a swap file vs. swap partition and why would someone else choose this method over the "standard" of a partition? Also have you noted any disadvantages outside of the post-OS-install setup of your swap file?
Mike
Logged

The plans of the diligent lead to profit...Pro. 21:5
VL64 7.1b3                                     RLU 486143
roarde
Vectorian
****
Posts: 519


move the needle


« Reply #2 on: August 21, 2011, 09:20:31 pm »

My main reason for using a file is that I use some operating systems that can only understand what's in the DOS-type mbr, so I have to make best use of the four entries available. There are other reasons I'm sure, but they're outside the scope here. Try http://duckduckgo.com/?q=swap+file+vs+partition.

Note that much of the info on their relative speeds is outdated.

I haven't noticed any disadvantages, but then I'm not looking for them. I have (just) enough RAM to not need swap during a system upgrade, tho. Using a file for swap would make upgrading VL or any unixish more difficult were swap needed for the process.

There should be a swap partition howto here, and a good tut or discussion of swap (and related) in general. I'm the wrong person for either of those, and wanted to focus this thread on one thing only.

As of now, my general advice is to use a partiton if you've no reason not to. Made a slight edit to the original post to reflect this. Thanks for pointing it out.
« Last Edit: August 21, 2011, 10:50:53 pm by roarde » Logged

Robert
VL STD 7.1 RC2.2.2, icewmvmods
nightflier
Administrator
Vectorian
*****
Posts: 4018



« Reply #3 on: August 22, 2011, 04:46:48 am »

I have found this procedure useful for adding swap to running servers without interrupting service.
Not having to re-partition your drive just to manage swap is a great feature.
Logged
MikeCindi
Tester
Vectorian
****
Posts: 1071


« Reply #4 on: August 22, 2011, 08:59:00 am »

I have used a swap file a few times in the past but personally found no advantage over using a swap partition. (This was on a laptop that I was trying to get "tux-on-ice" to work with the VL5 series.) I do have a couple of home servers but the load on either is minimal and each has enough RAM so that swap usage almost never happens. I was just curious to learn of other potential benefits or pitfalls.
Thanks,
Mike
Logged

The plans of the diligent lead to profit...Pro. 21:5
VL64 7.1b3                                     RLU 486143
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!