Expanding Disk Partitions

    Grow your filesystem after resizing a block storage volume

    After resizing a block storage volume in the Cloud Control Panel, the additional space isn't automatically usable. You need to expand the partition and resize the filesystem to utilize the new capacity. This guide covers the process for both standard partitions and LVM configurations.

    What You'll Learn

    Identify your current partition layout
    Rescan the block device to detect new size
    Expand partitions using growpart
    Resize ext4 and XFS filesystems online
    Expand LVM physical and logical volumes

    Important: Always create a backup or snapshot before modifying partitions. While these operations are generally safe, having a backup protects against unexpected issues.

    Prerequisites

    • Block storage volume already resized in the Cloud Control Panel
    • Root or sudo access to the server
    • The cloud-guest-utils package (for growpart)
    • A recent backup or snapshot of your data

    Install the required tools if not already present:

    Ubuntu/Debian
    sudo apt update
    sudo apt install cloud-guest-utils gdisk -y
    AlmaLinux/Rocky Linux
    sudo dnf install cloud-utils-growpart gdisk -y

    Check Current Layout

    First, identify your block device and current partition layout. Block storage volumes are typically named /dev/vdb, /dev/sdb, or similar.

    List Block Devices

    List Devices
    lsblk

    Example output:

    Example Output
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda    252:0    0   50G  0 disk 
    ├─vda1 252:1    0   49G  0 part /
    └─vda2 252:2    0    1G  0 part [SWAP]
    vdb    252:16   0  200G  0 disk 
    └─vdb1 252:17   0  100G  0 part /mnt/storage

    Notice that vdb shows 200G total, but vdb1 is only 100G. This means there's 100G of unallocated space after the resize.

    Check Filesystem Type

    Check Filesystem
    df -Th /mnt/storage

    Example output showing ext4:

    Example Output
    Filesystem     Type  Size  Used Avail Use% Mounted on
    /dev/vdb1      ext4   98G   24G   70G  26% /mnt/storage

    Check Partition Table Type

    Check Partition Table
    sudo fdisk -l /dev/vdb | grep "Disklabel type"

    This shows whether you have GPT or MBR (DOS) partition table. The growpart tool handles both.

    Rescan the Device

    After resizing the volume in the control panel, the kernel may need to rescan the device to detect the new size.

    Rescan Block Device
    # For virtio devices (vdX)
    echo 1 | sudo tee /sys/class/block/vdb/device/rescan
    
    # For SCSI devices (sdX)
    echo 1 | sudo tee /sys/class/block/sdb/device/rescan
    
    # Alternative: rescan all SCSI hosts
    for host in /sys/class/scsi_host/host*/scan; do
      echo "- - -" | sudo tee $host
    done

    Verify the new size is detected:

    Verify New Size
    lsblk /dev/vdb

    Expand the Partition

    Use growpart to expand the partition to use all available space. This can be done online (while the filesystem is mounted).

    Using growpart

    The syntax is growpart DEVICE PARTITION_NUMBER:

    Expand Partition
    # Expand partition 1 on /dev/vdb
    sudo growpart /dev/vdb 1

    Expected output:

    Success Output
    CHANGED: partition=1 start=2048 old: size=209713152 end=209715200 new: size=419428319 end=419430367

    Verify Partition Expansion

    Verify
    lsblk /dev/vdb

    The partition should now show the full size:

    Example Output
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vdb    252:16   0  200G  0 disk 
    └─vdb1 252:17   0  200G  0 part /mnt/storage

    Note: If you see "NOCHANGE: partition 1 is size X", the partition is already using all available space. Ensure the block device resize was successful in the control panel.

    Resize the Filesystem

    After expanding the partition, resize the filesystem to use the new space. The command depends on your filesystem type.

    For ext4 Filesystems

    Use resize2fs to grow ext4 filesystems online:

    Resize ext4
    sudo resize2fs /dev/vdb1

    Expected output:

    Success Output
    resize2fs 1.46.5 (30-Dec-2021)
    Filesystem at /dev/vdb1 is mounted on /mnt/storage; on-line resizing required
    old_desc_blocks = 13, new_desc_blocks = 25
    The filesystem on /dev/vdb1 is now 52428539 (4k) blocks long.

    For XFS Filesystems

    Use xfs_growfs with the mount point:

    Resize XFS
    sudo xfs_growfs /mnt/storage

    Note: XFS can only be grown while mounted. Use the mount point, not the device path.

    Verify Filesystem Size

    Verify Size
    df -h /mnt/storage

    The filesystem should now show the full capacity:

    Example Output
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/vdb1       197G   24G  164G  13% /mnt/storage

    LVM Volume Expansion

    If your block storage uses LVM (Logical Volume Manager), the process involves expanding the physical volume, then the logical volume, and finally the filesystem.

    Step 1: Expand the Partition

    First, expand the partition as shown above:

    Expand Partition
    sudo growpart /dev/vdb 1

    Step 2: Resize the Physical Volume

    Resize PV
    sudo pvresize /dev/vdb1

    Verify the PV size:

    Verify PV
    sudo pvs

    Step 3: Extend the Logical Volume

    Extend the LV to use all available space (replace with your VG and LV names):

    Extend LV
    # Use 100% of free space
    sudo lvextend -l +100%FREE /dev/mapper/vg_data-lv_storage
    
    # Or extend by a specific amount
    sudo lvextend -L +50G /dev/mapper/vg_data-lv_storage

    Step 4: Resize the Filesystem

    Resize Filesystem (ext4)
    sudo resize2fs /dev/mapper/vg_data-lv_storage
    Resize Filesystem (XFS)
    sudo xfs_growfs /mnt/storage

    One-Command LVM Resize

    With recent versions of LVM, you can extend and resize in one command:

    Combined Command
    # For ext4
    sudo lvextend -l +100%FREE --resizefs /dev/mapper/vg_data-lv_storage
    
    # For XFS
    sudo lvextend -l +100%FREE /dev/mapper/vg_data-lv_storage
    sudo xfs_growfs /mnt/storage

    Verification

    After completing the expansion, verify everything is working correctly:

    Verification Commands
    # Check filesystem size
    df -h /mnt/storage
    
    # Check partition layout
    lsblk /dev/vdb
    
    # Check filesystem integrity (optional, for ext4)
    sudo e2fsck -n /dev/vdb1
    
    # For LVM, check all components
    sudo pvs
    sudo vgs
    sudo lvs

    Successful Expansion Checklist

    lsblk shows the partition using the full disk size
    df -h shows increased filesystem capacity
    Data is accessible and intact
    Applications using the storage work normally

    Troubleshooting

    growpart shows NOCHANGE

    The partition is already using all available space, or the kernel hasn't detected the new size.

    • Verify the resize was successful in the Cloud Control Panel
    • Try rescanning the device: echo 1 | sudo tee /sys/class/block/vdb/device/rescan
    • Check lsblk shows the new disk size

    resize2fs: Bad magic number

    You're trying to resize a non-ext filesystem with resize2fs.

    • Check filesystem type: df -Th /mnt/storage
    • For XFS, use xfs_growfs /mnt/storage

    Device is busy

    The device or partition is in use by another process.

    • Check what's using the device: sudo lsof +D /mnt/storage
    • For online resize of ext4/XFS, this is usually not a problem
    • If issues persist, try stopping services using the mount

    GPT backup header issue

    GPT partition tables have a backup header at the end of the disk that needs updating.

    Fix GPT
    # Fix GPT header
    sudo sgdisk -e /dev/vdb
    
    # Then run growpart again
    sudo growpart /dev/vdb 1