LinuxCommandLibrary

resizepart

Resize a partition

SYNOPSIS

parted [OPTIONS] DEVICE resizepart NUMBER [END]

PARAMETERS

DEVICE
    The path to the disk device (e.g., /dev/sda, /dev/nvme0n1) on which the partition resides. This is an argument to the main parted command.

NUMBER
    The minor number (or index) of the partition to be resized on the specified DEVICE. You can typically see this number when listing partitions (e.g., using parted print).

[END]
    Optional. The new end position of the partition. This value can be expressed in bytes or units specified by parted's 'unit' command (e.g., 'MB', 'GB'). If omitted, parted will automatically resize the partition to its maximum possible extent, utilizing all available contiguous free space.

DESCRIPTION

resizepart is a subcommand of the parted utility, used for managing disk partitions. It allows you to resize an existing partition on a specified disk device. Unlike older tools like fdisk, parted (and thus resizepart) can resize partitions non-interactively and is capable of handling both MBR and GPT partition tables.

The primary function of resizepart is to adjust the size of a partition entry in the disk's partition table. When used without a specific end position, it expands the partition to occupy the maximum available contiguous unallocated space. If an end position is specified, it attempts to resize the partition to that exact boundary. It is critical to understand that resizepart only modifies the partition table entry; it does not resize the filesystem residing within the partition. Therefore, proper filesystem resizing (e.g., using resize2fs for ext4) is a separate, often crucial, step that must be performed before (for shrinking) or after (for growing) using resizepart to prevent data loss.

CAVEATS

Data Loss Risk: Resizing partitions is a high-risk operation. Always back up important data before attempting to resize partitions. Incorrect use can lead to permanent data loss.

Filesystem Consistency: resizepart only modifies the partition entry in the disk's partition table. It does not resize the filesystem contained within the partition.

  • If shrinking a partition, you must shrink the filesystem before shrinking the partition to avoid data corruption.
  • If growing a partition, you must grow the filesystem after the partition has been expanded to utilize the newly allocated space.

Mounted Filesystems: You generally cannot resize a partition that is currently mounted. Always unmount the partition (and its filesystem) before attempting to resize it.

Contiguous Space: To grow a partition, there must be contiguous unallocated space immediately adjacent to the partition you are resizing. resizepart typically expands to the right (higher addresses).

LVM/RAID/Cryptsetup: For partitions used in Logical Volume Management (LVM), RAID arrays, or encrypted volumes (e.g., LUKS), dedicated tools like pvresize, lvresize, or cryptsetup resize should be used in conjunction with (or sometimes instead of) parted to ensure proper resizing of the underlying structures.

TYPICAL USAGE WORKFLOW

A common sequence for safely growing a partition:
1. Unmount the filesystem: umount /dev/sdxY
2. Expand the partition: parted /dev/sdx resizepart Y (where Y is the partition number, letting it expand to max)
3. Run filesystem check: e2fsck -f /dev/sdxY (for ext2/3/4 filesystems)
4. Expand the filesystem: resize2fs /dev/sdxY (for ext2/3/4). For XFS, use xfs_growfs /mount/point.
5. Mount the filesystem: mount /dev/sdxY /mount/point

UNITS AND DISPLAY

parted works with various units for specifying positions and sizes. By default, it might display sizes in bytes or a dynamically chosen unit. You can explicitly set units using the unit command within the parted interactive prompt, or by adding unit before resizepart in a non-interactive command, e.g., parted /dev/sda unit GB resizepart 1 10GB. This allows for more human-readable and precise control over partition boundaries.

HISTORY

parted (GNU Parted) was originally created by Andrew Clausen in 1998 with the goal of providing a powerful, flexible, and non-interactive partition editor. This was a significant advancement over older tools like fdisk which were primarily interactive and lacked support for modern partitioning schemes or on-the-fly resizing. The resizepart subcommand has been a fundamental component of parted since its early versions, embodying the utility's core capability to modify partition sizes directly without requiring a system reboot, making it invaluable for system administrators and scripting automated disk management tasks.

SEE ALSO

Copied to clipboard