All Documents
Current Document

Content is empty

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

Documentation

Create a file system on a raw data disk

Last updated:2021-07-01 14:37:51

Scenarios

Linux operating systems allow you to directly create file systems on raw disks. 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. This topic describes how to create a file system on a raw data disk in the Ubuntu operating system.

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.

Procedure

The following procedure shows you how to create an ext4 or XFS file system on a data disk with a capacity of 2,400 GB. The data disk is attached to a KEC instance that runs 64-bit Ubuntu 16.04. 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.

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 2,400 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 mkfs.<fstype> <Data disk name>command to 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/vdb data disk

      mkfs.ext4 /dev/vdb

      The following figure shows the output. image.png

      Note: In the preceding command, /dev/vdb is the data disk 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/vdb data disk

      mkfs.xfs -f /dev/vdb

      The following figure shows the output. image.png

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

  4. Run the mkdir <Mount point> command to create a mount point for the data disk. In this example, create a mount point named /mnt/data_disk01.
    mkdir /mnt/data_disk01
  5. Run the mount <Data disk name> <Mount point> command to mount the data disk. In this example, mount the /dev/vdb data disk to the /mnt/data_disk01 mount point.
    mount /dev/vdb /mnt/data_disk01
  6. Run the following command to view the information about the data disk:
    df -Th

    The following figure shows the output. image.png

Description of optional actions If you want 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 data disk to the /etc/fstab file.

  1. Confirm the mount method and obtain the required information. An EBS volume can be automatically mounted by using the UUID or name of the EBS volume. Perform the corresponding operation to obtain the UUID or name.

    • To obtain the UUID of the /dev/vdb data disk, run the following command:

      blkid /dev/vdb
    • To obtain the 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 an EBS volume by adding the UUID of the EBS volume 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/vdb data disk to the /mnt/data_disk01 mount point.
    • To add the configuration to automatically mount the /dev/vdb data disk by using the disk UUID acafe6be-158e-4f22-8d08-6d9bae8af2c2, run the following command:
      echo 'UUID=acafe6be-158e-4f22-8d08-6d9bae8af2c2 /mnt/data_disk01 ext4 defaults 0 0' >> /etc/fstab
    • To add the configuration to automatically mount the /dev/vdb data disk by using the disk name, run the following command:
      echo '/dev/vdb /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 on the data disk 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