All Products
Search
Document Center

Elastic Compute Service:Create a file system on a raw disk

Last Updated:Aug 14, 2024

After creating an empty data disk, you cannot use directly the disk in the Elastic Compute Service (ECS) instance. You need to initialize the disk. If you want to use it as a raw disk without partitioning the disk, you can create a file system on the raw disk during the initialization process. This topic describes how to create a file system on a raw disk.

Note

You can create file systems only on the raw disks of Linux ECS instances.

Raw disks are typically represented as /dev/vda, /dev/vdb, excluding numeric indexes such as /dev/vdb1, /dev/vdb2 which represent partitions.

Prerequisites

A data disk is attached to an ECS instance and the disk status is In Use. For more information, see Attach a data disk.

Note

Ignore this step if you choose to attach to ECS instance when creating a data disk.

Procedure

In this example, an Alibaba Cloud Linux 3.2104 LTS 64-bit public image is used. Commands are different in different operating systems, adapt your actions according to your actual environment.

  1. Connect to the ECS instance.

  2. Run the following command to obtain the device name of the data disk:

    sudo fdisk -l 

    If a command output similar to the following one is displayed, the instance has the /dev/vda system disk and the /dev/vdb data disk.

    image.png

  3. Run the following command to install e2fsprogs:

    sudo yum install -y e2fsprogs
    Note

    The yum command in this step is suitable for Linux distributions such as CentOS. For other Linux distributions, modify the command based on your package management software. For example, for Debian or Ubuntu, use sudo apt-get install <Package name>.

  4. Run the following commands to create a file system for the destination data disk.

    Partition sizes vary based on file system types. Create a file system that meets your business requirements. The following sample commands are run to create an ext4 file system and an xfs file system respectively:

    Create an ext4 file system

    sudo mkfs.ext4 /dev/vdb

    In the sample command, /dev/vdb is the device name of the data disk. Replace the device name with the actual device name.

    Important

    Create an xfs file system

    sudo mkfs.xfs /dev/vdb

    In the sample command, /dev/vdb is the device name of the data disk. Replace the device name with the actual device name.

  5. (Required) If no mount directory is available, run the following command to create a mount directory for the destination data disk.

    Alternatively, you can mount the destination data disk on an existing directory. In this example, a mount directory named /media/test is created. Replace the directory name with the actual directory name.

    sudo mkdir /media/test
  6. Run the following command to mount the destination data disk on the created mount directory.

    In this example, a data disk named /dev/vdb is mounted on a directory named /media/test. Replace the disk name and directory name with the actual disk name and directory name.

    If you run the mount command to mount a file system, specify the corresponding mount parameters to meet your requirements on the data security and performance of the file system. For more information, see Run the mount command to mount an ext4 file system.

    • (Recommend) If you have moderate requirements on the data security and performance of the file system, do not specify the mount parameters:

      sudo mount /dev/vdb /media/test
    • If you have high requirements on the data security of the file system but low requirements on the performance of the file system, specify the following mount parameters:

      sudo mount -o rw,atime,sync,barrier,data=journal /dev/vdb /media/test
    • If you have high requirements on the performance of the file system but low requirements on the data security of the file system, specify the following mount parameters:

      sudo mount -o defaults,noatime,nodiratime,nobarrier,nodelalloc,data=writeback /dev/vdb /media/test
  7. Run the following command to check whether the file system is mounted:

    df -h

    If a command output similar to the following one is displayed, the /dev/vdb data disk is mounted.

    image.png

  8. Configure the /etc/fstab file and automatically mount the disk partition upon instance startup.

    If you want the system to mount the data disk upon instance startup, write the information about the disk partition to the /etc/fstab file and configure the disk partition to automatically mount the data disk upon instance startup.

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

      sudo cp /etc/fstab /etc/fstab.bak
    2. Run the following command to write the information about the disk partition to the /etc/fstab file.

      Root users

      If you are a root user, run the following command to modify the /etc/fstab file:

      echo `blkid /dev/vdb | awk '{print $2}' | sed 's/\"//g'` /media/test ext4 defaults 0 0 >> /etc/fstab

      The following items describe the parameters:

      • /dev/vdb: the device name of the data disk. Replace the device name with the actual device name.

      • /media/test: the mount point of the partition. Replace the mount point with the actual mount point.

      • ext4: the file system type of the partition. Replace the file system type with the actual file system type.

      • defaults: the mount parameters of the file system. Specify the corresponding mount parameters to meet your requirements on the data security and performance of the file system. For more information, see Run the mount command to mount an ext4 file system.

      Normal users

      If you are a normal user, you can manually modify the /etc/fstab file. For more information, see Configure UUIDs in the fstab file to automatically mount data disks.

    3. Run the following command to check the information about the new partition in the /etc/fstab file:

      cat /etc/fstab

      If a command output similar to the following one is displayed, the information of the new partition is written to the /etc/fstab file.

      image.png

    4. Run the following command to mount the file system that is configured in the /etc/fstab file. If the file system is correctly configured in the /etc/fstab file, no errors are reported.

      sudo mount -a
    5. Run the following command to check whether the file system is mounted as expected:

      df -Th

      If a command output similar to the following one is displayed, the file system is mounted.

      image.png