grow and extend an ext4 partition and filesystem on a live server

Endangered technic.
Photo by Patrick Lindenberg / Unsplash

Before doing anything: backup your data!

A disk contains partition(s). Each partition contains a file system like ext4.

To grow a file system, you have to:

  1. Resize the partition
  2. Resize the filesystem

To shrink:

  1. Resize the filesystem
  2. Resize the partition

The order is important.

Following is an example of:

  • 1 disk: xvdb
  • 1 partition: xvdb1
  • 1 ext4 filesystem

The partition is being resized to take up all the space on the disk and the filesystem to take up all the space on the partition:

# unmount before making any changes to the partition table.
sudo umount /dev/xvdb1
# resize the partition.
sudo parted /dev/xvdb
(parted) resizepart 1 100%
(parted) quit
# resize the filesystem.
sudo resize2fs /dev/xvdb1
mount /dev/xvdb1 /mnt

And now xvdb1 has grown to take all the available disk space.

Show Comments