All Products
Search
Document Center

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

最終更新日:May 21, 2024

A raw disk is a disk that is not partitioned or formatted with file systems. If your disk is a raw disk, it is presented as an independent partition such as /dev/vdb and you do not need to divide the disk into logical partitions such as /dev/vdb1 and /dev/vdb2. You can create a file system on a raw disk when you initialize the disk. 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 Elastic Compute Service (ECS) instances.

Prerequisites

A data disk is attached to an ECS instance. For more information, see Attach a data disk.

Procedure

In this example, an Alibaba Cloud Linux 3.2104 LTS 64-bit public image is used.

  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 mount the disk partition.

    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