Operating System - Linux
1822193 Members
3949 Online
109640 Solutions
New Discussion юеВ

changing the swap partition size in linux

 
laaalitha
Advisor

changing the swap partition size in linux

I installed new memory (RAM) to a machine had RH LINUX OS.In red hat Linux how to change (increase ) the swap partition size or Add a NEW swap partion.What are the commands and steps ?
3 REPLIES 3
kcpant
Trusted Contributor

Re: changing the swap partition size in linux

Hi,

Make a new partition of Swap type by using fdisk command, and then add an entry into /etc/fstab .

You may get more info from following link:


http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1091537
PreSales Specialist
Sandeepk_1
Advisor

Re: changing the swap partition size in linux

Hi Laalitha,
Please find the necessary below:
Use fdisk to create the swap partition( command t will ask for swap-id, give 82 for linux swap )and then do
mkswap /dev/hda*
swapon /dev/hda*

The above answer is correct only if there left some free space (i don't think it is!). If your harddisk is fully partitioned you need to find some way to resize(or simply delete) some partition. More easier way is to create swap file:
dd if=/dev/zero of=/swapfile bs=1K count=
mkswap /swapfile
swapon /swapfile
if you don't wish to tell "swapon /swapfile" every time you boot modify your /etc/fstab file and add record similar to created by your setup program (in case of automatic partitioning it usually exists)

Also,I tried creating a swapfile on my machine. I had a swap partition on /dev/hda2. I deleted this partition and added the swapfile entry inside /etc/fstab. I rebooted the machine and I saw this error message on the terminal.
Enabling swap partitions: could not create swap partition /swapfile [ERROR]
In the shell prompt I gave
mkswap /swapfile
swapon /swapfile
and then rebooted again. Then I got
Enabling swap paritions: [OK]
This worked fine for me.
So, I can use my /dev/hda2 partition for other purposes. This will be helpful if there is not enough space to create a swap partition on the disk

Try the above(using the best options) and let me know!!
Vitaly Karasik_1
Honored Contributor

Re: changing the swap partition size in linux

If you aren't going to run more applications on your machine, you don't need to add swap at all.
For example: yesterday you had 1GB RAM + 1GB swap = 2GB virtual memory.
today you have 2GB RAM + 1GB swap = 3GB virtual memory.