How to Allocate More Space to Swap and Increase its Size Greater than Ram?

You just want to increase the swap size on your system using the space from sda2. Your sda2

/dev/sda2       104G   74G   25G  75%  / 

You can add additional swap space to your system by using swap file created on / that will utilize your sda2. Just do:

dd if=/dev/zero of=/swapfile bs=20480 count=1M

and then do:

sudo mkswap /swapfile  
sudo swapon /swapfile 

and check, you swap space will increase by that amount using free -m

and yes , to enable it at boot time add the entry in /etc/fstab

 /swapfile     none     swap     sw     0     0

  1. Memory management

    • To display swap usage summary by your device:

      $ swapon -s
      
    • To displays the amount of your free and used physical and swap memory:

      $ free -h
      
    • To preallocate space to /swapfile, you can use the line below:

      $ fallocate -l 20G /swapfile
      % OR
      $ dd if=/dev/zero of=/swapfile bs=20480 count=1M
      
  2. Change permission and create/activate swap

    $ chmod 600 /swapfile
    
    $ mkswap /swapfile
    
    $ swapon /swapfile
    

    You can also improve your file security by changing your file attributes using chattr. I recommend you read its manual page, or read this guide on Tecmint website.

  3. Verify it is enabled by viewing the output of the command cat /proc/swaps, use free command, or

    $ swapon -s
    
  4. To enable it at boot time, edit /etc/fstab (static information about the file system) to include the following where the fields are fs_spec, fs_file, fs_vfstype, fs_mntops, fs_freq and fs_passno, about which you can read by man 5 fstab:

    $ vi /etc/fstab
    
    /swapfile     none     swap     defaults,discard     0     0
    
    • In the fourt parameter fs_mntops, do not use just sw when swapping to an SSD but defaults,discard such that the memory blocks are trimmed each time at startup, see the answer here about How to Do Error-trapping and Swapoff if Error/Warning? The discard option definitely works on partitions.

You question, "How to Allocate More Space to Swap and Increase its Size Greater than Ram?", does not say anything about changing the way your system is set up.

Your fdisk and free output tells us:

  • You have a a partition (/dev/sda3) dedicated to swap. If you just resize that partition you should not need to change anything in your system to use the extra space. (/etc/fstab).
  • You have a partition (/dev/sda2) that has the OS on it. This partition has 26G free space. If you shrink this partition by 20G the OS will have 5G left to grow and use.

The swap partition is not a extended partition, this makes it a little bit easier to increase the size.

Tools required:

  • Bootable OS with gparted

Look here for one location of the last free version of Parted Magic

Instruction for resizing partitions with gparted

  1. boot into another OS that has gparted tool
  2. In gparted; resize OS partition (/dev/sda2). Shrink by amount to donate to swap space. This could take a lot of time because all of the data that is in the space being freed up will need to be moved by gparted.
  3. In gparted; resize swap partition (/dev/sda3). Move and extend to include all free space.
  4. reboot into sda2 OS.
  5. verify swap partition (/dev/sda3) is being used.

Remember that you are changing you disk and partitions on a low level and that any errors or crashes could damage you data.

Backup you data first.