Saturday, January 22, 2011

Increase your available swap space with a swap file(Linux)

1)At a command line, type swapon -s (you might need to prepend /sbin/ if you're not root). The command should produce a message that looks something like this:

Filename Type Size Used Priority
/dev/hda2 partition 128044 92472 -1

2)Running df -m (short for "disk free") from a command line should produce output something like this:

Filesystem 1M-blocks Used Available Use% Mounted on
/dev/hda1 11443 6191 5252 55% /


3)dd if=/dev/zero of=/extraswap bs=1M count=512
replacing 512 with the number of megabytes you want in your auxiliary swap file. if= and of= are short for infile and outfile. The /dev/zero device file will give us zeroes to be written to the output file. If you want this file on a different partition, say your /var partition, you would replace /extraswap with /var/extraswap.

Again as root, carefully type:

4)mkswap /extraswap

5)swapon /extraswap.

6)swapon -s we should see our existing swap partition and our new swapfile. Also, the free command should show an increase in total swap space.

7)cp /etc/fstab /etc/fstab.mybackup and add the following entry same like existing:

/dev/hda2 none swap sw 0 0 (Existing swap partition)

/extraswap none swap sw 0 0 (New swap file)

Make sure the entry in the fstab file is correct to avoid problem during boot up.

No comments:

Post a Comment