How to modify the size of Swap Space in Linux Operating System

Login through root user.

To start off, see how much swap space you already have. At a command line, type swapon –s.

I was already done this process that’s way you can see that swap mount point shows /extraswap. First time when you do this process your swap mount point shows links this.

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

All the said process was done on Virtual Machine.

The numbers under "Size" and "Used" are in kilobytes.

Run df -h (short for "disk free") from a command line to see from which partition we should use the space for swap space.

Under the "Available" column we have approximately 16GB of free space on our root partition. Let's steal 512MB of that for our swap file. You might want more or less, depending on your memory needs, how much swap space you already have available, and how much free disk space you have. The general rule of thumb for swap size is that your total available swap space should be around double your RAM size.

NOTE: Back up your important data before proceeding. If you carefully follow the steps below you should be fine, but it's always better to be safe.

In order to create our supplementary swap file, we're going to use the dd (data dump) command. Carefully do this process.

Replacing 512 with the number of megabytes you want in your 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.

Now we have a file the size we want on disk, and we can prepare it for use as a swap partition. We'll use the mkswap command to make our file swap consumable for the Linux kernel. Again as root, carefully type.

To turn on our swap file, we run swapon /extswap. Now when we run 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.

But we're still not done yet. If we reboot our machine now, our new swapfile won't be active, and we'll have to run swapon /extswap again. In order to make things more permanent, we'll need to edit our /etc/fstab file.

First, make a copy of the file.

Now open /etc/fstab in your in vi editor and find a line about your swapfile that looks something like this:
/dev/hda2    none   swap   sw   0   0

Replace the first column with the location of your new swap file.

Save the file and reboot the system.

Now have more swap space than you did before.


Popular posts from this blog

Create Tables in Oracle Database using TOAD

How to create Oracle stored Procedures using TOAD for Oracle

How to Create Packages in Oracle Database using TOAD for Oracle