This is simple method for Increase your available swap space with a swap file
All of your devices function, and everything is configured just the way you like it. At least you think so, until you start running out of memory when you have Open Office.org and lots of browser tabs open simultaneously. You realize you should have specified a larger swap partition during your install. this simple method of installing gain .swap partition.
There’s more than one way to maintain your Linux system. Instead of creating a swap file, you could instead resize and or reshuffle your partitions with parted or its graphical front end QtParted.
To start , see how much swap space you already have. At a command line by typing ,
swapon -s (you might need to prepend /sbin/ if you’re not root)
the command should produce a message :
Filename Type Size Used Priority
/dev/hda2 partition 128044 92472 -1
The numbers under “Size” and “Used” are in kilobytes.
Let’s figure out where to put it. Running df -m from a command line should produce output something like this:
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/hda1 11443 6191 5252 55% /
The -m switch we used provided us with output in megabytes. Under the “Available” column we have approximately 5GB of free space on our root partition. Let’s steal 512MB of that for our auxiliary swap file. You might want more or less, depending on your memory needs, how much swap space you already have available, and how much free disk space you have. The general rule of thumb for swap size is that your total available swap space should be around double your RAM size. If you have additional partitions, and one of those is a better candidate than the / partition, feel free to use it instead.
Please make Back up your important data before proceeding. If you carefully follow the steps below you should be fine,
In order to create our supplementary swap file, we’re going to use the dd (data dump) command. You’ll need to become root to perform the next few steps. su - and enter your root password. When you’re ready,
dd if=/dev/zero of=/extraswap bs=1M count=512
replacing 512 with the number of megabytes you want in your auxiliary swap file. if= and of= are short for infile and outfile. The /dev/zero device file will give us zeroes to be written to the output file. If you want this file on a different partition, say your /var partition, you would replace /extraswap with /var/extraswap.
Now we have a file the size we want on disk, and we can prepare it for use as a swap partition. We’ll use the mkswap command to make our file swap-consumable for the Linux kernel. Again as root,
#mkswap /extraswap
To turn on our swap file, we run swapon /extraswap. Now when we run swapon -s we should see our existing swap partition and our new swapfile. Also, the free command should show an increase in total swap space.
But we’re still not done yet. If we reboot our machine now, our new swapfile won’t be active, and we’ll have to run swapon /extraswap again. to make things more permanent, you need to edit our /etc/fstab file.
make a copy of the file. Something like this should do the trick:
cp /etc/fstab /etc/fstab.mybackup
open /etc/fstab in your favorite text editor and find a line about your swapfile that looks something like this:
/dev/hda2 none swap sw 0 0
You’ll need another line like that underneath it pointing to your new swap file. Replace the first column with the location of your new swap file. For our example, the new line should look like this:
/extraswap none swap sw 0 0
Save the file. Mistaken changes to /etc/fstab could render your system unbootable, so just to make sure you didn’t accidently change anything else in /etc/fstab, run diff /etc/fstab.mybackup /etc/fstab to check for differences. That should output only the single line you added, with a “>” sign in front of it. If you see anything else in diff’s output, edit /etc/fstab again, fix it, and run the above diff command again.
In practical terms, there’s a minimal performance hit from this extra step. By the time you’ve run out of RAM and are beginning to swap, you’re already suffering a massive performance hit. After your original swap partition is full and you’re spilling into your auxiliary swap file, your system should be suffering badly enough that the added performance hit will be completely imperceptible.
In order to avoid this sort of problem entirely with your next install, using Linux’s Logical Volume Manger is probably a good idea, and there are other Linux memory management techniques. Of course the ideal solution is to just install additional RAM.
Incresing a swap space on Linux OS
Labels: Linux
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment