0

I have a few gigabytes of unused space on my hard drive. How can I add this extra space to my swap partition?

2
  • 2
    Why do you want to add it to your swap partition in the first place?
    – pzkpfw
    Jan 27, 2015 at 13:09
  • First it's only 2GBs. Second increasing the swap may help me to run my programs using MATLAB when the whole ram memory is in use.
    – Cypress
    Jan 27, 2015 at 13:29

2 Answers 2

1

Fortunately in my case free space is next to the swap partition. So I do the following steps to resize my swap partition:

  1. Install GParted from Software Center.

  2. Run Gparted and search for your current swap location. It's /dev/sda8 for me.

  3. Open a teminal and type:

     sudo swapoff /dev/sda8
    
  4. 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.

  5. Finally type the following command in the terminal:

     sudo swapon /dev/sda8
    
1
  • 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
    – Anwar
    May 9, 2017 at 19:38
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .