Initializing Linux Data Disks Using a Script
Scenarios
This section uses CentOS 7.4 64bit to describe how to initialize data disks attached to a server running Linux using the initialization script.
The formatting procedure varies depending on the server OS. This section is for reference only.
When using a disk for the first time, if you have not initialized it, including creating partitions and file systems, the additional space added to this disk in an expansion later may not be normally used.
Prerequisites
- You have attached the data disk to a server, but has not initialized it yet.
- You have logged in to the server.
- For how to log in to an ECS, see Logging In to an ECS.
- For how to log in to a BMS, see Logging In to a BMS.
Notes and Constraints
- This script uses the EXT4 file system by default. It cannot be used for the disks using LVM or VG.
- This script can only be used to format CentOS.
Initializing New Disks
- Log in to the server 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
If an abnormal output is returned, check whether the server has an EIP bound. When you are in a region other than CN North-Beijing1, the script can be obtained only after an EIP is bound to the server.
- Run the following command to change the permission of the script:
- Execute the following script to automatically detect the data disks to be initialized:
./LinuxVMDataDiskAutoInitialize.sh
The script automatically detects and displays the drive letters (for example, /dev/vdb) except the system disk on the server. Then, you need to enter the drive letter to be initialized, for example, /dev/vdb.
Figure 1 Automatic detecting disks
- 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
- 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 server start.Figure 4 Disk initialization completed
Initializing Existing Disks
- Log in to the server 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
- Run the following command to change the permission of the script:
- Execute the following script to automatically detect the data disks to be initialized:
- 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
- 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
- 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 server start.
Figure 8 Disk formatting and partition mounting completed
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.