How to expand a disk from the Linux command line

I’ve been frustrated with the number of instructions that involve deleting a partition and then creating a new partition with the same starting block. Totally unnecessary! 

Life has gotten a lot easier thanks to the growpart command. The best part is that with the right filesystem you don’t even need to unmount.  I suggest taking a backup or snapshot first in case something goes wrong.

growpart /dev/device_name partition_number

You can test it first with –dry-run:

growpart --dry-run /dev/sda 3

Once that is done, just run the command for your given filesystem to expand into the rest of the partition.

For btrfs:

btrfs filesystem resize amount mount_point

The amount can be something like +50g or max. To resize the root partition to max simply type:

btrfs filesystem resize max /

For ext4 it is:

resize2fs /dev/device

For example:

resize2fs /dev/sda3

For XFS:

xfs_growfs /mount_point

for example:

xfs_growfs /

Leave a Reply

Your email address will not be published. Required fields are marked *