Saturday, March 14, 2009

Setting Up Swap Space on Redhat Linux

Setting Up Swap Space on Redhat Linux

There might be times when you've run out of swap space and it is not practical to repartition a drive or add a new one. In this case, you can use a regular file in an ordinary partition. All you have to do is create a file of the size you want

[root@sys80 ~]# cat /proc/meminfo grep SwapTotal
SwapTotal: 4610644 kB
su - root
dd if=/dev/zero of=tmpswap bs=1k count=900000
chmod 600 tmpswap
mkswap tmpswap
swapon tmpswap

#su - root
[root@sys80 ~]# dd if=/dev/zero of=tmpswap bs=1024 count=1048576
1048576+0 records in
1048576+0 records out
[root@sys80 ~]# chmod 600 tmpswap
[root@sys80 ~]# mkswap tmpswap
Setting up swapspace version 1, size = 1073737 kB
[root@sys80 ~]# swapon tmpswap
[root@sys80 ~]# cat /proc/meminfo grep SwapTotal
SwapTotal: 5659212 kB
[root@sys80 ~]# free -m
total used free shared buffers cached
Mem: 3030 1333 1696 0 25 1157
-/+ buffers/cache: 150 2879
Swap: 5526 0 5526

To disable the temporary swap space execute the following commands:
su - root
swapoff tmpswap
rm tmpswap

No comments: