1. Purchase a disk
The parameters are as follows
View successfully purchased disks
- Note: The newly purchased hard disk belongs to the data disk. If the hard disk is purchased together with the cloud server, it belongs to the system disk.
2. Disk mounting and partitioning
Mount disk to cloud server
- Note: In Huawei Cloud, cloud disks can only be mounted to cloud servers in the same availability zone.
View disk name
- As shown below, the current cloud server has two disks,
/dev/vda
is the system disk, and/dev/vdb
is the new data disk
fdisk -l
Partition the disk**[optional]**
fdisk /dev/vdb
n
p
enter
2048*n
w
View partition results
fdisk -l
Create file system format
mkfs -t ext4 /dev/vdb
# 如果进行了分区操作,如上面的步骤,需修改如下
mkfs -t ext4 /dev/vdb1
Create a new mount point
mkdir /mnt/data
Mount the new partition to the new mount point
mount /dev/vdb /mnt/data
View mount results
- It can be seen that the cloud disk has been successfully mounted to the cloud server.
df -TH
3. Automatic mounting
Choose the following three methods according to your needs to automatically mount the disk.
- Soft link of elastic cloud disk
- UUID (universally unique identifier) of the file system
- Device name
You can view relevant information through the following command
View soft links of elastic cloud disks
ls -l /dev/disk/by-id
View file system UUID
blkid /dev/vdb
View device name
fdisk -l
Edit
/etc/fstab
file to configure automatic mounting
- Note: It is recommended to back up the file before modifying it.
# 备份
cp -r /etc/fstab /etc/fstab.bak
# 编辑
vim /etc/fstab
Add the following content to the last line, choose one of the three
【结合前面通过命令查看到的信息】
# 使用弹性云硬盘的软链接自动挂载
/dev/disk/by-id/virtio-18ce058b-b856-402f-b /mnt/data ext4 defaults 0 0
# 使用磁盘分区的 UUID 自动挂载
UUID=030b1d57-3134-4790-91c7-1f2979fecd2b /mnt/data ext4 defaults 0 0
# 使用磁盘分区的 UUID 自动挂载
/dev/vdb /mnt/data ext4 defaults 0 0
Check
/etc/fstab
file is written successfully
- Note: No prompt means success
mount -a
4. Test
Restart the server and check whether automatic mounting is set successfully.
- As can be seen from the picture, it has been successfully mounted.
df -TH