๐Ÿ’พHow to extend a partition

In Linux, you may need to extend a partition after increasing the underlying disk size. This guide will walk you through the steps using the growpart and resize2fs commands to achieve this.

Requirements

  • a VPS

  • an OnetSolutions account

Instructions

Prerequisites

Before you begin, ensure the following:

  1. Backup Data: Always back up your data before making any changes to disk partitions to avoid data loss.

  2. Access: Ensure that you have administrative or root access to the Linux system.

  3. Required Tools: Make sure you have the following tools installed:

    • growpart: Used to resize a partition.

    • resize2fs: Used to resize the filesystem within the partition.

Step 1: Identify the Disk and Partition

  1. Open a terminal.

  2. Use the lsblk command to list the available disks and their partitions:

    lsblk

    Identify the disk and partition you want to extend. Note the device name (e.g., /dev/vda) and partition number (e.g., /dev/vda1).

Step 2: Extend the Partition

  1. Run the growpart command to extend the partition to use all available space on the disk:

    sudo growpart /dev/<device_name> <partition_number>

    Replace <device_name> with the actual device name (e.g., /dev/vda) and <partition_number> with the partition number (e.g., 1).

  2. Verify that the partition has been resized by running the lsblk command again. The partition should now show the increased size.

Step 3: Resize the Filesystem

  1. Run the resize2fs command to resize the filesystem to fill the newly extended partition:

    sudo resize2fs /dev/<device_name><partition_number>

    Replace <device_name> and <partition_number> with the actual device name and partition number from Step 1.

  2. The resize2fs command will automatically adjust the filesystem size to match the partition size.

Step 4: Verify the Changes

  1. To confirm that the partition and filesystem have been successfully extended, you can run the df command to display disk space usage:

    df -h

    Check if the partition in question now shows the increased size.

Congratulations! You have successfully extended a partition after increasing the disk size using the growpart and resize2fs commands. Your system should now have more available storage space.

Remember to carefully follow these steps and back up your data before making any changes to disk partitions to avoid potential data loss.

Last updated