royong
12-05-2006, 17:43
First we check out the memory usage:
[root@srv /root]# free -m
total used free shared buffers cached
Mem: 251 242 8 22 11 32
-/+ buffers/cache: 198 52
As you can see, we do not have any swap space enabled. Presuming that we do not have any free space on the hard disk, we can only create a swapfile and enable that as the swap space that the system will use.
The following will create a swapfile of approximately 1GB
[root@srv /]# dd if=/dev/zero of=swapfile bs=1024 count=1024000
Now to make it non-world readable
[root@srv /]# chmod 600 swapfile
Now we setup the swap area and enable it for use.
[root@srv /]# mkswap swapfile
[root@srv /]# swapon swapfile
Monitoring to reconfirm that we now have swap enabled
[root@srv /]# free
total used free shared buffers cached
Mem: 257632 254632 3000 2512 36172 15096
-/+ buffers/cache: 203364 54268
Swap: 1024000 124000
Finally to make the setting permanent and to enable swap on bootup
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
[root@srv /root]# free -m
total used free shared buffers cached
Mem: 251 242 8 22 11 32
-/+ buffers/cache: 198 52
As you can see, we do not have any swap space enabled. Presuming that we do not have any free space on the hard disk, we can only create a swapfile and enable that as the swap space that the system will use.
The following will create a swapfile of approximately 1GB
[root@srv /]# dd if=/dev/zero of=swapfile bs=1024 count=1024000
Now to make it non-world readable
[root@srv /]# chmod 600 swapfile
Now we setup the swap area and enable it for use.
[root@srv /]# mkswap swapfile
[root@srv /]# swapon swapfile
Monitoring to reconfirm that we now have swap enabled
[root@srv /]# free
total used free shared buffers cached
Mem: 257632 254632 3000 2512 36172 15096
-/+ buffers/cache: 203364 54268
Swap: 1024000 124000
Finally to make the setting permanent and to enable swap on bootup
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab