• 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 (fdisk)

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

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 CentOS 7.0 64bit to describe how to allocate the additional disk space to a partition using fdisk.

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 current disk partition style:

    fdisk -l

    Information similar to the following is displayed:
    [root@ecs-1120 linux]# fdisk -l
    
    Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000c5712
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1            2048    83886079    41942016   83  Linux
    WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
    
    Disk /dev/xvdb: 161.1 GB, 161061273600 bytes, 314572800 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: gpt
    
    
    #         Start          End    Size  Type            Name
     1           34    209715166    100G  Microsoft basic opt
     2    209715167    314572766     50G  Microsoft basic opt1
    WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
    
    Disk /dev/xvdc: 42.9 GB, 42949672960 bytes, 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: gpt
    
    
    #         Start          End    Size  Type            Name
     1           34     16777215      8G  Microsoft basic opt
     2     16777216     83884031     32G  Microsoft basic opt

    In the command output, parameter Disk label type indicates the disk partition style. Value dos indicates the MBR partition style, and value gpt indicates the GPT partition style.

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:

    fdisk -l

    Information similar to the following is displayed: ( /dev/xvda is the system disk.)
    [root@ecs-bab9 test]# fdisk -l
    
    Disk /dev/xvda: 64.4 GB, 64424509440 bytes, 125829120 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000cc4ad
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1   *        2048     2050047     1024000   83  Linux
    /dev/xvda2         2050048    22530047    10240000   83  Linux
    /dev/xvda3        22530048    24578047     1024000   83  Linux
    /dev/xvda4        24578048    83886079    29654016    5  Extended
    /dev/xvda5        24580096    26628095     1024000   82  Linux swap / Solaris

  2. Run the following command to enter fdisk (/dev/xvda is used in this example):

    fdisk /dev/xvda

    Information similar to the following is displayed:
    [root@ecs-bab9 test]# fdisk /dev/xvda
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    Command (m for help):

  3. Enter n and press Enter to create a new partition.

    Information similar to the following is displayed:
    Command (m for help): n
    All primary partitions are in use
    Adding logical partition 6
    First sector (26630144-83886079, default 26630144): 
    NOTE:

    If the MBR partition style is used, a maximum of 4 primary partitions, or 3 primary partitions and 1 extended partition can be created. The extended partition cannot be used directly and must be divided into logical partitions before use.

    In this example, the maximum number of the primary partitions has been reached for the system disk, and the disk already has 5 partitions (3 primary partitions and 2 logical partitions). Therefore, the system automatically creates a sixth logical partition in the extended partition.

  4. Enter the new partition's first sector, for example the default value, and press Enter.

    The first sector must be greater than the last sector of the existing partition.

    Information similar to the following is displayed:
    First sector (26630144-83886079, default 26630144):
    Using default value 26630144
    Last sector, +sectors or +size{K,M,G} (26630144-83886079, default 83886079):

  5. Enter the new partition's last sector and press Enter.

    The default last sector is used in this example.

    Information similar to the following is displayed:
    Last sector, +sectors or +size{K,M,G} (26630144-83886079, default 83886079):
    Using default value 83886079
    Partition 6 of type Linux and of size 27.3 GiB is set
    
    Command (m for help): 

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

    Information similar to the following is displayed:
    Disk /dev/xvda: 64.4 GB, 64424509440 bytes, 125829120 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000cc4ad
    
    Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1   *        2048     2050047     1024000   83  Linux
    /dev/xvda2         2050048    22530047    10240000   83  Linux
    /dev/xvda3        22530048    24578047     1024000   83  Linux
    /dev/xvda4        24578048    83886079    29654016    5  Extended
    /dev/xvda5        24580096    26628095     1024000   82  Linux swap / Solaris
    /dev/xvda6        26630144    83886079    28627968   83  Linux
    
    Command (m for help): 

  7. Enter w and press Enter to write the changes into the partition table.

    Information similar to the following is displayed:
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.

    The partition is successfully created.

    NOTE:

    In case that you want to discard the changes made before, you can exit fdisk by entering q.

  8. Run the following command to synchronize the new partition table to the OS:

    partprobe

  9. 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/xvda6

    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/xvda6.

    Information similar to the following is displayed:
    [root@ecs-bab9 test]# mkfs -t ext4 /dev/xvda6
    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
    1790544 inodes, 7156992 blocks
    357849 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2155872256
    219 block groups
    32768 blocks per group, 32768 fragments per group
    8176 inodes per group
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
            4096000
    
    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.

  10. 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-bab9 test]# mount /dev/xvda6 /opt
    [root@ecs-bab9 test]#
    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.

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

    df -TH

    Information similar to the following is displayed:
    [root@ecs-bab9 test]# df -TH
    Filesystem     Type      Size  Used Avail Use% Mounted on
    /dev/xvda2     xfs        11G  7.4G  3.2G  71% /
    devtmpfs       devtmpfs  4.1G     0  4.1G   0% /dev
    tmpfs          tmpfs     4.1G   82k  4.1G   1% /dev/shm
    tmpfs          tmpfs     4.1G  9.2M  4.1G   1% /run
    tmpfs          tmpfs     4.1G     0  4.1G   0% /sys/fs/cgroup
    /dev/xvda3     xfs       1.1G   39M  1.1G   4% /home
    /dev/xvda1     xfs       1.1G  131M  915M  13% /boot
    /dev/xvda6     ext4       29G   47M   28G   1% /opt

Expanding an Existing Partition

The following example shows you how to make use of the additional capacity of a data disk attached to a server by recreating the /dev/xvdb1 partition and mounting the partition on /mnt/sdc. During this process, the 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:

    fdisk -l

    Information similar to the following is displayed:
    [root@ecs-b656 test]# fdisk -l
    
    Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000cc4ad
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1   *        2048     2050047     1024000   83  Linux
    /dev/xvda2         2050048    22530047    10240000   83  Linux
    /dev/xvda3        22530048    24578047     1024000   83  Linux
    /dev/xvda4        24578048    83886079    29654016    5  Extended
    /dev/xvda5        24580096    26628095     1024000   82  Linux swap / Solaris
    
    Disk /dev/xvdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0xb00005bd
    
    Device Boot      Start         End      Blocks   Id  System
    /dev/xvdb1            2048    20971519    10484736   83  Linux

    In the command output, the total capacity of the /dev/xvdb disk is 21.5 GB, and the disk has only one partition, dev/xvdb1. The partition's first sector is 2048, and its last sector is 20971519.

    View the /dev/xvdb 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 enter fdisk and enter d to delete the existing /dev/xvdb1 partition:

    fdisk /dev/xvdb

    Information similar to the following is displayed:
    [root@ecs-b656 test]# fdisk /dev/xvdb
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    Command (m for help): d
    Selected partition 1
    Partition 1 is deleted
    
    Command (m for help):
    NOTE:

    If the partitions are recreated according to the following steps, deleting partitions will not cause data loss on the data disk.

  4. Enter n and press Enter to create a new partition.

    Entering n creates a new partition.

    Information similar to the following is displayed:
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    There are two types of disk partitions:
    • Choosing p creates a primary partition.
    • Choosing e creates an extended partition.

  5. Ensure that the entered partition type is the same as the partition had before. In this example, a primary partition is used. Therefore, enter p and press Enter to create a primary partition.

    Information similar to the following is displayed:
    Select (default p): p
    Partition number (1-4, default 1):

    In the command output, Partition number specifies the primary partition number.

  6. Ensure that entered partition number is the same as the partition had before. In this example, the partition number 1 is used. Therefore, enter 1 and press Enter.

    Information similar to the following is displayed:
    Partition number (1-4, default 1): 1
    First sector (2048-41943039, default 2048):

    In the command output, First sector specifies the first sector.

    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.

  7. Ensure that the entered first sector is the same as the partition had before. In this example, first sector 2048 is recorded in 1. Therefore, enter 2048 and press Enter.

    Information similar to the following is displayed:
    First sector (2048-41943039, default 2048):
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):

    In the command output, Last sector specifies the last sector.

  8. Ensure that the entered last sector is greater than or equal to the last sector recorded in 1. In this example, the recorded last sector is 20971519, and the default last sector is used. Therefore, enter 41943039 and press Enter.

    Information similar to the following is displayed:
    Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
    Using default value 41943039
    Partition 1 of type Linux and of size 20 GiB is set
    Command (m for help):

    The partition is successfully created.

  9. Enter p and press Enter to view the details about the created partition.

    Information similar to the following is displayed:
    Command (m for help): p
    
    Disk /dev/xvdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0xb00005bd
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/xvdb1            2048    41943039    20970496   83  Linux
    
    Command (m for help): 

    Details about the /dev/xvdb1 partition are displayed.

  10. Enter w and press Enter to write the changes into the partition table.

    Information similar to the following is displayed:
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.

    The partition is successfully created.

    NOTE:

    In case that you want to discard the changes made before, you can exit fdisk by entering q.

  11. 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/xvdb1:

        e2fsck -f /dev/xvdb1

        Information similar to the following is displayed:
        [root@ecs-b656 test]# e2fsck -f /dev/xvdb1
        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/xvdb1: 11/655360 files (0.0% non-contiguous), 83137/2621184 blocks
      2. Run the following command to expand the size of the file system on /dev/xvdb1:

        resize2fs /dev/xvdb1

        Information similar to the following is displayed:
        [root@ecs-b656 test]# resize2fs /dev/xvdb1
        resize2fs 1.42.9 (28-Dec-2013)
        Resizing the filesystem on /dev/xvdb1 to 5242624 (4k) blocks.
        The filesystem on /dev/xvdb1 is now 5242624 blocks long.
      3. Run the following command to mount the created partition to the /mnt/sdc directory:

        mount /dev/xvdb1 /mnt/sdc

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

        mount /dev/xvdb1 /mnt/sdc

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

        sudo xfs_growfs /dev/xvdb1

  12. Run the following command to view the mount result for /dev/xvdb1:

    df -TH