LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Change the swap size (https://www.linuxquestions.org/questions/linux-general-1/change-the-swap-size-333672/)

ust 06-14-2005 10:38 PM

Change the swap size
 
I hv newly setup the RH linux , it use auto partition method to install , I didn't define the swap partition size , if I want to install its size , is it possible ? if yes , how to do it ? thx.

seran 06-15-2005 12:29 AM

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*

pvs 06-15-2005 06:37 AM

the seran's 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=<desired size in Kb>
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)

seran 06-15-2005 07:24 AM

Creating a swapfile instead of using a partition on the disk, is a good idea.

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. Today I am happy, I learned a new thing.

pvs 06-15-2005 07:45 AM

Quote:

Originally posted by seran
I rebooted the machine and I saw this error message on the terminal.

Enabling swap partitions: could not create swap partition /swapfile [ERROR]

That's right: you can't use swap without "mkswap" first. It initializes a file/device so it cat be used as swap.

seran 06-15-2005 08:11 AM

I thought this will be useful. http://www.linux-tutorial.info/modul...ial&pageid=218

marcosdumay 06-15-2005 02:51 PM

Quote:

Creating a swapfile instead of using a partition on the disk, is a good idea.
It depends. Keeping the swap on a file is slower than on a partition. You will note the difference if you start using it often.

If you almost never use the swap, otherwise, you may choose to lose some speed (and response time) on those rare occasions and get a simpler partition scheme.

edong23 06-16-2005 12:25 AM

so..... i dont get it. you had a swap partition, on /dev/hda2 made by redhat, and you switched to a swapfile which is slower cause it uses the filesystem of the partition it is on, i think,,, and so now what with your swap partition. that makes no sense.!?!? did i miss something. that is like putting your root partition on a cd so you can just have an unused root partition on the harddrive.

pvs 06-16-2005 01:11 AM

Quote:

Originally posted by edong23
so now what with your swap partition. that makes no sense.!?!? did i miss something.
1) it still can be used as swap-space
2) it can be formatted and used as a place for other files (not neccessary swap)
3) if you have 256Mb or more RAM Linux as a rule uses swap very rarely, so there is almost no speedup when using partition instead of file

edong23 06-16-2005 02:23 AM

as a rule huh. you must not use your linux box for what it is intended for. looong uptime, free software to do extensive audio and video encoding and ripping, multitasking ( like me downloading movies, while ripping mp3s, while encoding another movie, while instant messaging, while checking the forums, while playing the linux version of doom3, while downloading the linux version of quake, while also using another peer2peer to download the crack to the windows version of quake so that i may use the linux version, and all the while compiling the new 2.6.11.12 kernel. this is what i am doing right this minute, and yes i am accessing my swap space... :) i have 768MB Rambus mem@800mhz and i always make sure that my linux systems have at least a gig of swap. you dont want to sell yourself short incase you actually want to do something memory intensive. but anyway i jsut didnt understand y you wanted to have a swap file in place of a swap space.

btw. my uptime is 72 days 17 hours 46 minutes can you imagine? my mother is bound to kick the bucket real soon with all i put it through.

pvs 06-16-2005 03:18 AM

Quote:

Originally posted by edong23
but anyway i jsut didnt understand y you wanted to have a swap file in place of a swap space.
I just advised to create swap file instead of resizing partitions, because it is simplier.

edong23 06-16-2005 11:04 PM

well yeah. it is sound advice. it is easier, but like i said i was confused as to y the user that posted the question.


All times are GMT -5. The time now is 09:55 AM.