Wednesday, August 1, 2007

Create swap file in Fedora- Linux

Swap file is used by the Kernel for Virtual Memory.
It is recommended to have swap size double of the RAM but if RAM is more than enough (>512 MB) then
smaller swap has no issue.

To know the actual memory (RAM) and already swap on a Linux box use the free command.

$ free
total used free shared buffers cached
Mem: 507956 489860 18096 0 9580 76876
-/+ buffers/cache: 403404 104552
Swap: 1012084 69668 942416

Now to create extra swap file follow the steps:
(To create swap file of approx 1GB)

$ dd if=/dev/zero if=/usr/more_swap bs=1000000 count=1024

(It will create one swap file more_swap in /usr)

$ chmod 600 /usr/more_swap
$ mkswap /usr/more_swap
$ swapon /usr/more_swap


Now add this file to the /etc/fstab file (at last)
$ vi /etc/fstab

/usr/more_swap swap swap defaults 0 0

2 comments:

Andrew said...

Just one little problem:

$ dd if=/dev/zero if=/usr/more_swap bs=1000000 count=1024

should be
$ dd if=/dev/zero of=/usr/more_swap bs=1000000 count=1024

Andrew said...

... (Different Andrew said)

Or more readable still..

$ dd if=/dev/zero of=/usr/more_swap bs=1M count=1024

Whats new in Ajuby 0.5