• Elastic Volume Service

evs
  1. Help Center
  2. Elastic Volume Service
  3. User Guide
  4. Management
  5. Expanding the Capacity of an EVS Disk
  6. Performing Post-Expansion Operations for a Linux EVS Disk (parted)

Performing Post-Expansion Operations for a Linux EVS Disk (parted)

Scenarios

In a Linux OS, after the capacity expansion succeeded, the additional disk space needs to be allocated to an existing partition or a new partition.

This topic uses EulerOS 2.0 64bit to describe how to allocate the additional EVS disk space to a partition using parted.

The method for allocating the additional space varies depending on the server OS. This document is used for reference only. For the detailed operations and differences, see the corresponding OS documents.

Based on your service requirements and actual disk condition, you can choose either of the following ways to allocate the additional disk space:
  • Create a new partition (services will not be interrupted)

    Creating a new partition for the expanded disk does not require the original partitions to be unmounted. Therefore, the impacts on services are minor than expanding an existing partition. This method is recommended for system disks or disks carrying services that cannot be interrupted.

    If the MBR partition style is used, the disk capacity cannot exceed 2 TB and the number of partitions cannot exceed the upper limit after the expansion completes.

  • Expand an existing partition (services will be interrupted)

    If the MBR partition style is used and the number of partitions has reached the upper limit, the existing partition needs to be expanded. Expanding an existing partition does not delete its data, but requires the partition to unmount. Therefore, services will be interrupted.

    If the MBR partition style is used and the disk capacity after expansion has exceeded 2 TB, the space exceeding 2 TB cannot be used. To use the excessive space, the disk partition style must be changed from MBR to GPT. Data on the disk will be cleared during such a change. Therefore, back up the disk data before changing the partition style.

    Performing the expansion operations with caution. Misoperation may lead to data loss or exceptions. Therefore, you are advised to back up the disk data using backups or snapshots before expansion. For details about backups and snapshots, see Managing EVS Backup and Creating a Snapshot, respectively.

Prerequisites

  • You have logged in to the server.
    • For how to log in to an ECS, see the Elastic Cloud Server User Guide.
    • For how to log in to a BMS, see the Bare Metal Server User Guide.
  • You have attached the EVS disk to the server, and the additional space has not been allocated.

Viewing the Partition Style

Before allocating the additional space, query the current disk partition style. If MBR is used, you can use either the fdisk or parted partitioning tool. If GPT is used, only the parted partitioning tool can be used.

  1. Run the following command to view the disk information:

    lsblk

    Information similar to the following is displayed:
    [root@ecs-1120 linux]# lsblk
    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    xvda    202:0    0   40G  0 disk 
    └─xvda1 202:1    0   40G  0 part /
    xvdb    202:16   0  150G  0 disk 
    ├─xvdb1 202:17   0  100G  0 part /mnt/sdc
    └─xvdb2 202:18   0   50G  0 part /mnt/opt
    xvdc    202:32   0   40G  0 disk 
    ├─xvdc1 202:33   0    8G  0 part 
    └─xvdc2 202:34   0   32G  0 part 

  2. Run the following command and enter p to view the current disk partition style:

    parted Disk

    For example, run the following command to view the partition style of the /dev/xvdb disk:

    parted /dev/xvdb

    Information similar to the following is displayed:
    root@ecs-1120 linux]# parted /dev/xvdb
    GNU Parted 3.1
    Using /dev/xvdb
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) p                                                                
    Model: Xen Virtual Block Device (xvd)
    Disk /dev/xvdb: 161GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End    Size    File system  Name  Flags
     1      17.4kB  107GB  107GB   ext4         opt
     2      107GB   161GB  53.7GB  ext4         opt1

    In the command output, parameter Partition Table indicates the disk partition style. Value msdos indicates the MBR partition style, and value gpt indicates the GPT partition style.

  3. Enter q and press Enter to exit parted.
  4. Check the disk partition style of other disks. For details, see 2 to 3.

Creating a New Partition

The following example shows you how to make use of the additional capacity of a system disk by creating a new partition and mount the partition on /opt without interrupting services.

  1. Run the following command to view the disk partition information:

    lsblk

    Information similar to the following is displayed:
    [root@ecs-1120 linux]# lsblk
    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    xvda    202:0    0   80G  0 disk 
    └─xvda1 202:1    0   40G  0 part /
    xvdb    202:16   0  250G  0 disk 
    ├─xvdb1 202:17   0  100G  0 part 
    └─xvdb2 202:18   0   50G  0 part 
    xvdc    202:32   0   40G  0 disk 
    ├─xvdc1 202:33   0    8G  0 part 
    └─xvdc2 202:34   0   32G  0 part  

    In the command output, the capacity of the dev/xvda system disk is 80 GB, in which the in-use dev/xvda1 partition takes 40 GB and the additional 40 GB has not been allocated.

  2. Run the following command to enter parted to allocate the additional space of the system disk to a partition:

    parted System disk

    In this example, /dev/xvda is the system disk.

    parted /dev/xvda

    Information similar to the following is displayed:

    [root@ecs-1120 linux]# parted /dev/xvda
    GNU Parted 3.1
    Using /dev/xvda
    Welcome to GNU Parted! Type 'help' to view a list of commands.

  3. Enter unit s and press Enter to set the measurement unit of the disk to sector numbers.
  4. Enter p and press Enter to view the current disk partition style.

    Information similar to the following is displayed:

    (parted) unit s                                                   
    (parted) p                                                        
    Model: Xen Virtual Block Device (xvd)
    Disk /dev/xvda: 167772160s
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags: 
    
    Number  Start  End        Size       Type     File system  Flags
     1      2048s  83886079s  83884032s  primary  ext4

  5. Enter mkpart and press Enter to create a new partition.
  6. In this example, a primary partition is created. Therefore, enter p and press Enter to create a primary partition.

    Information similar to the following is displayed:

    (parted) mkpart
    Partition type?  primary/extended? p
    File system type?  [ext2]? ext4                                   
    Start? 83886080
    End? 1677722159         

  7. Set the file system type and the size of the new partition.

    Value 83886080 indicates the first sector of the dev/xvda2 partition you created, and value 167772159 indicates the last sector. The two values are used for reference only. You can determine the number of partitions and partition sizes based on your service requirements.

    Information similar to the following is displayed:

    (parted) mkpart
    Partition type?  primary/extended? p
    File system type?  [ext2]? ext4                                   
    Start? 83886080
    End? 1677722159         
    NOTE:

    The file system type may fail to set in this step. Therefore, reconfigure the file system type according to 10 after the partition is created.

    The maximum sector value can be obtained in either of the following ways:

    • Run the fdisk -l command and take note of the value.
    • Enter -1s, and the value displayed is the desired value.

  8. Enter p and press Enter to view the created partition.

    Information similar to the following is displayed:
    (parted) p                                                        
    Model: Xen Virtual Block Device (xvd)
    Disk /dev/xvda: 167772160s
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags: 
    
    Number  Start      End         Size       Type     File system  Flags
     1      2048s      83886079s   83884032s  primary  ext4
     2      83886080s  167772159s  83886080s  primary

    The dev/xvda2 partition is created.

  9. Enter q and press Enter to exit parted.
  10. Run the following command to create a file system on the newly created partition:

    In this example, the ext4 file system is created.

    mkfs -t ext4 /dev/xvda2

    NOTE:

    The operation for setting the xfs file system is the same as that for setting the ext3 or ext4 file system. The command is mkfs -t xfs /dev/xvda2.

    Information similar to the following is displayed:

    [[root@ecs-1120 linux]# mkfs -t ext4 /dev/xvda2
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    2621440 inodes, 10485760 blocks
    524288 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2157969408
    320 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
    ?32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    ?4096000, 7962624
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   
    

    The formatting takes a while, and you need to observe the system running status. Once done is displayed in the command output, the formatting is complete.

  11. Run the following command to mount the new partition on a space-demanding directory, for example /opt:

    mount /dev/xvda6 /opt

    Information similar to the following is displayed:

    [root@ecs-1120 linux]# mount /dev/xvda2 /opt
    [root@ecs-1120 linux]# 
    NOTE:

    If the new partition is mounted on a directory that is not empty, the subdirectories and files in the directory will be hidden. Therefore, you are advised to mount the new partition on an empty directory or a newly created directory. If the new partition must be mounted on a directory that is not empty, move the subdirectories and files in this directory to another directory temporarily. After the partition is successfully mounted, move the subdirectories and files back.

  12. Run the following command to view the mount result:

    df -TH

    Information similar to the following is displayed:

    [root@ecs-1120 linux]# df -TH
    Filesystem     Type      Size  Used Avail Use% Mounted on
    /dev/xvda1     ext4       43G  8.3G   33G  21% /
    devtmpfs       devtmpfs  885M     0  885M   0% /dev
    tmpfs          tmpfs     894M     0  894M   0% /dev/shm
    tmpfs          tmpfs     894M   18M  877M   2% /run
    tmpfs          tmpfs     894M     0  894M   0% /sys/fs/cgroup
    tmpfs          tmpfs     179M     0  179M   0% /run/user/2000
    tmpfs          tmpfs     179M     0  179M   0% /run/user/0
    tmpfs          tmpfs     179M     0  179M   0% /run/user/1001
    /dev/xvda2     ext4       43G   51M   40G   1% /opt

Expanding an Existing Partition

The following example shows you how to make use of the additional capacity of a disk attached to a server by recreating the /dev/xvdc1 partition mounted on /mnt/sdc. Because the /dev/xvdc disk only has one partition, this partition can be regarded as the partition at the disk end. During the partition recreation, services will be interrupted.

After the disk capacity has been expanded, the additional space is added to the end of the disk. When the disk has multiple partitions, only the partition at the end of the disk can be expanded.

  1. Run the following command to view the disk partition information:

    lsblk

    Information similar to the following is displayed:
    [root@ecs-1120 sdc]# lsblk
    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    xvda    202:0    0   80G  0 disk 
    ├─xvda1 202:1    0   40G  0 part /
    └─xvda2 202:2    0   40G  0 part /opt
    xvdb    202:16   0  350G  0 disk 
    ├─xvdb1 202:17   0  100G  0 part 
    └─xvdb2 202:18   0  200G  0 part
    xvdc    202:32   0   60G  0 disk 
    └─xvdc1 202:33   0    10G  0 part /mnt/sdc

    In the command output, the total capacity of the /dev/xvdc disk is 60 GB, in which the existing partition takes 10 GB. The /dev/xvdc1 partition is at the end of the disk and has been mounted on /mnt/sdc.

    View the /dev/xvdc capacity and check whether the additional space is included.

  2. Run the following command to unmount the disk partition:

    umount /mnt/sdc

  3. Run the following command to view the unmount result:

    lsblk

    Information similar to the following is displayed:
    [root@ecs-1120 linux]# umount /mnt/sdc
    [root@ecs-1120 linux]# lsblk
    NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    xvda    202:0    0   80G  0 disk 
    ├─xvda1 202:1    0   40G  0 part /
    └─xvda2 202:2    0   40G  0 part /opt
    xvdb    202:16   0  350G  0 disk 
    ├─xvdb1 202:17   0  100G  0 part 
    └─xvdb2 202:18   0  200G  0 part
    xvdc    202:32   0   60G  0 disk 
    └─xvdc1 202:33   0    10G  0 part

  4. Run the following command to enter parted to allocate the additional space of the data disk to a partition:

    parted Data disk

    In this example, /dev/xvdc is the data disk.

    parted /dev/xvdc

    Information similar to the following is displayed:
    [root@ecs-1120 linux]# parted /dev/xvdc
    GNU Parted 3.1
    Using /dev/xvdc
    Welcome to GNU Parted! Type 'help' to view a list of commands.

  5. Enter unit s and press Enter to set the measurement unit of the disk to sector numbers.
  6. Enter p and press Enter to view the current disk partition style.

    Information similar to the following is displayed:
    (parted) unit s                                                   
    (parted) p                                                        
    Error: The backup GPT table is not at the end of the disk, as it should be.  
    This might mean that another operating system believes the disk is smaller.  
    Fix, by moving the backup to the end (and removing the old backup)?
    Fix/Ignore/Cancel? Fix                                                    
    Warning: Not all of the space available to /dev/xvdb appears to be used, 
    you can fix the GPT to use all of the space (an extra 104857600 blocks) 
    or continue with the current setting? 
    Fix/Ignore? Fix                                                           
    Model: Xen Virtual Block Device (xvd)
    Disk /dev/xvdc: 125829120s
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start       End         Size        File system  Name  Flags
     1      2048s       20969471s  20967424s    ext4         opt

    If the preceding information is displayed, enter Fix to rectify the disk exception. Then take note of the first and last sectors of the /dev/xvdc1 partition. These values will be used during the partition recreation. In this example, the partition's first sector is 2048, and its last sector is 20969471.

  7. The /dev/xvdc1 partition number is 1. Therefore, enter rm 1 and press Enter to delete the partition.
  8. Enter p and press Enter to check whether the /dev/xvdc1 partition has been deleted.

    Information similar to the following is displayed:
    (parted) rm 1
    (parted) p                                                                
    Model: Xen Virtual Block Device (xvd)
    Disk /dev/xvdc: 125829120s
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start  End         Size        File system  Name  Flags

  9. Enter mkpart opt 2048s 125829119 and press Enter to recreate the partition.

    2048 specifies the first sector recorded in 6, and 125829119 specifies the last sector, which must be greater than or equal to the last sector recorded in 6.

    Information similar to the following is displayed:
    (parted) mkpart opt 2048s 125829119s
    Warning: You requested a partition from 2048s to 125829199s (sectors 2048..125829199).
    The closest location we can manage is 2048s to 125829036s (sectors 2048..125829036).
    Is this still acceptable to you?
    Yes/No? Yes

    Enter Yes as prompted to set the last sector.

    If the following warning message is displayed, enter Ignore to ignore the performance warning. The warning message will not be displayed if the first sector with the best disk performance has been entered. In this example, 2048s is one of such first sectors. Therefore, the system does not display the warning message.
    Warning: The resulting partition is not properly aligned for best performance.
    Ignore/Cancel? Ignore  
    NOTE:
    Data will be lost if the following operations are performed:
    • Select a first sector other than the partition had before.
    • Select a last sector smaller than the partition had before.

  10. Enter p and press Enter to check whether the /dev/xvdc1 partition has been recreated.

    Information similar to the following is displayed:
    (parted) p                                                                
    Model: Xen Virtual Block Device (xvd)
    Disk /dev/xvdb: 125829120s
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start       End         Size        File system  Name  Flags
     1      2048s       125829086s  125827039s  ext4         opt

    The /dev/xvdc1 partition has been recreated.

  11. Enter q and press Enter to exit parted.
  12. Perform the following operations based on the file system of the disk:

    • For the ext3 or ext4 file system
      1. Run the following command to check the correctness of the file system on /dev/xvdc1:

        e2fsck -f /dev/xvdc1

        Information similar to the following is displayed:
        [root@ecs-1120 linux]# e2fsck -f /dev/xvdb2
        e2fsck 1.42.9 (28-Dec-2013)
        Pass 1: Checking inodes, blocks, and sizes
        Pass 2: Checking directory structure
        Pass 3: Checking directory connectivity
        Pass 4: Checking reference counts
        Pass 5: Checking group summary information
        /dev/xvdc1: 11/655360 files (0.0% non-contiguous), 83137/2620928 blocks
      2. Run the following command to expand the size of the file system on /dev/xvdc1:

        resize2fs /dev/xvdc1

        Information similar to the following is displayed:
        [root@ecs-1120 linux]# resize2fs /dev/xvdc1
        resize2fs 1.42.9 (28-Dec-2013)
        Resizing the filesystem on /dev/xvdc1 to 15728379 (4k) blocks.
        The filesystem on /dev/xvdc1 is now 15728379 blocks long.
      3. Run the following command to view the disk partition information after the partition expansion:

        lsblk

        Information similar to the following is displayed:
        [root@ecs-1120 linux]# lsblk
        NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
        NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
        xvda    202:0    0   80G  0 disk 
        ├─xvda1 202:1    0   40G  0 part /
        └─xvda2 202:2    0   40G  0 part /opt
        xvdb    202:16   0  350G  0 disk 
        ├─xvdb1 202:17   0  100G  0 part 
        └─xvdb2 202:18   0  200G  0 part
        xvdc    202:32   0   60G  0 disk 
        └─xvdc1 202:33   0    60G  0 part

        In the command output, the total capacity of the /dev/xvdc disk is 60 GB, in which the additional 50 GB has been allocated to the dev/xvdc1 partition.

      4. Run the following command to mount the created partition to the /mnt/sdc directory:

        mount /dev/xvdc1 /mnt/sdc

    • For the xfs file system
      1. Run the following command to mount the created partition to the /mnt/sdc directory:

        mount /dev/xvdc1 /mnt/sdc

      2. Run the following command to expand the size of the file system on /dev/xvdc1:

        sudo xfs_growfs /dev/xvdc1

      3. Run the following command to view the disk partition information after the partition expansion:

        lsblk

        Information similar to the following is displayed:
        [root@ecs-1120 linux]# lsblk
        NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
        NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
        xvda    202:0    0   80G  0 disk 
        ├─xvda1 202:1    0   40G  0 part /
        └─xvda2 202:2    0   40G  0 part /opt
        xvdb    202:16   0  350G  0 disk 
        ├─xvdb1 202:17   0  100G  0 part 
        └─xvdb2 202:18   0  200G  0 part
        xvdc    202:32   0   60G  0 disk 
        └─xvdc1 202:33   0    60G  0 part

        In the command output, the total capacity of the /dev/xvdc disk is 60 GB, in which the additional 50 GB has been allocated to the dev/xvdc1 partition.

  13. Run the following command to view the mount result for /dev/xvdc1:

    df -TH

    Information similar to the following is displayed:
    [root@ecs-1120 linux]# mount /dev/xvdc1 /mnt/sdc
    [root@ecs-1120 linux]# df -TH
    Filesystem     Type      Size  Used Avail Use% Mounted on
    /dev/xvda1     ext4       43G  8.3G   33G  21% /
    devtmpfs       devtmpfs  885M     0  885M   0% /dev
    tmpfs          tmpfs     894M     0  894M   0% /dev/shm
    tmpfs          tmpfs     894M   18M  877M   2% /run
    tmpfs          tmpfs     894M     0  894M   0% /sys/fs/cgroup
    tmpfs          tmpfs     179M     0  179M   0% /run/user/2000
    tmpfs          tmpfs     179M     0  179M   0% /run/user/0
    tmpfs          tmpfs     179M     0  179M   0% /run/user/1001
    /dev/xvda2     ext4       43G   51M   40G   1% /opt
    /dev/xvdc1     ext4       64G   55M   60G   1% /mnt/sdc

    The /dev/xvdc1 partition has been mounted on the /mnt/sdc directory.