All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

Format a data disk (< 2 TB)

Last updated:2021-07-16 10:54:19

Scenarios

This topic describes how to format a data disk whose capacity is less than 2 TB. If you want to partition a data disk whose capacity is greater than 2 TB, you must use the GUID Partition Table (GPT) partition format. For more information, see Format a data disk (≥ 2 TB).

Prerequisites

  1. An EBS volume has been attached to a KEC instance. For more information, see Attach an EBS volume.
  2. You understand the risks of formatting operations and the impact of formatting operations on the data in data disks.

    Precautions

  • The operations to format and partition data disks are high-risk operations. Proceed with caution. If you format a data disk, all data in the data disk is cleared. Before you start formatting, make sure that you do not have important data in the data disk, or have created a snapshot of the data disk to avoid data loss. For more information, see Create a snapshot.
  • You can partition data disks but not system disks of KEC instances. If you use a third-party tool to forcibly partition a system disk, unforeseeable risks such as system crash and data loss may arise. You are allowed to extend partitions or create partitions for a system disk only after you expand the capacity of the system disk. For more information, see Overview.
  • To avoid service exceptions, make sure that the services of the KEC instance are stopped before you start formatting.

    Initialize a data disk on a Windows instance

    Operating environment

A data disk with a capacity of 200 GB is attached to a KEC instance that runs 64-bit Windows Server 2012 R2. The following procedure shows you how to initialize the data disk in the Master Boot Record (MBR) partition format, format the data disk, and then create a New Technology File System (NTFS) file system for the data disk.

Procedure

  1. Log in to the KEC instance. For more information, see Connect to instances.
  2. On the Windows Server desktop, right-click the Start icon and select Disk Management. image.png
  3. In the Disk Management window, select the target data disk. In this example, select Disk 1. By default, the disk is in the Offline state. Disk 0 is the system disk. image.png

    Note: If the data disk that you want to initialize is in the Offline state, as shown in the preceding figure, you must perform Step 4 to bring it online before you perform Step 5 to initialize it. If the data disk is in the Online state, you can directly perform Step 5 to initialize it.

  4. Right-click the blank area of Disk 1 and select Online. Then, the status of Disk 1 changes to Not Initialized. image.png
  5. Right-click the blank area of Disk 1 and select Initialize Disk. image.png
  6. In the Initialize Disk window, select Disk 1 and select the partition format. In this example, select MBR (Master Boot Record) and click OK. image.png Note:
    • MBR is a widely used partition format, but applies only to data disks whose capacity does not exceed 2 TB and allows up to four primary partitions for each data disk. If you want to create more partitions for a data disk that uses the MBR partition format, you must use a primary partition as an extended partition and create logical partitions in the extended partition.
    • GPT is a new partition format that is not supported in earlier versions of Windows operating systems. The data disk capacity that GPT supports depends on the operating system and the file system. In the Windows operating system, you can create up to 128 primary partitions for a data disk that uses the GPT partition format.
  7. In the Disk Management window, right-click the Unallocated section of Disk 1 and select New Simple Volume. image.png
  8. In the New Simple Volume Wizard window, click Next as prompted. image.png
  9. Specify the volume size. If you want to create only one primary partition, use the default value and click Next. image.png
  10. Select a drive letter. In this example, select D and click Next. image.png
  11. Select Format this volume with the following settings, configure the parameters based on your business requirements, select Perform a quick format, and then click Next. image.png
  12. Click Finish to close the New Simple Volume Wizard window. You need to wait for a while before the initialization is complete. When the status of the disk changes to Healthy, it indicates that the disk is successfully initialized. image.png After the initialization, you can view the disk on the This PC interface. image.png

Initialize a data disk on a Linux instance

Operating environment

A data disk with a capacity of 200 GB is attached to a KEC instance that runs 64-bit CentOS 7.6. The following procedure shows you how to create a primary partition for the /dev/vdb data disk by using the fdisk partition utility, initialize the partition in the MBR format, and then create an ext4 or XFS file system for the partition. After you configure the file system, you can mount the file system to the /mnt/data_disk01 directory and configure the file system to be automatically mounted upon operating system startup.

Note: By default, the device names of data disks are assigned by the system, which ascend from /dev/vdb to /dev/vdz. If you do not need to create logical partitions such as /dev/vdb1 or /dev/vdb2 on your data disk, you can directly create a file system on the raw data disk. For more information, see Create a file system on a raw data disk.

Procedure

  1. Log in to the KEC instance. For more information, see Connect to instances.
  2. Run the following command to view the information about the EBS volumes on the KEC instance:

    fdisk -l
    The following figure shows the output. image.png The following table describes the information extracted from the figure. EBS volume Partition Partition description
    /dev/vda is the system disk with a capacity of 50 GB. /dev/vda1 MBR partition, with a capacity of 50 GB
    /dev/vdb is a data disk with a capacity of 200 GB. /dev/vdb No partition

    Note: If the /dev/vd* data disk that you purchase is not displayed in the command output, check whether the data disk is attached to the instance. In this example, the data disk is /dev/vdb. For more information about how to attach a data disk to a KEC instance in the EBS console, see Attach an EBS volume.

  3. Run the fdisk <Data disk name> command to partition the data disk by using the fdisk partition utility. In this example, the /dev/vdb data disk is partitioned.

    fdisk /dev/vdb

    Perform the following steps as prompted: a. Enter p and press the Enter key to view the partition information about the data disk. By default, a new data disk does not have a partition. b. Enter n and press the Enter key to create a partition. c. Enter p and press the Enter key to set the partition type to primary partition.

    Note If you want to create four or less partitions on a data disk, you can set the partition type to primary partition for all the partitions. If you want to create more than four partitions, enter e at least once to create an extended partition.

    d. Enter the partition number 1 and press the Enter key to create a primary partition.

    Note: Partition number specifies the number of a primary partition, which ranges from 1 to 4.

    e. Press the Enter key twice to use the default partition size. By default, the number of the start sector is 2048 and the number of the end sector is 419430399.

    Note [First sector] specifies the number of the start sector. The default value is 2048. You can select a value within the range from 2048 to 419430399. [Last sector] specifies the number of the end sector. The default value is 419430399. You can select a value within the range from 2048 to 419430399.

    f. Enter p and press the Enter key to view the details of the new partition. g. Enter w to save the partition table and start partitioning. The following figure shows the output. image.png

  4. Run the following command to view the information about the new partition:

    lsblk

    The following figure shows the output. image.png

  5. Run the mkfs.<fstype> <Partition name> command to format the new partition and create a file system. In this example, create an ext4 file system.

    • To create an ext* file system, for example, ext4, run the following command:

      Create a file system for the /dev/vdb1 partition

      mkfs.ext4 /dev/vdb1

      The following figure shows the output. image.png

      Note: In the preceding command, /dev/vdb1 is the partition name. You must change it based on your business requirements.

    • To create an XFS file system, run the following command:

      Create a file system for the /dev/vdb1 partition

      mkfs.xfs -f /dev/vdb1

      The following figure shows the output. image.png

      Note: In the preceding command, /dev/vdb1 is the partition name. You must change it based on your business requirements. If the message -bash: mkfs.xfs: command not found appears, run the yum -y install xfsprogs command to install the RPM package of xfsprogs.

  6. Run the mkdir <Mount point> command to create a mount point for the new partition. In this example, create a mount point named /mnt/data_disk01.
    mkdir /mnt/data_disk01
  7. Run the mount <Partition name> <Mount point> command to mount the new partition. In this example, mount the /dev/vdb1 partition to the /mnt/data_disk01 mount point.
    mount /dev/vdb1 /mnt/data_disk01
  8. Run the following command to view the information about the new partition:
    df -Th

    The following figure shows the output. image.png

Description of optional actions If you want the new partition of the data disk to be automatically mounted to the KEC instance when the KEC instance starts or restarts, perform the following steps to add the information about the new partition to the /etc/fstab file.

  1. Confirm the mount method and obtain the required information. A partition can be automatically mounted by using the universally unique identifier (UUID) or name of the partition. Perform the corresponding operation to obtain the UUID or name.

    • To obtain the UUID of the /dev/vdb1 partition, run the following command:

      blkid /dev/vdb1
    • To obtain the partition information about the data disk, run the following command:

      lsblk

      The following figure shows the output. image.png Note: If you detach or delete an EBS volume from a running KEC instance, the names of other EBS volumes attached to the KEC instance may change. We recommend that you reference a partition by adding the UUID of the partition to the /etc/fstab file.

  2. Run the following command to back up the etc/fstab file:

    cp /etc/fstab /etc/fstab.bak
  3. Add the auto-mount configuration to the etc/fstab file. In this example, add the configuration to automatically mount the /dev/vdb1 partition to the /mnt/data_disk01 mount point.
    • To add the configuration to automatically mount the /dev/vdb1 partition by using the partition UUID 34dbba74-5123-4b0f-a589-ae5e7e9e497c, run the following command:
      echo 'UUID=34dbba74-5123-4b0f-a589-ae5e7e9e497c /mnt/data_disk01 ext4 defaults 0 0' >> /etc/fstab
    • To add the configuration to automatically mount the /dev/vdb1 partition by using the partition name, run the following command:
      echo '/dev/vdb1 /mnt/data_disk03 ext4 defaults 0 0' >> /etc/fstab
  4. Run the cat /etc/fstab command to view the auto-mount configuration.
    cat /etc/fstab

    The following figure shows the output. image.png

  5. Run the following command to check whether the /etc/fstab file is successfully configured:
    mount -a

    If the command is successfully run, the /etc/fstab file is successfully configured, and the file system created for the partition will be automatically mounted when the operating system starts.

On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback