Help Center/ Dedicated Enterprise Storage Service/ User Guide/ FAQs/ Performing Post-Expansion Operations for a Linux Disk (Using Parted)
Updated on 2022-02-22 GMT+08:00

Performing Post-Expansion Operations for a Linux Disk (Using Parted)

After the capacity expansion has succeeded, you need to allocate the extended space to an existing partition, or allocate new partitions to the expanded disks.

Prerequisites

  • You have logged in to the BMS. For details, see section "Logging In to a Linux BMS" in Bare Metal Server User Guide.
  • You have attached the EVS disk to the BMS and the additional disk space remains to be allocated.

Context

This section uses EulerOS 2.0 64-bit 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 disk condition, you can choose either of the following ways to allocate the additional disk space:
  • Create a partition (services will not be interrupted)

    You can create a partition for the expanded disk without the need of detaching the original partitions. The impacts on services are smaller 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, the services will be interrupted.

    If the MBR partition style is used and the disk capacity after expansion has exceeded 2 TB, the excessive disk space cannot be partitioned. In this case, if you change the partition style from MBR to GPT, the original disk data will be cleared. Therefore, back up the disk data before you change the partition style.

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 MBR and value gpt indicates GPT.

  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 Partition

The following example shows you how to create a partition for the expanded space of the system disk and mount the partition to /opt without interrupting services.

  1. Run the following command to view information about partitioning:

    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 added 40 GB remains unallocated.

  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 partition.
  6. Enter p and press Enter to create a primary partition. Creating a primary partition is used as an example.

    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         

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

  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 set the file system format of the new partition:

    In this example, ext4 ext3 is used:

    mkfs -t ext4 /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. When done is displayed in the command output, the formatting is complete.

  11. Run the following command to mount the new partition on the 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]# 

    If the new partition is mounted to a directory that is not empty, the subdirectories and files in the directory will be hidden. In this situation, you are advised to mount the new partition to an empty directory or a new directory. If the new partition must be mounted to 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 check the mounting 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

Replacing the Existing Partition

In the following example, two disks have been attached to the BMS, and the partition /dev/xvdc1 has been mounted to /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 creation, 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 information about partitioning:

    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 unmounting 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 Cancel to stop the partitioning. Then, find the first sector with the best disk performance and use that value to partition the disk. 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? Cancel  
    Data will be lost if:
    • The first sector you selected is inconsistent with the original partition.
    • The last sector you selected is smaller than that of the original partition.

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

  13. 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.

  14. 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.

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

    mount /dev/xvdc1 /mnt/sdc

  16. Run the following command to view the mounting 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.