LinuxCommandLibrary

growpart

Increase partition size after disk resize

TLDR

Extend partition n from sdX to fill empty space until end of disk or beginning of next partition

$ growpart [/dev/sdX] [n]
copy

Show what modifications would be made when growing partition n in a disk image
$ growpart [[-N|--dry-run]] /[path/to/disk.img] [n]
copy

SYNOPSIS


growpart [OPTIONS] DEVICE PARTITION_NUMBER

PARAMETERS

DEVICE
    The block device containing the partition (e.g., /dev/sda).

PARTITION_NUMBER
    The numerical identifier of the partition to be expanded (e.g., 1 for /dev/sda1).

-h, --help
    Display a help message and exit.

-v, --version
    Show program's version number and exit.

-N, --dry-run
    Perform a dry run; print what would be done without making actual changes.

-u, --update auto|off
    Control kernel partition table update. 'auto' (default) attempts to update, 'off' does not.

-b, --bytes N
    Limit the expansion to N bytes after the partition's original size.

DESCRIPTION


growpart is a command-line utility used to expand a specified disk partition to occupy all available contiguous free space on the underlying storage device. It is commonly employed in virtualized environments where the disk size of a virtual machine is increased, and the corresponding partition needs to be extended to utilize the newly available capacity. Unlike tools such as fdisk or parted, which require more manual intervention and understanding of disk geometry, growpart simplifies the process by automatically identifying and extending the partition to the largest possible size. It works by modifying the partition table entry for the given partition, typically extending it to the end of the disk. It is crucial to remember that growpart only resizes the partition itself; the filesystem residing within that partition must be resized separately using appropriate tools like resize2fs for ext2/3/4 or xfs_growfs for XFS after the partition has been successfully extended.

CAVEATS


Requires root privileges to execute.
Only resizes the partition entry in the disk's partition table; the filesystem on the partition must be resized separately.
Cannot shrink partitions or move them.
Risk of data loss if operations are interrupted or used incorrectly.

IMPORTANT USAGE NOTE


After successfully using growpart to extend a partition, it is critical to also resize the filesystem located on that partition to utilize the newly available space. For ext2/3/4 filesystems, use resize2fs (e.g., resize2fs /dev/sda1). For XFS filesystems, use xfs_growfs (e.g., xfs_growfs /mnt/mydata). Failing to resize the filesystem will result in the partition being larger, but the filesystem still using only its original capacity.

HISTORY


growpart is often found as part of the cloud-utils or cloud-init packages, which are crucial for automating the initial setup and configuration of cloud instances. Its development was motivated by the common need in virtualized environments to programmatically expand disk partitions after a virtual machine's underlying disk has been increased. It provides a simpler, scriptable alternative to more interactive and complex partitioning tools, streamlining the deployment and scaling of cloud resources.

SEE ALSO

fdisk(8), parted(8), sfdisk(8), resize2fs(8), xfs_growfs(8), lsblk(8)

Copied to clipboard