How to shrink swap on BTRFS?

Hello lovely Endeavour community,

I’m wondering if someone can help guide me with shrinking the size of my swap partition?

I am much more comfortable with ext4 file systems but decided to be daring and try something new with btrfs. Might be in over my head. :new_moon_with_face:

I’ve been reading previous posts here and on the Arch Wiki; finding a lot about creating a swap file & swap partition, but have not come across any definitive solution for just shrinking the swap I accidentally made way too big.

Any assistance or suggestions for further reading are greatly appreciated!

Some info that might be helpful:

  • I don’t ever use hibernate
  • I have never used the full capacity of RAM
  • I don’t really run any RAM-hungry programs

File system info:

[saturn@deepthought ~]$ lsblk -a
sda      8:0    0 931.5G  0 disk 
├─sda1   8:1    0   300M  0 part /boot/efi
├─sda2   8:2    0   897G  0 part /var/log
│                                /var/cache
│                                /home
│                                /
└─sda3   8:3    0  34.2G  0 part [SWAP]
[saturn@deepthought ~]$ sudo btrfs subvolume list /
ID 256 gen 668869 top level 5 path @
ID 257 gen 668870 top level 5 path @home
ID 258 gen 668813 top level 5 path @cache
ID 259 gen 668870 top level 5 path @log
ID 260 gen 26 top level 256 path var/lib/portables
ID 261 gen 27 top level 256 path var/lib/machines
[saturn@deepthought ~]$ sudo fdisk -l
Disk /dev/sda: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: Samsung SSD 870 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 85831B9A-5884-CD42-AC13-D953579443E7

Device          Start        End    Sectors  Size Type
/dev/sda1        4096     618495     614400  300M EFI System
/dev/sda2      618496 1881805571 1881187076  897G Linux filesystem
/dev/sda3  1881805572 1953520064   71714493 34.2G Linux swap

Let me know if any other details are required. And thanks in advance!!

You could use a partition manager like Gparted.

  • Launch the application.
  • Right click on the swap partition and choose “swapoff” from the menu.
  • Right click again on the partition and choose “resize”. Resize the partition to the desired size.
  • Now right click on the BTRFS partition and resize it to the right to fill up the empty space.
  • Apply the changes from the menu bar.
  • Right click on the swap partition and choose “swapon”.

Hope this helps!


Yes, that is immensely helpful!

I was hoping it would be this easy and was tempted to try it with Gparted but was not feeling confident about doing it with btrfs.

There should be no space in between the BTRFS partition and the start of swap, correct?

Thanks a million!

1 Like

You are welcome! Glad you got it resolved!
It could have been a bit more involved if you had chosen a swapfile instead of a swap partition.

Normally when you resize the partition all the way, to the right in this case, there shouldn’t be any empty space left.

However, I think I have seen sometimes a tiny unalloacated space of 1 mb or so to be inserted in between. If I am not mistaken, it may have something to do with partition alignment or some such. I might be wrong though.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.