How To add more swap without having to Re-partation

Write your "How To" regarding anything you are comfortable with and you feel it will help the forum members.

NOTE :: All threads started here will appear only after the approval from Administrator
Post Reply
anish
Posts: 353
Joined: Fri Apr 27, 2007 12:34 pm
Contact:

How To add more swap without having to Re-partation

Post by anish »

If you dont have nough mmory, (ram + swap) there are 3 things you can do.
the first 2 are the most obviouse,

1) buy more memory.
2) use knoppix and qtparted to re-size your parttions
3) the little known easy method.

You may not know, but linux has a loop driver in the /dev/ folder that allows a file on the hard disk to act as a disk drive / disk partiton. you can use it in exactly the same way your would use /dev/hda1 or /dev/cdrom.

here is how to use it to quickly add extra virtual memory.

before we start, make sure your loop driver is loaded... have a look in the /dev/ folder for files named loopX where X is a number between 0 and 7, possably by using the ommand "ls /dev/ | grep loop"
if its not there, then as root run "modprobe loop" and look again.

all these commands need to be done as root user.
to become root user run the command "su -" and enter the root password.
when you have finished, be sure to run "exit" to giveup the root privilages.

first, create the file that will contain the virtual disk drive.

CODE

dd if=/dev/zero of=/SWAP.img bs=1M count=256


the abouve command will copy 256 * 1Megabyte from the file /dev/zero into the file /SWAP.img.
/dev/zero is a pretend file, which dontains an infinite number of "0"'s for more info, read "man dd"
replace 256 with the extra amount of memory you require.

secondly, we need to setup the loop driver, to create a /dev/ interface to the file.
their are 8 loop devices, somtimes the first one or 2 is in use, so to be save, lets use the 6th.
losetup /dev/loop5 /SWAP.img
now /dev/loop5 will act as a disk drive, and save all its information to the /SWAP.img file automatically.
for more information about losetup, read "man losetup" (you can delete a loop device like so "losetup -d /dev/loopX" where X is the loop number.

thirdly... we need to format the disk as swap.
mkswap /dev/loop5
finally, activate the swap
swapon /dev/loop5
if you ever need to remove the swap file, first de-activate, then delete the interface, then delete the file.
swapoff /dev/loop5
losetup -d /dev/loop5
rm /SWAP.img
to make the added swap activate automatically add the following lines to the end or your rc.local startup script. this script is in different places for different distro's but i will be somwhere in your /etc/ folder.
most likely /etc/init.d/rc.local
losetup /dev/loop5 /SWAP.img
swapon /dev/loop5


SHAdmin
Posts: 2089
Joined: Sat Dec 18, 2004 11:28 am
Contact:

Post by SHAdmin »

True that was not a very well known easy method :)

You have been credited 35 points for sharing it.
Zeqya
Posts: 155
Joined: Mon Aug 20, 2007 6:36 pm

Post by Zeqya »

Swap What?I Dont Really Understand What You Mean

Why Do You Lose Point For Writing A Reply?
Lixas
Posts: 750
Joined: Wed Feb 16, 2005 4:21 pm

Post by Lixas »

In this forum you loose one point for reply. Dont worry, it's just one point. Just be active, and you will have enough point for any services (like me :D ). Bus please remember- spam is not tolerated. For example, i'm not worying about loosing points in this way, because is such way i get more respect from admin and other forum members (that is also important)

Swap is a disc partinion, used in linux systems to make computer more faster, because swap acts like a ram, but only disk space is used
Image
Zeqya
Posts: 155
Joined: Mon Aug 20, 2007 6:36 pm

Post by Zeqya »

Lixas wrote:In this forum you loose one point for reply. Dont worry, it's just one point. Just be active, and you will have enough point for any services (like me :D ). Bus please remember- spam is not tolerated. For example, i'm not worying about loosing points in this way, because is such way i get more respect from admin and other forum members (that is also important)

Swap is a disc partinion, used in linux systems to make computer more faster, because swap acts like a ram, but only disk space is used
Ok Thanks But That Time I Only Had 0 Points And Got - After Posting In This Place I Was Trying To Get More Not Losing But Now I See How Easy To Get Points So It Isnt Any Problem To Reply Here Anymore
Want A Nice Website With A Forum
Dont **** Unless You Want To Die If You're Already Dead Then Ok
Wanna Make Colors Too?BBcode
lenchnikin
Posts: 1
Joined: Wed Sep 09, 2009 2:35 pm

How To add more swap without having to Re partation

Post by lenchnikin »

I dont think so. Extended bootloader is bigger than original bootloader, so parition adresses and sizes in flash will be changed.
If you flash the original firmware back again, it might be that the partitions dont match anymore withe the original firmware.

You should find more about that if you search this forum.
z327774948
Posts: 11
Joined: Mon Sep 24, 2012 1:36 am

Re: How To add more swap without having to Re-partation

Post by z327774948 »

It's very practical, thank you!!!
Post Reply