Online Extending Partitions and File Systems

Last updated: 2021-06-24 16:39:50

    Overview

    Expanding a data disk via the console only increases its storage space. You need to extend the partition or file system of the cloud disk to the larger size. This document describes how to extend partitions and file systems online.

    Prerequisites

    • Before extending partition or file system, create a snapshot of the cloud disk to back up data. For more information, see Creating Snapshots.
      This practice helps you roll back snapshot to recover data in case of data loss due to misoperation.
    • The cloud disk has been expanded and mounted to a CVM via the console. For more information, see Expanding Cloud Disk Capacity.
    • The Linux CVM kernel should be version 3.6.0 or later. You can use the uname -a command to check the kernel version.
      If the kernel version is earlier than 3.6.0, refer to Extending Partitions and File Systems (Linux).

    Operating Environment

    ResourceDescription
    Operating system CentOS 8.0 64-bit
    Cloud disk (data disk)
    • /dev/vdb: uses the MBR partition and the EXT4 file system, and expands from 50 GB to 60 GB via the console.
    • /dev/vdc: uses the GPT partition and the XFS file system, and expands from 50 GB to 60 GB via the console.

    Directions

    Viewing partitions of the cloud disk

    1. Log in to a Linux instance using standard login method.
    2. Run the following command to query partitions of the cloud disk.
      fdisk -l
      
      The following information will appear:

      As shown in the figure,
      • The 60 GB /dev/vdb data disk contains a 50 GB MBR partition /dev/vdb1.
      • The 60 GB /dev/vdc data disk contains a 50 GB GPT partition /dev/vdc1.
    3. Run the following command to determine the file system type of existing partitions.
      df -TH
      
      The following information will appear:

      As shown in the figure,
      • The /dev/vdb1 partition is on an EXT4 file system that has been mounted to /mnt/disk1.
      • The /dev/vdc1 partition is on an EXT4 file system that has been mounted to /mnt/disk2.

    Extending a partition

    1. Use the command as needed to install the gdisk tool.
      • For a MBR partition, skip this step.
      • For a GPT partition, run the following command according to the operating system of the CVM.

    yum install gdisk -y
    

    2. Run the following command to install the growpart tool according to the operating system of the CVM.

    yum install -y cloud-utils-growpart
    

    1. Run the following command to extend partitions using growpart.
      Take extending the /dev/vdb1 partition as an example. Note that there is a space between /dev/vdb and 1 in the command. Replace with your actual values.
      growpart /dev/vdb 1
      
      If information similar to what is shown below is returned, the partition has been extended.

    Extending a file system

    1. Use the file system-specific command to resize a file system based on the type obtained in step.

      Run the following command to extend the EXT file system.

      resize2fs /dev/vdb1 
      

      The following information will appear:

    2. Run the following command to view the result.

      df -TH
      

      If information similar to what is shown below is returned, the file system has been extended.

    3. Check data integrity and CVM running status after expansion.
      You can roll back the snapshot to recover data in case of exceptions. For more information, see Rolling Back Snapshots.