Linux is unique compared to other operating systems in that you are expected to have at least basic knowledge of the OS command line. You can do almost anything from the command line, and often it can be easier than juggling the GUI.
Among the things you can do with the command line is resize partitions. Detailed information is provided on how to do this.
Preparation
Proper preparation is key
Before making any changes to the disk partitions, you should prepare everything if you want to avoid catastrophic data loss. The absolute first step in any partition resizing operation is to create a comprehensive, verified backup of all critical data on the target drive. Disk operations inherently carry the risk of file system corruption or accidental deletion, so using tools to image the disk or securely copy key files to an external storage medium is out of the question.
After backups are secured, administrators should evaluate the current disk structure using command-line utilities. The lsblk command provides a clear hierarchical view of all attached block devices and their respective partitions, allowing you to define specific drive and partition assignments, e.g. /dev/sda1 or /dev/nvme0n1p2. In addition, commands such as df -h and fdisk -l provides important information about file system usage, sector sizes, and the exact start and end boundaries of existing partitions.
To successfully extend a partition, there must be unallocated space on the physical disk immediately adjacent to the partition you want to extend. If the unallocated space is located at the beginning of the drive or is separated by another active partition, standard expansion methods will not work without transferring the data, which is a significantly more complicated and risky procedure. Additionally, administrators should determine the type of file system currently formatted on the partition, such as ext4 or XFS, as this dictates the specific tools required for the final resizing step. Although modern Linux kernels often support online resizing for ext4 and XFS filesystems while they are actively mounted and in use, shrinking operations or structural changes to the partition table itself may require removing a drive or booting from live USB media to provide exclusive access to the storage device.
Standard (non-LVM) partition expansion
For most users
Extending a standard, non-LVM partition involves a strict two-step process: modifying the partition table to recognize the larger physical space, and then instructing the file system to expand to that newly allocated boundary.
The first step requires changing the partition boundary using a tool like this fdisk or parted. A common, albeit intimidating, method of use fdisk involves deleting the existing partition record and immediately recreating it. During this rest process, it is absolutely essential that the new partition starts in the same starting sector as the original; failure to match the boot sector will result in immediate data loss and a destroyed file system.
Using fdisk is relatively simple:
-
Run away
sudo fdisk /dev/sda. -
Kind
pto print the partition table and mark the start sector of the partition you want to resize. -
Kind
dto delete a section, then the section number (eg1). This deletes only the partition entry in the partition table, not the data. -
Kind
nto create a new partition. Use the same start sector as mentioned earlier and accept the default end sector to use all available free space. -
Kind
wto save changes to disk and exit. -
You may need to reboot the system for the kernel to recognize changes to the partition table:
sudo reboot.
The end sector is then expanded to include the adjacent unpartitioned space. Alternatively, growpart utility offers a safer, more streamlined approach by automatically rewriting the partition table to extend the specified partition into available contiguous space without requiring manual deletion and rebuilding of sector boundaries.
After the base partition table is updated to reflect the increased size, the operating system must be notified of the hardware change. Running partprobe command forces the kernel to reread the partition tables, allowing it to recognize new block device sizes without requiring a system reboot. The second stage addresses the file system itself, which is still unaware of the additional space and retains the original size limits. For standard ext2, ext3 or ext4 file systems resize2fs the command is executed against the target partition block device. This utility expands file system structures to completely fill the newly expanded partition. If the partition uses the XFS file system, xfs_growfs Instead, a command is used that requires the partition to be mounted and takes the mount point directory as an argument rather than the device path.
Expandable with LVM
You can also do this with your server
Logical Volume Manager offers a highly flexible abstraction layer over physical memory, which makes the expansion process significantly more dynamic than working with standard partitions.
The LVM architecture is built on three main components: Physical Volumes, which map to actual storage devices, Volume Groups, which combine the storage of one or more Physical Volumes, and Logical Volumes, which are end-use partitions carved out of a Volume Group. To expand an LVM installation, an administrator first needs available raw storage. This can be achieved by adding an entirely new hard drive to the system or using unallocated space on an existing drive.
The new storage area must first be initialized as a Physical Volume pvcreate command. This step prepares the raw disk or partition by writing the LVM metadata and tells the LVM subsystem that the device is ready to access the available storage pool.
After the Physical Volume is enabled, the next step is to expand the overall Volume Group. The vgextend command is used to add the newly created Physical Volume to the desired Volume Group. This immediately increases the total pool of available, unallocated storage blocks within that particular Volume Group. When a Volume Group is successfully extended, the administrator can now allocate this fresh space to a specific Logical Volume.
The lvextend command is responsible for increasing the size of the Logical Volume itself. The main advantage of this LVM process is the ability to use it -r or --resizefs flag directly inside lvextend command. This integrated flag automatically detects the underlying file system, whether ext4 or XFS, and seamlessly executes the appropriate file system resizing utility in tandem with the volume extension. This eliminates the need to execute separate commands such as resize2fs or xfs_growfs by hand.
Command lines can be intimidating, especially when you’re dealing with something as complex as partitioning. I hope that makes it a little easier.




