Home » Linux » Shell » How to Grow a Linux Partition to Fill a Disk with growpart

How to Grow a Linux Partition to Fill a Disk with growpart

This article will show how to grow a partition on your Linux partition to fill the entire disk using growpart. This is useful if you have resized a virtual machine disk, or moved to a larger disk on your desktop or laptop Linux system.

Resizing Linux Virtual Machine Disks

Most commonly, you’ll be looking to grow your Linux partition to fill the entire disk on a virtual machine after resizing it. Cloud hosts like Amazon AWS and Google Cloud, and virtual machine solutions like VirtualBox and Hyper-V allow you to increase the size of the storage volumes attached to Linux virtual machines, but you still need to expand the file system within them.

Step 1: Listing and Identifying Storage Devices

To expand the filesystem on your resized disk, you’ll need to first locate the disk using the lsblk command, execute it by running:

lsblk 

And you will see output similar to the following listing storage devices and the partitions on them:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0    50G  0 disk 
??sda1   8:1    0     1M  0 part 
??sda2   8:2    0   513M  0 part /boot/efi
??sda3   8:3    0  29.5G  0 part /
sr0     11:0    1  1024M  0 rom  

Above, you can see that disk sda has a size of 50 gigabytes, but that the volume containing the root partition (sda3) is only 29.5 gigabytes – there is unused space on the storage device.

There may be multiple entries in the output from lsblk – you’ll need to identify the disk you have resized by the size and utilization – it should be apparent which disk has unused space. Usually on single-disk machines, the first and only storage device will be named sda.

You will also need to know the name of the partition your wish to grow – in this case sda3 – usually identified by it having the root mount point of /.

Step 2: Installing growpart

growpart is a utility that makes it super easy to grow a partition. It’s part of the cloud-guest-utils package. Note that while this package is intended to work on cloud-hosted virtual machines, the growpart utility also works just fine on physical machines.

On Debian and Ubuntu, run:

sudo apt install cloud-guest-utils

On Arch, run:

pacman install cloud-guest-utils

On RedHat, run:

yum install cloud-utils-growpart -y

Step 3: Grow your Partition

Once growpart is available, growing a partition to use the entire remaining disk space is as simple as running:

sudo growpart /dev/sda 3

You’ll need to specify the correct partition name above, replaceing sda 3 (note the space! the device and partition number are separated when using growpart) if necessary. growpart is executed with no additional parameters – if the size parameter is not specified, it will default to the available size of the partition.

Now that the partition has been expanded, the file system must be also using resize2fs:

sudo resize2fs /dev/sda3

Note that the space has disappeared in the device path again.

You will see output similar to:

resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/sda3 is mounted on /; online resizing required
old_desc_blocks = 4, new_desc_blocks = 7
The filesystem on /dev/sda3 is now 12975355 (4k) blocks long.

Confirming the change. Once this final step is done, reboot:

sudo reboot

And you’re done!

SHARE:
Photo of author
Author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Comment