Wednesday, April 22, 2020

How to Mount Data Disk in Alibaba Cloud ECS?

If you are an Alibaba Cloud or any other similar cloud provider ECS instance user, most of the time I find that the data disk is not automatically mounted by default. Therefore, in this article, I am going to share how to mount a data disk to ECS instance.

Firstly, check if your ECS is attached with the correct disk from the Console.


List Disk

Now, remote SSH to the server. Then, run the following command to check if the attached disk is available.
sudo fdisk -l


 As you can see:
/dev/vda is your 40GB system disk.
/dev/vdb is your 20GB data disk.

There is an existing partition /dev/vda1 existed. So, we need to create one partition for the data disk.

Create Partition

Now, execute the following command to create partition.
sudo fdisk /dev/vdb


When it prompt for command, simply enter "n" which stand for new partition.
Next, key in the partition number, default 1
Next, key in first sector, default 2048 for the very beginning
Next, key in last sector, default 41953039 for the very end if you wish to partition the entire disk
Finally, enter command "w" to write the above setting and execute the partitioning.

Now, if you run the list disk command fdisk -l again, you will see new partition /dev/vdb1 is created.

Format Disk

Before we can save data into the disk, we need to create disk format for it first. Let's just create the most commonly used Linux file system ext4 format by executing the following command:
mkfs.ext4 /dev/vdb1


Mount Disk

In order to prevent the disk unmounted after server being rebooted, let's create an auto mount command in the file system table:
echo /dev/vdb1 /mnt ext4 defaults 0 0 >> /etc/fstab
For mounting the disk, simply run the following command:
mount /dev/vdb1 /mnt
Now, you may change directory to /mnt to access to your data disk.




No comments:

Post a Comment

Send Transactional SMS with API

This post cover how to send transactional SMS using the Alibaba Cloud Short Message Service API. Transactional SMS usually come with One Tim...