In the realm of operating systems, few tasks are as universally daunting yet routinely necessary as disk partition management. Whether a server is running out of space on a critical file system or a workstation needs to reallocate unused capacity from one volume to another, the ability to resize partitions is a cornerstone of system administration. For users of FreeBSD, the native gpart utility serves as the definitive tool for this purpose. Unlike Linux’s more fragmented ecosystem of tools ( fdisk , gdisk , resize2fs , etc.), gpart provides a unified, scriptable, and highly reliable command-line interface for managing partitioning schemes, including the all-important task of resizing. This essay provides a comprehensive exploration of resizing partitions with gpart , covering its underlying concepts, the prerequisites for a safe operation, a step-by-step procedural guide, and common pitfalls. Understanding gpart and Partition Layouts gpart is the primary partition management utility in FreeBSD, designed to handle modern partitioning schemes such as MBR (Master Boot Record) and, more commonly, GPT (GUID Partition Table). Unlike logical volume managers (LVMs) that offer flexible, online resizing, gpart operates directly on the physical or virtual disk’s partition table. This fundamental difference means that resizing with gpart is not as simple as changing a number; it requires careful attention to disk geometry, partition alignment, and the file system contained within the partition.
A key concept is that a partition is merely a defined range of sectors on a disk. Resizing involves either growing the partition into unallocated space immediately following it or shrinking the partition by moving its end boundary inward. The operation is only possible if the adjacent space is free. Moreover, gpart modifies the partition table, but it resize the file system inside the partition. Consequently, any resize operation must be paired with an appropriate file system resize command (e.g., growfs for UFS or zfs online expand for ZFS). Prerequisites and Critical Preparations Before executing any gpart resize command, a prudent administrator must take several preparatory steps. First and foremost is data backup . Although gpart is mature and reliable, an unexpected power loss or kernel panic during a partition table write can corrupt the partition layout, rendering data inaccessible. A full backup or, at minimum, a snapshot of critical data is non-negotiable. gpart resize partition
Second, the administrator must inspect the current partition layout. The command gpart show ada0 (assuming ada0 is the target disk) displays partitions, their indices, start sectors, sizes, and, crucially, any free space. For a successful grow operation, there must be unallocated sectors immediately after the target partition. For a shrink operation, the partition must have enough internal free space within its file system to allow the truncation without data loss. In the realm of operating systems, few tasks