How do I reduce the size of swap after accidentally enlarging it by 100GB? I imagine it would be via fdisk somehow. Do I need to delete the partition and remake it?

  • Are you using LVM? – user1700494 Aug 15 '16 at 12:35
  • @user1700494 yes – rafvasq Aug 15 '16 at 12:50
  • add output of pvdisplay, vgdisplay, lvscan to your post – user1700494 Aug 15 '16 at 12:54

Use gparted, it's easy to use! You just need to find your swap partition (/dev/sda4 on my system as you can see in the screenshot below) and then resize it.

enter image description here

However, unless your swap artition is the last partition on the disk, this will leave unallocated space in the middle. Depending on how your partitions are set up, you may or may not be ab;e to add that to one of the other partitions. For more details, please edit your question and show us the output of sudo parted -l or a screenshot like the one above.

You can find a step by step howto on using gparted to reassign and move unallocated space here.

|improve this answer|||||

As you use LVM, the easiest (and safest) way is to simply lvcreate new swap partition with size you want, mkswap and swapon it, and then 'lvremove' old oversized partition. That sequence insures you won't run out of virtual memory in the middle of process, and leaves you just with partition of wanted size. Do not forget to update /etc/fstab.

If you're flat out of disk space though, you will need to swapoff and lvremove first (or use temporary swap file if you do not have enough physical memory)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.