Having a dedicated Swap partition is good but 16 GB of space just for swap is a serious waste of space since most modern systems come with 4 GB of memory so for day to day use, you're very very unlikely to run out of memory.
As Rinzwind mentioned, you don't need more than even 15-20 GB of Ubuntu partition to use it on daily basis. So as you've asked to get more space for currently installed Ubuntu while keeping the swapping intact. Here's what I'd suggest you to do.
What we're gonna do is merge that swap partition back into your Ubuntu partition using following steps.
Firstly, get rid of your Swap partition, follow this link for the same.
Second, merge that unallocated space left out by deleted Swap partition back into Ubuntu partition by resizing it, follow this article.
Now comes the part where we create swap memory without having a dedicated partition.
Open terminal using Ctrl + Alt + T.
Run following command to create swap file by running following command.
sudo dd if=/dev/zero of=/swapfile bs=1M count=512
Notice the value of count
, which denotes the size of your file in MB that you want to use as Swap memory, replace that with appropriate value as per your system memory. You can refer to Ubuntu Official Docs to know how much swap memory is recommended. 2 GB (2048 MB) of swap memory is enough for a machine with 4 GB of RAM.
The parameter of
suggests location and name of swap file, here we create it in /
(which is root) and name it as swapfile
. I suggest you to leave it as it is.
This command will take a few seconds to complete, depending on how much size you set.
Now, format the newly created file as swap memory using following command.
sudo mkswap /swapfile
Once done, you need to tell Ubuntu to mount this file as Swap memory on startup, to do that, run following command.
sudo gedit /etc/fstab
This will open fstab
(File System Table) file in text editor. Add following line at the end of the file. DO NOT CHANGE ANYTHING ELSE IN THIS FILE
/swapfile none swap sw 0 0
Now save the file and close the editor.
Now just restart Ubuntu, and you'll see the Swap memory available in System Monitor.
I understand this is overwhelming for first time user like you but it is worth trying to gain additional storage, so feel free to drop in comments if you're stuck anywhere. :)