Help Center> Huawei Cloud Flexus> User Guide> EVS Disks> Initializing a Linux Data Disk Using a Script

Initializing a Linux Data Disk Using a Script

Scenarios

When a data disk is attached to an HECS, you must log in to the HECS and initialize the disk before you can use the disk.

The method of initializing data disks for an HECS is the same as that of initializing disks for an ECS. This section describes how to use scripts to initialize data disks for a Windows HECS. For more information, see Introduction to Data Disk Initialization Scenarios and Partition Styles.

This section uses CentOS 7.4 64bit as an example to describe how to initialize data disks attached to a Linux HECS using an initialization script.

The way to initialize a disk varies with the HECS OS. The operations described in this section are for reference only. For detailed operations and differences, see the product documentations of the HECS OSs.

Prerequisites

  • A data disk has been attached to the HECS and has not been initialized.
  • You have logged in to the HECS.

Constraints

This script uses the EXT4 file system by default. This script cannot be used to create LVM or VG partitions.

Initializing New Disks

  1. Log in to the HECS and run the following command to obtain the automatic disk initialization script:

    wget https://ecs-instance-driver.obs.cn-north-1.myhuaweicloud.com/datadisk/LinuxVMDataDiskAutoInitialize.sh

  2. Run the following command to change the permission of the script:

    chmod -x LinuxVMDataDiskAutoInitialize.sh

  3. Execute the following script to automatically detect the data disks to be initialized:

    sh LinuxVMDataDiskAutoInitialize.sh

    The script automatically detects and displays the drive letters (for example, /dev/vdb) except the system disk on the HECS. Then, you need to enter the drive letter to be initialized, for example, /dev/vdb.

    Figure 1 Automatically detecting disks
  4. Enter the drive letter and press Enter. The script automatically creates the partition for the disk and formats it.
    Figure 2 Entering the drive letter
  5. Enter the directory on which you want to mount the partition, for example, /data-test.
    Figure 3 Entering the mounting directory
    The initialization is complete until the script has mounted the partition and configured automatic mounting upon HECS startup.
    Figure 4 Disk initialization completed

Initializing Existing Disks

  1. Log in to the HECS and run the following command to obtain the automatic disk initialization script:

    wget https://ecs-instance-driver.obs.cn-north-1.myhuaweicloud.com/datadisk/LinuxVMDataDiskAutoInitialize.sh

  2. Run the following command to change the permission of the script:

    chmod -x LinuxVMDataDiskAutoInitialize.sh

  3. Execute the following script to automatically detect the data disks to be initialized:

    sh LinuxVMDataDiskAutoInitialize.sh

  4. The script automatically detects that the disk partition has been mounted and displays the mounting directory. Determine whether to unmount the partition. Enter y to unmount the partition, or enter n to exit the script. In this example, enter y to continue the initialization.
    Figure 5 Unmounting the disk partition
  5. After the disk partition is unmounted, determine whether to format the disk. Enter y to format the disk, or enter n to exit the script.
    Figure 6 Formatting the disk
  6. After the disk is formatted, the system automatically creates a partition and completes the formatting. Enter the directory on which you want to mount the partition, for example, /data-test.
    Figure 7 Entering the mounting directory

    The initialization is complete until the script has mounted the partition and configured automatic mounting upon HECS startup.

    Figure 8 Disk formatting and partition mounting completed