Wednesday, August 13, 2008

How to increase swap space in Linux

Sometimes we find that the swap partition we set up at install-time just isn't enough anymore. Maybe we're upgrading your system to RedHat 4.1 from a version of RedHat that used less swap in relation to physical RAM. Perhaps you're running Oracle or adding more memory and would like to increase swap space accordingly.

#free -m
total used free shared buffers cached
Mem: 3772 2201 1571 207 179 1541
-/+ buffers/cache: 480 3292
Swap: 2047 0 2047

#dd if=/dev/zero of=swapfile bs=1024 count=132207
132207+0 records in
132207+0 records out

# ls -l swap*

-rw-r--r-- 1 root root 135379968 May 19 19:06 swapfile

# chmod 600 swapfile

# /sbin/mkswap swapfile
Setting up swapspace version 1, size = 135372800 bytes

# /sbin/swapon swapfile
# free -m
total used free shared buffers cached
Mem: 3863260 2384072 1479188 212636 183964 1711140
-/+ buffers/cache: 488968 3374292
Swap: 2228636 0 2228636

As we see the swap has increased from 2047 to 2228636

No comments: