Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 24 Oct 2014, 23:05
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
swap on the fly on any linux system
Moderators: Flash, Ian, JohnMurga
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message

Joined: 23 Mar 2010
Posts: 1157
Location: Tasmania, Australia in the mountains.

PostPosted: Tue 17 Apr 2012, 08:47    Post_subject:  swap on the fly on any linux system
Sub_title: out of resources? unfamiliar system? make some swap and activate it

Hi Dogfarmers,

i would like to share with yall a trick i use all the time that most likely the techy people among you already know but those of you who dont, this is really cool to be able to do.

These commands are available in any linux, so it should be universal.

open a terminal, most linuxs have a console/ terminal icon you can click to do this, you dont have to exit your desktop environment, this works within X or at the console, it dont matter.

use the following (lines separated by enter):

------- code snippet ---------
cd /
dd if=/dev/zero of=mrswappy bs=1M count=300
mkswap mrswappy
swapon mrswappy

------- code snippet ---------

when you cd / you are moving to the top dir of your OS, this is usually located on the hdd and partition the OS is using unless your using a live OS from a pen drive or cdrom or some frugal setups.

the dd if=/dev/zero of=mrswappy bs=1M count=300 command creates a new file that contains all zeros. Note that the name mrswappy can be anything you like and the count can be anything you like. the above example makes a 300MB swapfile. You can change the count to any other number you like, 1000 will make a 1000MB swap, and 50 will make a 50MB swap etc... etc...

mkswap mrswappy command turns the file mrswappy into a swapfile, not just an empty file, altho yes it is empty still, this command turns it into a filesystem that is the same as the linux swap partition, it even had a uuid and can have a drive label if you want it to altho that wont be discussed here.

swapon mrswappy command tells the linux system to mount the new swap file and use it immediately.

You can see your swapfile in action by the: free and top commands
free command will show you the used ram and swap etc.
Top will show you in real time the usage of the ram and swap and what resources all the apps that are running are using. The ram and swap stuff is at the top of the screen, application resource stuff is below this.

remember the file is located in the / dir and you can delete it next boot, it will not be automatically activated next time you boot. If you want it to be automatically actuvated then on boot then add an entry in /etc/fstab ... you may wanna google how to do this, i wont explain it here as the point of this post is to show you how to mount it on the fly whenever you like not make a permanent change.

Note for live and or frugal installed OSes:

instead of using cd / at the beginning, cd to a dir that you know accesses either the HDD or partition that you know is a real HDD or partition that is outside of your savefile or the live temporary ramdisk.

You can use the command: fdisk -l (lowercase L not an i or upper case i)

this will list the connected disks and you can mount whatever you like and make the swapfile there, it can be a usb stick or external hdd or another hdd or partition but not in a savefile (wont work) or in the ramdisk (defeats the purpose).

When trying a live cd/ dvd and you have low ram this can help quite alot. usually there will be a /dev/sda1 on your system you can mount then cd to and create the swap file on. To make sure your using a real disk in a live Puppy then open up the disk via the icon for it on the desktop then right click within the disk window and select "terminal here" then run all the commands except for the cd / at the beginning, as the "terminal here" does this automatically, it cd's to the filesystem you right clicked in.

2 ways to remove the swapfile after you have finnished with it:

1) reboot and delete the file without mounting it first
2) no need to reboot, but run swapoff -a (can also be swapoff all) and then delete the swapfile. However in some cases you may have used too many resources to be able to swapoff. If this is the case you cant delete it as its in use, so you will need to reboot first then delete as per option 1.

This is especially useful if you rent a cheap virtual private server (vps) that uses Xen virtualization, as this allows you to run your own swap. Even tho it probable already has a small mount of swap on another partition, you can add more. (openvz doesnt let you do this). When you add more swap on a VPS often its as good as RAM, as the host system unless its overloaded will be running all its virtualization within its RAM, so your new swap file is possibly as fast as your ram is. However this is a little bit of a crap shoot as if the host server is oversold or under a heavy load at the time then when your swap is activated and used it will be using HDD space not the RAM of the host server.
Back to top
View user's profile Send_private_message Visit_website 

Joined: 04 Jan 2009
Posts: 4257
Location: Gatineau (Qc), Canada

PostPosted: Tue 17 Apr 2012, 10:37    Post_subject:  

Very informative article. Thanks.
"Logical entities must not be multiplied needlessly." / "Il ne faut pas multiplier les êtres logiques inutilement." (Ockham)
Back to top
View user's profile Send_private_message Visit_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot attach files in this forum
You can download files in this forum

Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0490s ][ Queries: 12 (0.0034s) ][ GZIP on ]