I need to shrink my / partition and expand my swap partition all one NVMe drive

I have a single NVMe drive with a 2GB swap partition and the rest is a single Btrfs partition (well apart from the standard EFI system partition of 512MB). I want to grow the swap partition to 72GB and in order to do that I need to shrink the root partition. Is this possible to do while the computer is up and running or do I need to boot off a USB stick? And when I am in the correct environment what are the commands I need to write in order to achieve what I want to do?

Thanks for any help.

Just create a swap file of 70GB and use that… it doesn’t need to be a partition…

A quick example for you;

free |grep Swap
Swap:       1971196           0     1971196

fallocate -l 10G /stuff/swapfile

chmod 600 /stuff/swapfile 

mkswap /stuff/swapfile
Setting up swapspace version 1, size = 10 GiB (10737414144 bytes)
no label, UUID=0f382788-7bbb-43af-89b5-07fd78c7bdb4

swapon /stuff/swapfile

swapon --show
NAME            TYPE      SIZE USED PRIO
/dev/sda4       partition 1.9G   0B   -2
/stuff/swapfile file       10G   0B   -3

free |grep Swap
Swap:      12456952           0    12456952

You can enable on the fly, or add to /etc/fstab…

That is a nice example. Thank you. Could I do the opposite then and delete my swap partition and grow the / partition to take up all remaining space on the drive and just have a 72GB swap file stored somewhere? I just want to be able to suspend to RAM at the moment.

Not sure btrfs like expanding, not worth it, just use the file and add to fstab?

OK. Thank you for your help. I’ll do that then.

Yast2 > Partitioner > Select Root Partition > Change Size. You can do this while your computer is up and running. :wink:

How to resize/extend a btrfs formatted root partition