I have a few gigabytes of unused space on my hard drive. How can I add this extra space to my swap partition?
2 Answers
Fortunately in my case free space is next to the swap partition. So I do the following steps to resize my swap partition:
Install GParted from Software Center.
Run Gparted and search for your current swap location. It's
/dev/sda8
for me.Open a teminal and type:
sudo swapoff /dev/sda8
Resize the swap using Gparted.
Right click on swap-Linux and select Resize/Move. Next determine your new swap size and click Resize/Move. Finally apply the pending operation using Edit menu.
Finally type the following command in the terminal:
sudo swapon /dev/sda8
-
this kind of problem generally very much dependent on the layout of the partitions. It's your luck that the spaces were adjusted otherwise it would be very hard– AnwarMay 9, 2017 at 19:38
I recommend you use gParted, a pretty easy-to-use GUI tool to do partitioning stuff.
If the unpartitioned space is physically directly allocated next to your current swap partition, you can just change its size to also cover the free space. This is easy.
But if there are other partitions between the free space and the old swap, you have to move the partitions in between them. This takes a bit more time and is risky (there is always the danger of losing data when you edit partitions - do a backup first!), but also possible. However, you should avoid moving (bootable) system partitions, as this could get you in trouble at the next restart...
Anyway, about what amount of space are we talking? Having swap partitions bigger than maybe 2x RAM size or 8GB (values guessed by myself!) does not lead to better performance. It will just lay there useless.