Operating System - Linux
1830207 Members
1845 Online
109999 Solutions
New Discussion

Re: How to add swap size?

 
SOLVED
Go to solution
violin_1
Advisor

How to add swap size?

Hello ,

I have a Linpus Linux release 6.4 ,
Yesterday I added 512M RAM on the server ,

but I don't know how to add swap size ,
I did some tests but failed ,
(I've crushed 2 test servers.)

I uploaded the testing steps ,
And I know maybe I make mistakes in mkswap or swapon ,

Should somebody help me to add swap size?

Or should I enlarge /dev/hdb1 size?
like :
mkswap -v1 /dev/hdb2 128512
and then :
swapon -v -p -1 /dev/hdb2

Need helps,

Thanks billions!

Violin.
5 REPLIES 5
I_M
Honored Contributor
Solution

Re: How to add swap size?

Hi

You can not "extend" the current swap partition, instead you can create another partion then add it to additional swap.
You can add the swap partition on hda or hdb.

> # mkswap -v0 /dev/hda1 128512
This command will initialize your "live" OS partition to swap partition. That's why you crashed the system.

So what you need is
1) Create new partition
2) reboot the system to make the new partition ready to use from the system.
3) mkswap /dev/hdXXX is just OK.
The default is swap version 1 (new style swap area)
And you don't need to put the size. The partition will be initialized as swap
4) put one line into /etc/fstab
5) swapon -a

Good luck



violin_1
Advisor

Re: How to add swap size?

Thanks for your tips.

But if I have no free disk to create partition,
how could I do?

All the disks are created mount point,
But I have enough free space in /u02,

Can you help me? Thanks again.

Violin.
I_M
Honored Contributor

Re: How to add swap size?

Hello again,

If you don't have additional space for new partition, use "swap on filesystem".

Following example is how to create 500mb swap on filesystem.

# dd if=/dev/zero of=swapfile bs=1024k count=500

This command will create 500mb file. Make sure you put "count" otherwise you will make your filesystem full.

# mkswap swapfile

# chmod 0600 swapfile

Edit /etc/fstab
/swapfile swap swap defaults 0 0

# free

# swapon -a

# free (to confirm your system use the new swap)

"dd" will kill your system, if you forget options. Be careful!!

Good luck

violin_1
Advisor

Re: How to add swap size?

And question again,

If I add more memory , could I use dd again?

like:

dd if=/dev/zero of=swapfile1 bk=1024k count=500

Could I?

Thanks.
I_M
Honored Contributor

Re: How to add swap size?

Hello again,

Yes, you can create additional "swap on filesystem" and mkswap then enable it.

I am not sure how many swaps you can create in a system, but the max swap partition size is 2gb. so I guess a max-swap-file-size would be the same 2gb.

Regards,