The time now is Wed 19 Jun 2013, 06:46
All times are UTC - 4 |
| Author |
Message |
sickgut

Joined: 23 Mar 2010 Posts: 1157 Location: Tasmania, Australia in the mountains.
|
Posted: 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
|
|
 |
musher0

Joined: 04 Jan 2009 Posts: 2273 Location: Gatineau (Qc), Canada
|
Posted: Tue 17 Apr 2012, 10:37 Post_subject:
|
|
Very informative article. Thanks.
_________________
"To err is human; to really foul things up, you need a computer!" / "L'erreur est humaine; pour vraiment f... la m..., il faut un ordinateur." (Carleton University, banderole à la Rentrée 1979 / banner, start of 1979 school year) 
|
|
Back to top
|
|
 |
|
|
|
Rules_post_cannot Rules_reply_cannot Rules_edit_cannot Rules_delete_cannot Rules_vote_cannot You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|