create a swap partition

neorder

Verified User
Joined
Oct 1, 2003
Messages
346
i just noticed my new server doesn't comes with a swap partition,
my question is: is swap still needed with nowadays fast computers, i've seen many ppl said swap would slow down the server if there is enough RAM.

but the problem is i have 1.5G of RAM, i still *think* it would be better off to have a swap partition, but i've never created a partition remotely, so i want to confirm here, would be okay i just use http://www.gnu.org/software/parted/manual/ to create a swap and reboot? is there any more detailed instruction you can recommand.

thanks.
 
A swap is only needed if you don't have enough ram, but even today's servers never have enough ram persay. In an event you run out of ram you would (in layman's terms) be screwed.

I create swap partitions that are a minimum of equal to the ammount of ram, usually more depending on the server's purpose.
 
Last edited:
thank you, the server is for web hosting of course, since i've decided to create a swap patition, the problem now is how am i going to create one?

i had never tried to create one remotely, i want to consult professionals opinion.

thank you.
 
How do you know you don't have a swap partition?

Please post the output of

df -h

Jeff
 
of course i know how to use df, and there is no swap, datacenter admin replied me he forgot it. :(
 
neorder said:
of course i know how to use df, and there is no swap, datacenter admin replied me he forgot it. :(
Well, you asked for an answer from a professional.

You got a response from a professional who asked you for a bit more information.

And you told the professional you knew more than he did and you refused to reply with the information.

The output of the "df -h" would have made it a bit easier to determine if you could safely create a swap partition, but you didn't think that was important.

Do you still want an answer?
from: "http://dev.panopticsearch.com/swapfile-notes.html:

Adding swap space on Linux 2.4

* Minimum swap space required is 256 Mb.
* Create a 1GB swap file with dd if=/dev/zero of=swapfile bs=1024 count=1M.
* Creating a new swap partition requires use of fdisk, but this should be used with care on disks already in use.
* Use /sbin/mkswap -c swapfile to "format" the new swap file. Similarly for a new swap partition.
* Set swap file ownership and permissions chown root.root swapfile; chmod 0600 swapfile.
* Add each new swap space entry to /etc/fstab. Eg. swapfile swap swap defaults 0 0.
* Enable the new swapspace(s) with /sbin/swapon -a.
You'd have to resize one of your partitions to make room for a swap partition, so you're better off using a swap file.

Jeff
 
Last edited:
thanks, i will take your advise.

anyway, the following was how i did two days ago, and it redered my server to be unbootable.


$ dd if=/dev/zero of=/swap bs=1024 count=1024
$ mkswap /swap
$ sync
$ swapon /swap

after i did above, the /swap partition i created was showing me it's a *huge* partition, it become sth like 1000G+, my HDD is only 80G, then the system message recommand me to reboot, i did, then it became unbootable....

i'm going to get it reformat again..:(
 
I'm sorry to hear of your problems.

We do not ever recommend rebuilding partition tables on running servers.

When you have it rebuilt you should probably have them rebuild it with a swap partition.

Jeff
 
Resize

jlasman said:
...
You'd have to resize one of your partitions to make room for a swap partition, so you're better off using a swap file.

Jeff [/B]

Jeff,
I have this:

Filesystem Size Used Avail Use% Mounted on
/dev/sda3 73G 666M 69G 1% /
/dev/sda1 54M 13M 38M 26% /boot
/dev/shm 491M 0 491M 0% /dev/shm

and:
total used free shared buffers cached
Mem: 1004184 142792 861392 0 35200 87656
-/+ buffers/cache: 19936 984248
Swap: 530136 0 530136

there is any way to resize the swap to 2GB?

thank you,
winger.
 
Not easily.

As a local user (logged in through a terminal, not ssh) you could attempt to resize and recreate partitions using qparted.

Not recommended.

Jeff
 
Back
Top