Step 4. Linux _ Format and mount a data disk

Last Updated: Aug 17, 2017

If you select a data disk when creating an instance, you need to format the data disk before using it.

You can also configure multiple data disk partitions based on service requirements. We recommend you to use the built-in system tool for partitioning.

Note: For ECS, either running Windows or Linux, only the partitions on the data disk, but not on the system disk, can be subdivided into multiple partitions. If you use a third-party tool to forcibly subdivide the partition on the system disk, some unknown risks, such as system crash and data loss, may occur.

In this article, the example instance has the following configurations:

  • Non-I/O optimized:

    The only difference between I/O Optimized and non-I/O Optimized instances is that the later has an additional x in its device name, for example, xvdb for a non-I/O Optimized instance and vdb for an I/O Optimized instance.

  • Linux OS: Redhat, CentOS, Debian, or Ubuntu, at your choice
  • SSD cloud disk

Prerequisites

Operating procedure

To format and mount a data disk:

  1. Run the fdisk -l command to view the data disk. Note: Before the data disk is partitioned and formatted, you cannot view the data disk by running the df –h command. In the following example, a 5GB data disk needs to be mounted.
    If you do not find /dev/xvdb after running the fdisk -l command, it indicates that your instance does not have a data disk. Therefore, mounting is not required. In this case, you can skip this chapter.

    1. [root@xxxx ~]# fdisk -l
    2. Disk /dev/xvda: 42.9 GB, 42949672960 bytes
    3. 255 heads, 63 sectors/track, 5221 cylinders
    4. Units = cylinders of 16065 * 512 = 8225280 bytes
    5. Sector size (logical/physical): 512 bytes / 512 bytes
    6. I/O size (minimum/optimal): 512 bytes / 512 bytes
    7. Disk identifier: 0x00078f9c
    8. Device Boot Start End Blocks Id System
    9. /dev/xvda1 * 1 5222 41940992 83 Linux
    10. Disk /dev/xvdb: 5368 MB, 5368709120 bytes
    11. 255 heads, 63 sectors/track, 652 cylinders
    12. Units = cylinders of 16065 * 512 = 8225280 bytes
    13. Sector size (logical/physical): 512 bytes / 512 bytes
    14. I/O size (minimum/optimal): 512 bytes / 512 bytes
    15. Disk identifier: 0x00000000
  2. Run the following command to partition the data disk.

    1. fdisk /dev/xvdb
  3. Enter the commands n, p, 1 in sequence as prompted, press the Enter key twice, and then enter the wq command. The partitioning will begin.

    1. [root@xxx ~]# fdisk /dev/xvdb
    2. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    3. Building a new DOS disklabel with disk identifier 0x33eb5059.
    4. Changes will remain in memory only, until you decide to write them.
    5. After that, of course, the previous content won't be recoverable.
    6. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
    7. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
    8. switch off the mode (command 'c') and change display units to
    9. sectors (command 'u').
    10. Command (m for help): n
    11. Command action
    12. e extended
    13. p primary partition (1-4)
    14. p
    15. Partition number (1-4): 1
    16. First cylinder (1-652, default 1):
    17. Using default value 1
    18. Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):
    19. Using default value 652
    20. Command (m for help): wq
    21. The partition table has been altered!
    22. Calling ioctl() to re-read partition table.
    23. Syncing disks.
  4. Run the fdisk -l command to view the new partition. A new partition is created, for example, /dev/xvdb1 shown in the below.

    1. [root@xxx ~]# fdisk -l
    2. Disk /dev/xvda: 42.9 GB, 42949672960 bytes
    3. 255 heads, 63 sectors/track, 5221 cylinders
    4. Units = cylinders of 16065 * 512 = 8225280 bytes
    5. Sector size (logical/physical): 512 bytes / 512 bytes
    6. I/O size (minimum/optimal): 512 bytes / 512 bytes
    7. Disk identifier: 0x00078f9c
    8. Device Boot Start End Blocks Id System
    9. /dev/xvda1 * 1 5222 41940992 83 Linux
    10. Disk /dev/xvdb: 5368 MB, 5368709120 bytes
    11. 255 heads, 63 sectors/track, 652 cylinders
    12. Units = cylinders of 16065 * 512 = 8225280 bytes
    13. Sector size (logical/physical): 512 bytes / 512 bytes
    14. I/O size (minimum/optimal): 512 bytes / 512 bytes
    15. Disk identifier: 0x33eb5059
    16. Device Boot Start End Blocks Id System
    17. /dev/xvdb1 1 652 5237158+ 83 Linux
  5. Run the following command to format the new partition. The formatting time depends on the size of the data disk. You can also choose other file formats, for example, ext4.

    1. mkfs.ext3 /dev/xvdb1
  6. Run the following command to write the new partition information.

    1. echo '/dev/xvdb1 /mnt ext3 defaults 0 0'>> /etc/fstab

    Upon completion, run the cat /etc/fstab command to view the information.
    Note: Ubuntu 12.04 does not support barrier. Therefore, the correct command for the system is as follows:

    1. echo '/dev/xvdb1 /mnt ext3 barrier=0 0 0'>>/etc/fstab

    To mount the data disk to a folder separately, for example, to store webpages separately, modify the /mnt part in the above command.

  7. Run the mount /dev/xvdb1 /mnt command to mount the new partition. Then, run the df -h command to view the partition. If data disk information is displayed, the new partition has been mounted successfully and can be used.

    1. [root@xxx ~]# mount /dev/xvdb1 /mnt
    2. [root@xxx ~]# df -h
    3. Filesystem Size Used Avail Use% Mounted on
    4. /dev/xvda1 40G 1.5G 36G 4% /
    5. tmpfs 498M 0 498M 0% /dev/shm
    6. /dev/xvdb1 5.0G 139M 4.6G 3% /mnt

Note: ECS does not support installation and deployment of virtualization software, for example, KVM, Xen, and VMware.

Thank you! We've received your feedback.