Linux – Increase swap space in linux through terminal

linuxswap

While installing Oracle DB in linux machine, I face a problem like swap space is not sufficient. How can I increase the swap space?

Best Answer

In linux there is swap space in partitions or in files. Once the disk is partitioned the easiest way to grow the swap space is creating a swap file in one of your partitions. Type df -h and check which one has free space. Say you find free GB in /home:

First create a file. In this example we add around 1GB of space. Login as root in a terminal.

# dd if=/dev/zero of=/home/swap1 bs=1024 count=1024000

Make this file owned by the root user and allow only root to read and write to it:

# chown root:root /home/swap1
# chmod 0600 /home/swap1

Turn it into a swap file

# mkswap /home/swap1

Try it right now. This activates the new swap space without rebooting:

# swapon /home/swap1

Add it to the fstab file so it works when you reboot. Be carefull with the next command, do not forget there are two >

echo "/home/swap1 none swap sw 0 0" >> /etc/fstab

Check the new space is being used typing this: # swapon --show

Related Question