By Urbana Der Ga'had
Sometimes in the course of a system's existence you find that the swap partition you set up at install-time just isn't enough anymore. Maybe you're upgrading your system to RedHat 7.1 from a version of RedHat that used less swap in relation to physical RAM. Perhaps you're running Oracle. Or maybe you're adding more memory and would like to increase swap space accordingly.
Our machine srv-2 is swapping like mad and we just can't take it down right now to add more RAM. So to keep the machine from running out of memory entirely and freezing, we'll add 128 MB more swap space by creating a swap file.
First we check out the memory usage:[root@srv-2 /root]# free -m |
Make sure we have 128 MB laying around somewhere:
[root@srv-2 /root]# df |
OK, we're going to make a swap file in /opt by using dd to create a file 128 MB in size.
[root@srv-2 /opt]# dd if=/dev/zero of=swapfile bs=1024 count=132207 |
Hey, I know, let's not make it world-readable...
[root@srv-2 /opt]# chmod 600 swapfile |
Now we set up the swap area and enable it.
[root@srv-2 /opt]# mkswap swapfile |
And viola! Twice as much swap as before.
[root@srv-2 /opt]# free |
You can edit /etc/fstab to enable your swap file automatically at boot time.
By adding an entry like this:
/opt/swapfile swap swap defaults 0 0 |
Sure, swapping's ugly, slow and will grind your hard drives to dust. But even modern systems which have been tuned for performance require a generous oodle of swap space.
No comments:
Post a Comment