Grow and extend an ext4 partition and filesystem

harddisk.jpg
Photo by Patrick Lindenberg on 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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s